@cogitator-ai/worker 0.3.8 → 0.3.18
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/README.md +5 -9
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/metrics.d.ts +1 -1
- package/dist/processors/agent.d.ts +1 -4
- package/dist/processors/agent.d.ts.map +1 -1
- package/dist/processors/agent.js +2 -44
- package/dist/processors/agent.js.map +1 -1
- package/dist/processors/shared.d.ts +5 -0
- package/dist/processors/shared.d.ts.map +1 -0
- package/dist/processors/shared.js +29 -0
- package/dist/processors/shared.js.map +1 -0
- package/dist/processors/swarm-agent.d.ts.map +1 -1
- package/dist/processors/swarm-agent.js +2 -28
- package/dist/processors/swarm-agent.js.map +1 -1
- package/dist/processors/swarm.d.ts +1 -4
- package/dist/processors/swarm.d.ts.map +1 -1
- package/dist/processors/swarm.js +2 -43
- package/dist/processors/swarm.js.map +1 -1
- package/dist/processors/workflow.d.ts +5 -9
- package/dist/processors/workflow.d.ts.map +1 -1
- package/dist/processors/workflow.js +7 -30
- package/dist/processors/workflow.js.map +1 -1
- package/dist/queue.d.ts +1 -1
- package/dist/worker.d.ts +1 -1
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -302,7 +302,7 @@ Built-in processors handle each job type.
|
|
|
302
302
|
### Using Processors Directly
|
|
303
303
|
|
|
304
304
|
```typescript
|
|
305
|
-
import { processAgentJob,
|
|
305
|
+
import { processAgentJob, processSwarmJob, processSwarmAgentJob } from '@cogitator-ai/worker';
|
|
306
306
|
|
|
307
307
|
const agentResult = await processAgentJob({
|
|
308
308
|
type: 'agent',
|
|
@@ -312,14 +312,6 @@ const agentResult = await processAgentJob({
|
|
|
312
312
|
threadId: 'thread-1',
|
|
313
313
|
});
|
|
314
314
|
|
|
315
|
-
const workflowResult = await processWorkflowJob({
|
|
316
|
-
type: 'workflow',
|
|
317
|
-
jobId: 'job-2',
|
|
318
|
-
workflowConfig: myWorkflowConfig,
|
|
319
|
-
input: { data: [] },
|
|
320
|
-
runId: 'run-1',
|
|
321
|
-
});
|
|
322
|
-
|
|
323
315
|
const swarmResult = await processSwarmJob({
|
|
324
316
|
type: 'swarm',
|
|
325
317
|
jobId: 'job-3',
|
|
@@ -328,6 +320,8 @@ const swarmResult = await processSwarmJob({
|
|
|
328
320
|
});
|
|
329
321
|
```
|
|
330
322
|
|
|
323
|
+
> **Note:** `processWorkflowJob` is not yet implemented — it throws an error. Workflows should be executed directly via `WorkflowExecutor` from `@cogitator-ai/workflows`.
|
|
324
|
+
|
|
331
325
|
---
|
|
332
326
|
|
|
333
327
|
## Job Results
|
|
@@ -707,12 +701,14 @@ import type {
|
|
|
707
701
|
AgentJobPayload,
|
|
708
702
|
WorkflowJobPayload,
|
|
709
703
|
SwarmJobPayload,
|
|
704
|
+
SwarmAgentJobPayload,
|
|
710
705
|
|
|
711
706
|
// Job results
|
|
712
707
|
JobResult,
|
|
713
708
|
AgentJobResult,
|
|
714
709
|
WorkflowJobResult,
|
|
715
710
|
SwarmJobResult,
|
|
711
|
+
SwarmAgentJobResult,
|
|
716
712
|
|
|
717
713
|
// Configuration
|
|
718
714
|
QueueConfig,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* - Job priorities and delays
|
|
8
8
|
* - Prometheus metrics for HPA
|
|
9
9
|
*/
|
|
10
|
-
export { JobQueue } from './queue';
|
|
11
|
-
export { WorkerPool, type WorkerPoolEvents } from './worker';
|
|
12
|
-
export { formatPrometheusMetrics, DurationHistogram, MetricsCollector } from './metrics';
|
|
13
|
-
export { processAgentJob, processWorkflowJob, processSwarmJob } from './processors/index';
|
|
14
|
-
export type { SerializedAgent, SerializedWorkflow, SerializedWorkflowNode, SerializedWorkflowEdge, SerializedSwarm, JobPayload, AgentJobPayload, WorkflowJobPayload, SwarmJobPayload, JobResult, AgentJobResult, WorkflowJobResult, SwarmJobResult, QueueConfig, WorkerConfig, QueueMetrics, } from './types';
|
|
10
|
+
export { JobQueue } from './queue.js';
|
|
11
|
+
export { WorkerPool, type WorkerPoolEvents } from './worker.js';
|
|
12
|
+
export { formatPrometheusMetrics, DurationHistogram, MetricsCollector } from './metrics.js';
|
|
13
|
+
export { processAgentJob, processWorkflowJob, processSwarmJob, processSwarmAgentJob, } from './processors/index.js';
|
|
14
|
+
export type { SerializedAgent, SerializedWorkflow, SerializedWorkflowNode, SerializedWorkflowEdge, SerializedSwarm, JobPayload, AgentJobPayload, WorkflowJobPayload, SwarmJobPayload, SwarmAgentJobPayload, JobResult, AgentJobResult, WorkflowJobResult, SwarmJobResult, SwarmAgentJobResult, QueueConfig, WorkerConfig, QueueMetrics, } from './types.js';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEzF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - Job priorities and delays
|
|
8
8
|
* - Prometheus metrics for HPA
|
|
9
9
|
*/
|
|
10
|
-
export { JobQueue } from './queue';
|
|
11
|
-
export { WorkerPool } from './worker';
|
|
12
|
-
export { formatPrometheusMetrics, DurationHistogram, MetricsCollector } from './metrics';
|
|
13
|
-
export { processAgentJob, processWorkflowJob, processSwarmJob } from './processors/index';
|
|
10
|
+
export { JobQueue } from './queue.js';
|
|
11
|
+
export { WorkerPool } from './worker.js';
|
|
12
|
+
export { formatPrometheusMetrics, DurationHistogram, MetricsCollector } from './metrics.js';
|
|
13
|
+
export { processAgentJob, processWorkflowJob, processSwarmJob, processSwarmAgentJob, } from './processors/index.js';
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAyB,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEzF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAyB,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
package/dist/metrics.d.ts
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Recreates an Agent from serialized config and executes it.
|
|
5
5
|
*/
|
|
6
|
-
import type { AgentJobPayload, AgentJobResult } from '../types';
|
|
7
|
-
/**
|
|
8
|
-
* Process an agent job
|
|
9
|
-
*/
|
|
6
|
+
import type { AgentJobPayload, AgentJobResult } from '../types.js';
|
|
10
7
|
export declare function processAgentJob(payload: AgentJobPayload): Promise<AgentJobResult>;
|
|
11
8
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGhE,wBAAsB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAqCvF"}
|
package/dist/processors/agent.js
CHANGED
|
@@ -3,50 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Recreates an Agent from serialized config and executes it.
|
|
5
5
|
*/
|
|
6
|
-
import { Cogitator, Agent
|
|
7
|
-
import {
|
|
8
|
-
/**
|
|
9
|
-
* Convert JSON Schema parameters to a permissive Zod schema
|
|
10
|
-
*
|
|
11
|
-
* Since we only have the JSON Schema and not the original Zod type,
|
|
12
|
-
* we create a schema that accepts any object matching the required structure.
|
|
13
|
-
*/
|
|
14
|
-
function jsonSchemaToZod(params) {
|
|
15
|
-
const properties = params.properties;
|
|
16
|
-
const required = params.required ?? [];
|
|
17
|
-
if (Object.keys(properties).length === 0) {
|
|
18
|
-
return z.object({});
|
|
19
|
-
}
|
|
20
|
-
const shape = {};
|
|
21
|
-
for (const [key, _] of Object.entries(properties)) {
|
|
22
|
-
shape[key] = required.includes(key) ? z.unknown() : z.unknown().optional();
|
|
23
|
-
}
|
|
24
|
-
return z.object(shape).passthrough();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Recreate tools from schemas
|
|
28
|
-
*
|
|
29
|
-
* Note: This creates stub tools that log execution but can't actually run
|
|
30
|
-
* the original code. For full tool support, tools need to be registered
|
|
31
|
-
* separately on the worker or use a remote execution mechanism.
|
|
32
|
-
*/
|
|
33
|
-
function recreateTools(schemas) {
|
|
34
|
-
return schemas.map((schema) => tool({
|
|
35
|
-
name: schema.name,
|
|
36
|
-
description: schema.description,
|
|
37
|
-
parameters: jsonSchemaToZod(schema.parameters),
|
|
38
|
-
execute: async (input) => {
|
|
39
|
-
console.warn(`[worker] Tool "${schema.name}" called with input:`, JSON.stringify(input));
|
|
40
|
-
return {
|
|
41
|
-
warning: 'Tool executed in worker with stub implementation',
|
|
42
|
-
input,
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Process an agent job
|
|
49
|
-
*/
|
|
6
|
+
import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
7
|
+
import { recreateTools } from './shared.js';
|
|
50
8
|
export async function processAgentJob(payload) {
|
|
51
9
|
const { agentConfig, input, threadId } = payload;
|
|
52
10
|
const cogitator = new Cogitator();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;A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K,CAAC,WAAW;YAChC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW;SAChC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Tool, ToolSchema } from '@cogitator-ai/types';
|
|
3
|
+
export declare function jsonSchemaToZod(params: ToolSchema['parameters']): z.ZodType;
|
|
4
|
+
export declare function recreateTools(schemas: ToolSchema[]): Tool[];
|
|
5
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/processors/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE5D,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,CAc3E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,CAe3D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { tool } from '@cogitator-ai/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export function jsonSchemaToZod(params) {
|
|
4
|
+
const properties = params.properties;
|
|
5
|
+
const required = params.required ?? [];
|
|
6
|
+
if (Object.keys(properties).length === 0) {
|
|
7
|
+
return z.object({});
|
|
8
|
+
}
|
|
9
|
+
const shape = {};
|
|
10
|
+
for (const key of Object.keys(properties)) {
|
|
11
|
+
shape[key] = required.includes(key) ? z.unknown() : z.unknown().optional();
|
|
12
|
+
}
|
|
13
|
+
return z.object(shape).passthrough();
|
|
14
|
+
}
|
|
15
|
+
export function recreateTools(schemas) {
|
|
16
|
+
return schemas.map((schema) => tool({
|
|
17
|
+
name: schema.name,
|
|
18
|
+
description: schema.description,
|
|
19
|
+
parameters: jsonSchemaToZod(schema.parameters),
|
|
20
|
+
execute: async (input) => {
|
|
21
|
+
console.warn(`[worker] Tool "${schema.name}" called with input:`, JSON.stringify(input));
|
|
22
|
+
return {
|
|
23
|
+
warning: 'Tool executed in worker with stub implementation',
|
|
24
|
+
input,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/processors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,UAAU,eAAe,CAAC,MAAgC;IAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;IAEvC,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAED,MAAM,KAAK,GAA8B,EAAE,CAAC;IAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC7E,CAAC;IAED,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC5B,IAAI,CAAC;QACH,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC;QAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACvB,OAAO,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,IAAI,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACzF,OAAO;gBACL,OAAO,EAAE,kDAAkD;gBAC3D,KAAK;aACN,CAAC;QACJ,CAAC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm-agent.d.ts","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"swarm-agent.d.ts","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAgF9B"}
|
|
@@ -4,35 +4,9 @@
|
|
|
4
4
|
* Executes a single agent within a distributed swarm context.
|
|
5
5
|
* Reads shared state from Redis and publishes results back.
|
|
6
6
|
*/
|
|
7
|
-
import { Cogitator, Agent
|
|
7
|
+
import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
8
8
|
import Redis from 'ioredis';
|
|
9
|
-
import {
|
|
10
|
-
function jsonSchemaToZod(params) {
|
|
11
|
-
const properties = params.properties;
|
|
12
|
-
const required = params.required ?? [];
|
|
13
|
-
if (Object.keys(properties).length === 0) {
|
|
14
|
-
return z.object({});
|
|
15
|
-
}
|
|
16
|
-
const shape = {};
|
|
17
|
-
for (const [key, _] of Object.entries(properties)) {
|
|
18
|
-
shape[key] = required.includes(key) ? z.unknown() : z.unknown().optional();
|
|
19
|
-
}
|
|
20
|
-
return z.object(shape).passthrough();
|
|
21
|
-
}
|
|
22
|
-
function recreateTools(schemas) {
|
|
23
|
-
return schemas.map((schema) => tool({
|
|
24
|
-
name: schema.name,
|
|
25
|
-
description: schema.description,
|
|
26
|
-
parameters: jsonSchemaToZod(schema.parameters),
|
|
27
|
-
execute: async (input) => {
|
|
28
|
-
console.warn(`[swarm-agent-worker] Tool "${schema.name}" called with input:`, JSON.stringify(input));
|
|
29
|
-
return {
|
|
30
|
-
warning: 'Tool executed in worker with stub implementation',
|
|
31
|
-
input,
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
9
|
+
import { recreateTools } from './shared.js';
|
|
36
10
|
export async function processSwarmAgentJob(payload) {
|
|
37
11
|
const { swarmId, agentName, agentConfig, input, context, stateKeys } = payload;
|
|
38
12
|
let redis = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm-agent.js","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"swarm-agent.js","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,MAAM,SAAS,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAA6B;IAE7B,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,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ACV,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Recreates a Swarm from serialized config and executes it.
|
|
5
5
|
*/
|
|
6
|
-
import type { SwarmJobPayload, SwarmJobResult } from '../types';
|
|
7
|
-
/**
|
|
8
|
-
* Process a swarm job
|
|
9
|
-
*/
|
|
6
|
+
import type { SwarmJobPayload, SwarmJobResult } from '../types.js';
|
|
10
7
|
export declare function processSwarmJob(payload: SwarmJobPayload): Promise<SwarmJobResult>;
|
|
11
8
|
//# sourceMappingURL=swarm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../src/processors/swarm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../../src/processors/swarm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAmB,MAAM,UAAU,CAAC;AAkCjF,wBAAsB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAqCvF"}
|
package/dist/processors/swarm.js
CHANGED
|
@@ -3,44 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Recreates a Swarm from serialized config and executes it.
|
|
5
5
|
*/
|
|
6
|
-
import { Cogitator, Agent
|
|
6
|
+
import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
7
7
|
import { Swarm } from '@cogitator-ai/swarms';
|
|
8
|
-
import {
|
|
9
|
-
/**
|
|
10
|
-
* Convert JSON Schema to permissive Zod schema
|
|
11
|
-
*/
|
|
12
|
-
function jsonSchemaToZod(params) {
|
|
13
|
-
const properties = params.properties;
|
|
14
|
-
const required = params.required ?? [];
|
|
15
|
-
if (Object.keys(properties).length === 0) {
|
|
16
|
-
return z.object({});
|
|
17
|
-
}
|
|
18
|
-
const shape = {};
|
|
19
|
-
for (const [key, _] of Object.entries(properties)) {
|
|
20
|
-
shape[key] = required.includes(key) ? z.unknown() : z.unknown().optional();
|
|
21
|
-
}
|
|
22
|
-
return z.object(shape).passthrough();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Recreate tools from schemas
|
|
26
|
-
*/
|
|
27
|
-
function recreateTools(schemas) {
|
|
28
|
-
return schemas.map((schema) => tool({
|
|
29
|
-
name: schema.name,
|
|
30
|
-
description: schema.description,
|
|
31
|
-
parameters: jsonSchemaToZod(schema.parameters),
|
|
32
|
-
execute: async (input) => {
|
|
33
|
-
console.warn(`[worker] Tool "${schema.name}" called with input:`, JSON.stringify(input));
|
|
34
|
-
return {
|
|
35
|
-
warning: 'Tool executed in worker with stub implementation',
|
|
36
|
-
input,
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Recreate an agent from serialized config
|
|
43
|
-
*/
|
|
8
|
+
import { recreateTools } from './shared.js';
|
|
44
9
|
function recreateAgent(config) {
|
|
45
10
|
const tools = recreateTools(config.tools);
|
|
46
11
|
return new Agent({
|
|
@@ -52,9 +17,6 @@ function recreateAgent(config) {
|
|
|
52
17
|
tools,
|
|
53
18
|
});
|
|
54
19
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Map topology to strategy type
|
|
57
|
-
*/
|
|
58
20
|
function getStrategyType(topology) {
|
|
59
21
|
switch (topology) {
|
|
60
22
|
case 'sequential':
|
|
@@ -71,9 +33,6 @@ function getStrategyType(topology) {
|
|
|
71
33
|
return 'round-robin';
|
|
72
34
|
}
|
|
73
35
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Process a swarm job
|
|
76
|
-
*/
|
|
77
36
|
export async function processSwarmJob(payload) {
|
|
78
37
|
const { swarmConfig, input } = payload;
|
|
79
38
|
const cogitator = new Cogitator();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/processors/swarm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/processors/swarm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,SAAS,aAAa,CAAC,MAAuB;IAC5C,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,IAAI,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,KAAK,EAAE;QAC3C,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CACtB,QAA+E;IAE/E,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,UAAU,CAAC;QACpB,KAAK,cAAc;YACjB,OAAO,cAAc,CAAC;QACxB,KAAK,eAAe;YAClB,OAAO,aAAa,CAAC;QACvB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC;QACrB;YACE,OAAO,aAAa,CAAC;IACzB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAwB;IAC5D,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAEvC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAElC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAErD,MAAM,YAAY,GAAG,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAgB;QAC1B,IAAI,EAAE,gBAAgB,IAAI,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM;QACN,QAAQ,EAAE,YAAY;KACvB,CAAC;IAEF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE3C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;QAC7B,KAAK;KACN,CAAC,CAAC;IAEH,MAAM,YAAY,GAAwC,EAAE,CAAC;IAC7D,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACvD,YAAY,CAAC,IAAI,CAAC;gBAChB,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,SAAS,CAAC,MAAM;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;QACnC,MAAM,EAAE,CAAC;QACT,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workflow job processor
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Workflow execution in a distributed worker requires a serialization protocol
|
|
5
|
+
* for the workflow graph (nodes, edges, conditions). This is planned but not
|
|
6
|
+
* yet implemented. The processor throws so BullMQ properly marks the job as failed.
|
|
5
7
|
*/
|
|
6
|
-
import type { WorkflowJobPayload, WorkflowJobResult } from '../types';
|
|
7
|
-
|
|
8
|
-
* Process a workflow job
|
|
9
|
-
*
|
|
10
|
-
* Note: Full workflow execution requires deserializing the workflow graph
|
|
11
|
-
* and recreating node instances. This is a placeholder implementation.
|
|
12
|
-
*/
|
|
13
|
-
export declare function processWorkflowJob(payload: WorkflowJobPayload): Promise<WorkflowJobResult>;
|
|
8
|
+
import type { WorkflowJobPayload, WorkflowJobResult } from '../types.js';
|
|
9
|
+
export declare function processWorkflowJob(_payload: WorkflowJobPayload): Promise<WorkflowJobResult>;
|
|
14
10
|
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/processors/workflow.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/processors/workflow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtE,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAMjG"}
|
|
@@ -1,36 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workflow job processor
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Workflow execution in a distributed worker requires a serialization protocol
|
|
5
|
+
* for the workflow graph (nodes, edges, conditions). This is planned but not
|
|
6
|
+
* yet implemented. The processor throws so BullMQ properly marks the job as failed.
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* and recreating node instances. This is a placeholder implementation.
|
|
11
|
-
*/
|
|
12
|
-
export async function processWorkflowJob(payload) {
|
|
13
|
-
const { workflowConfig, input, runId } = payload;
|
|
14
|
-
const startTime = Date.now();
|
|
15
|
-
console.warn(`[worker] Workflow "${workflowConfig.name}" (${runId}) execution not fully implemented`);
|
|
16
|
-
const nodeResults = {};
|
|
17
|
-
for (const node of workflowConfig.nodes) {
|
|
18
|
-
nodeResults[node.id] = {
|
|
19
|
-
status: 'skipped',
|
|
20
|
-
reason: 'Worker workflow execution not fully implemented',
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const duration = Date.now() - startTime;
|
|
24
|
-
return {
|
|
25
|
-
type: 'workflow',
|
|
26
|
-
output: {
|
|
27
|
-
input,
|
|
28
|
-
warning: 'Workflow execution in worker is not fully implemented',
|
|
29
|
-
workflowId: workflowConfig.id,
|
|
30
|
-
workflowName: workflowConfig.name,
|
|
31
|
-
},
|
|
32
|
-
nodeResults,
|
|
33
|
-
duration,
|
|
34
|
-
};
|
|
8
|
+
export async function processWorkflowJob(_payload) {
|
|
9
|
+
throw new Error('Workflow job processing is not yet implemented. ' +
|
|
10
|
+
'Workflows require a graph deserialization protocol that is currently in development. ' +
|
|
11
|
+
'Use direct WorkflowExecutor instead.');
|
|
35
12
|
}
|
|
36
13
|
//# sourceMappingURL=workflow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/processors/workflow.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/processors/workflow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAA4B;IACnE,MAAM,IAAI,KAAK,CACb,kDAAkD;QAChD,uFAAuF;QACvF,sCAAsC,CACzC,CAAC;AACJ,CAAC"}
|
package/dist/queue.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Rate limiting
|
|
9
9
|
*/
|
|
10
10
|
import { Queue, type Job } from 'bullmq';
|
|
11
|
-
import type { QueueConfig, QueueMetrics, JobPayload, AgentJobPayload, WorkflowJobPayload, SwarmJobPayload, SwarmAgentJobPayload, SerializedAgent, SerializedWorkflow, SerializedSwarm } from './types';
|
|
11
|
+
import type { QueueConfig, QueueMetrics, JobPayload, AgentJobPayload, WorkflowJobPayload, SwarmJobPayload, SwarmAgentJobPayload, SerializedAgent, SerializedWorkflow, SerializedSwarm } from './types.js';
|
|
12
12
|
export declare class JobQueue {
|
|
13
13
|
private queue;
|
|
14
14
|
constructor(config: QueueConfig);
|
package/dist/worker.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Manages multiple BullMQ workers that process agent, workflow, and swarm jobs.
|
|
5
5
|
* Supports graceful shutdown and health monitoring.
|
|
6
6
|
*/
|
|
7
|
-
import type { WorkerConfig, JobPayload, JobResult, QueueMetrics } from './types';
|
|
7
|
+
import type { WorkerConfig, JobPayload, JobResult, QueueMetrics } from './types.js';
|
|
8
8
|
export interface WorkerPoolEvents {
|
|
9
9
|
onJobStarted?: (jobId: string, type: JobPayload['type']) => void;
|
|
10
10
|
onJobCompleted?: (jobId: string, result: JobResult) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/worker",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"description": "Distributed job queue for Cogitator agent execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@cogitator-ai/core": "workspace:*",
|
|
27
|
-
"@cogitator-ai/redis": "workspace:*",
|
|
28
27
|
"@cogitator-ai/swarms": "workspace:*",
|
|
29
28
|
"@cogitator-ai/types": "workspace:*",
|
|
30
|
-
"@cogitator-ai/workflows": "workspace:*",
|
|
31
29
|
"bullmq": "^5.69.3",
|
|
32
30
|
"nanoid": "^5.0.9",
|
|
33
31
|
"zod": "^4.3.6"
|