@cereworker/core 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,11 @@
1
+ import type { Conversation, Message, MessageRole } from './types.js';
2
+ export declare class ConversationStore {
3
+ private conversations;
4
+ create(): Conversation;
5
+ get(id: string): Conversation | undefined;
6
+ list(): Conversation[];
7
+ appendMessage(conversationId: string, role: MessageRole, content: string, extra?: Partial<Message>): Message;
8
+ getMessages(conversationId: string): Message[];
9
+ delete(id: string): boolean;
10
+ }
11
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErE,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,aAAa,CAAmC;IAExD,MAAM,IAAI,YAAY;IAYtB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIzC,IAAI,IAAI,YAAY,EAAE;IAItB,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;IAiB5G,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,EAAE;IAI9C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;CAG5B"}
@@ -0,0 +1,43 @@
1
+ import { nanoid } from 'nanoid';
2
+ export class ConversationStore {
3
+ conversations = new Map();
4
+ create() {
5
+ const now = Date.now();
6
+ const conversation = {
7
+ id: nanoid(),
8
+ messages: [],
9
+ createdAt: now,
10
+ updatedAt: now,
11
+ };
12
+ this.conversations.set(conversation.id, conversation);
13
+ return conversation;
14
+ }
15
+ get(id) {
16
+ return this.conversations.get(id);
17
+ }
18
+ list() {
19
+ return Array.from(this.conversations.values()).sort((a, b) => b.updatedAt - a.updatedAt);
20
+ }
21
+ appendMessage(conversationId, role, content, extra) {
22
+ const conversation = this.conversations.get(conversationId);
23
+ if (!conversation)
24
+ throw new Error(`Conversation ${conversationId} not found`);
25
+ const message = {
26
+ id: nanoid(),
27
+ role,
28
+ content,
29
+ timestamp: Date.now(),
30
+ ...extra,
31
+ };
32
+ conversation.messages.push(message);
33
+ conversation.updatedAt = Date.now();
34
+ return message;
35
+ }
36
+ getMessages(conversationId) {
37
+ return this.conversations.get(conversationId)?.messages ?? [];
38
+ }
39
+ delete(id) {
40
+ return this.conversations.delete(id);
41
+ }
42
+ }
43
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,OAAO,iBAAiB;IACpB,aAAa,GAAG,IAAI,GAAG,EAAwB,CAAC;IAExD,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,YAAY,GAAiB;YACjC,EAAE,EAAE,MAAM,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACf,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QACtD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IAC3F,CAAC;IAED,aAAa,CAAC,cAAsB,EAAE,IAAiB,EAAE,OAAe,EAAE,KAAwB;QAChG,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC5D,IAAI,CAAC,YAAY;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,cAAc,YAAY,CAAC,CAAC;QAE/E,MAAM,OAAO,GAAY;YACvB,EAAE,EAAE,MAAM,EAAE;YACZ,IAAI;YACJ,OAAO;YACP,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG,KAAK;SACT,CAAC;QAEF,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,WAAW,CAAC,cAAsB;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,IAAI,EAAE,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,EAAU;QACf,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import type { Message, ToolCall, ToolResult, TaskAction, CerebellumStatus } from './types.js';
2
+ export type OrchestratorEvent = {
3
+ type: 'message:user';
4
+ message: Message;
5
+ } | {
6
+ type: 'message:cerebrum:start';
7
+ conversationId: string;
8
+ } | {
9
+ type: 'message:cerebrum:chunk';
10
+ chunk: string;
11
+ } | {
12
+ type: 'message:cerebrum:end';
13
+ message: Message;
14
+ } | {
15
+ type: 'message:cerebrum:toolcall';
16
+ toolCall: ToolCall;
17
+ } | {
18
+ type: 'tool:start';
19
+ callId: string;
20
+ name: string;
21
+ } | {
22
+ type: 'tool:end';
23
+ result: ToolResult;
24
+ } | {
25
+ type: 'heartbeat:tick';
26
+ actions: TaskAction[];
27
+ } | {
28
+ type: 'cerebellum:status';
29
+ status: CerebellumStatus;
30
+ } | {
31
+ type: 'error';
32
+ error: Error;
33
+ };
34
+ type EventHandler<T> = (event: T) => void;
35
+ type EventMap = {
36
+ [K in OrchestratorEvent['type']]: Extract<OrchestratorEvent, {
37
+ type: K;
38
+ }>;
39
+ };
40
+ export declare class TypedEventEmitter {
41
+ private handlers;
42
+ on<K extends OrchestratorEvent['type']>(type: K, handler: EventHandler<EventMap[K]>): () => void;
43
+ emit<K extends OrchestratorEvent['type']>(event: EventMap[K]): void;
44
+ removeAllListeners(): void;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9F,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,2BAA2B,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAE1C,KAAK,QAAQ,GAAG;KACb,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,iBAAiB,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC;CAC1E,CAAC;AAEF,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAA2D;IAE3E,EAAE,CAAC,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAYhG,IAAI,CAAC,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;IASnE,kBAAkB,IAAI,IAAI;CAG3B"}
package/dist/events.js ADDED
@@ -0,0 +1,25 @@
1
+ export class TypedEventEmitter {
2
+ handlers = new Map();
3
+ on(type, handler) {
4
+ if (!this.handlers.has(type)) {
5
+ this.handlers.set(type, new Set());
6
+ }
7
+ const typedHandler = handler;
8
+ this.handlers.get(type).add(typedHandler);
9
+ return () => {
10
+ this.handlers.get(type)?.delete(typedHandler);
11
+ };
12
+ }
13
+ emit(event) {
14
+ const handlers = this.handlers.get(event.type);
15
+ if (handlers) {
16
+ for (const handler of handlers) {
17
+ handler(event);
18
+ }
19
+ }
20
+ }
21
+ removeAllListeners() {
22
+ this.handlers.clear();
23
+ }
24
+ }
25
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,iBAAiB;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAgD,CAAC;IAE3E,EAAE,CAAsC,IAAO,EAAE,OAAkC;QACjF,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACrC,CAAC;QACD,MAAM,YAAY,GAAG,OAA0C,CAAC;QAChE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAE3C,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QAChD,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAsC,KAAkB;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export type { Message, MessageRole, ToolCall, ToolResult, Conversation, TaskAction, CerebellumStatus, OrchestratorConfig, } from './types.js';
2
+ export type { OrchestratorEvent } from './events.js';
3
+ export { TypedEventEmitter } from './events.js';
4
+ export { ConversationStore } from './conversation.js';
5
+ export { Orchestrator } from './orchestrator.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,WAAW,EACX,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { TypedEventEmitter } from './events.js';
2
+ export { ConversationStore } from './conversation.js';
3
+ export { Orchestrator } from './orchestrator.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { TypedEventEmitter } from './events.js';
2
+ import type { Message, ToolCall, ToolResult } from './types.js';
3
+ export interface CerebrumAdapter {
4
+ stream(messages: Message[], tools: Record<string, ToolDefinition>, callbacks: StreamCallbacks): Promise<void>;
5
+ }
6
+ export interface ToolDefinition {
7
+ description: string;
8
+ parameters: Record<string, unknown>;
9
+ execute: (args: Record<string, unknown>) => Promise<string>;
10
+ }
11
+ export interface StreamCallbacks {
12
+ onChunk: (chunk: string) => void;
13
+ onToolCall: (toolCall: ToolCall) => Promise<ToolResult>;
14
+ onFinish: (content: string) => void;
15
+ onError: (error: Error) => void;
16
+ }
17
+ export declare class Orchestrator extends TypedEventEmitter {
18
+ private conversations;
19
+ private cerebrum;
20
+ private tools;
21
+ private activeConversationId;
22
+ constructor();
23
+ setCerebrum(cerebrum: CerebrumAdapter): void;
24
+ registerTool(name: string, tool: ToolDefinition): void;
25
+ getActiveConversationId(): string | null;
26
+ getConversation(id: string): import("./types.js").Conversation | undefined;
27
+ getMessages(conversationId?: string): Message[];
28
+ startConversation(): string;
29
+ sendMessage(content: string, conversationId?: string): Promise<void>;
30
+ start(): Promise<void>;
31
+ stop(): Promise<void>;
32
+ }
33
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,MAAM,CACJ,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EACrC,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,UAAU,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACjC;AAED,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,OAAO,CAAC,aAAa,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,oBAAoB,CAAuB;;IAOnD,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAI5C,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI;IAItD,uBAAuB,IAAI,MAAM,GAAG,IAAI;IAIxC,eAAe,CAAC,EAAE,EAAE,MAAM;IAI1B,WAAW,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE;IAM/C,iBAAiB,IAAI,MAAM;IAMrB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEpE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
@@ -0,0 +1,105 @@
1
+ import { TypedEventEmitter } from './events.js';
2
+ import { ConversationStore } from './conversation.js';
3
+ export class Orchestrator extends TypedEventEmitter {
4
+ conversations;
5
+ cerebrum = null;
6
+ tools = new Map();
7
+ activeConversationId = null;
8
+ constructor() {
9
+ super();
10
+ this.conversations = new ConversationStore();
11
+ }
12
+ setCerebrum(cerebrum) {
13
+ this.cerebrum = cerebrum;
14
+ }
15
+ registerTool(name, tool) {
16
+ this.tools.set(name, tool);
17
+ }
18
+ getActiveConversationId() {
19
+ return this.activeConversationId;
20
+ }
21
+ getConversation(id) {
22
+ return this.conversations.get(id);
23
+ }
24
+ getMessages(conversationId) {
25
+ const id = conversationId ?? this.activeConversationId;
26
+ if (!id)
27
+ return [];
28
+ return this.conversations.getMessages(id);
29
+ }
30
+ startConversation() {
31
+ const conversation = this.conversations.create();
32
+ this.activeConversationId = conversation.id;
33
+ return conversation.id;
34
+ }
35
+ async sendMessage(content, conversationId) {
36
+ if (!this.cerebrum)
37
+ throw new Error('Cerebrum not connected');
38
+ const convId = conversationId ?? this.activeConversationId;
39
+ if (!convId)
40
+ throw new Error('No active conversation');
41
+ const userMessage = this.conversations.appendMessage(convId, 'user', content);
42
+ this.emit({ type: 'message:user', message: userMessage });
43
+ this.emit({ type: 'message:cerebrum:start', conversationId: convId });
44
+ const messages = this.conversations.getMessages(convId);
45
+ const toolDefs = Object.fromEntries(this.tools);
46
+ let fullContent = '';
47
+ try {
48
+ await this.cerebrum.stream(messages, toolDefs, {
49
+ onChunk: (chunk) => {
50
+ fullContent += chunk;
51
+ this.emit({ type: 'message:cerebrum:chunk', chunk });
52
+ },
53
+ onToolCall: async (toolCall) => {
54
+ this.emit({ type: 'message:cerebrum:toolcall', toolCall });
55
+ this.emit({ type: 'tool:start', callId: toolCall.id, name: toolCall.name });
56
+ const tool = this.tools.get(toolCall.name);
57
+ let result;
58
+ if (tool) {
59
+ try {
60
+ const output = await tool.execute(toolCall.args);
61
+ result = { callId: toolCall.id, output, isError: false };
62
+ }
63
+ catch (err) {
64
+ result = {
65
+ callId: toolCall.id,
66
+ output: err instanceof Error ? err.message : String(err),
67
+ isError: true,
68
+ };
69
+ }
70
+ }
71
+ else {
72
+ result = { callId: toolCall.id, output: `Unknown tool: ${toolCall.name}`, isError: true };
73
+ }
74
+ this.emit({ type: 'tool:end', result });
75
+ this.conversations.appendMessage(convId, 'tool', result.output, {
76
+ toolResult: result,
77
+ });
78
+ return result;
79
+ },
80
+ onFinish: (content) => {
81
+ const cerebrumMessage = this.conversations.appendMessage(convId, 'cerebrum', content);
82
+ this.emit({ type: 'message:cerebrum:end', message: cerebrumMessage });
83
+ },
84
+ onError: (error) => {
85
+ this.emit({ type: 'error', error });
86
+ },
87
+ });
88
+ }
89
+ catch (error) {
90
+ this.emit({
91
+ type: 'error',
92
+ error: error instanceof Error ? error : new Error(String(error)),
93
+ });
94
+ }
95
+ }
96
+ async start() {
97
+ if (!this.activeConversationId) {
98
+ this.startConversation();
99
+ }
100
+ }
101
+ async stop() {
102
+ this.removeAllListeners();
103
+ }
104
+ }
105
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAwBtD,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IACzC,aAAa,CAAoB;IACjC,QAAQ,GAA2B,IAAI,CAAC;IACxC,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC1C,oBAAoB,GAAkB,IAAI,CAAC;IAEnD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC/C,CAAC;IAED,WAAW,CAAC,QAAyB;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,IAAoB;QAC7C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,eAAe,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,cAAuB;QACjC,MAAM,EAAE,GAAG,cAAc,IAAI,IAAI,CAAC,oBAAoB,CAAC;QACvD,IAAI,CAAC,EAAE;YAAE,OAAO,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CA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,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;wBAC9D,UAAU,EAAE,MAAM;qBACnB,CAAC,CAAC;oBAEH,OAAO,MAAM,CAAC;gBAChB,CAAC;gBACD,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE;oBACpB,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;oBACtF,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;gBACxE,CAAC;gBACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBACjB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;gBACtC,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACjE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ export type MessageRole = 'user' | 'cerebrum' | 'cerebellum' | 'tool' | 'system';
2
+ export interface ToolCall {
3
+ id: string;
4
+ name: string;
5
+ args: Record<string, unknown>;
6
+ }
7
+ export interface ToolResult {
8
+ callId: string;
9
+ output: string;
10
+ isError: boolean;
11
+ }
12
+ export interface Message {
13
+ id: string;
14
+ role: MessageRole;
15
+ content: string;
16
+ toolCalls?: ToolCall[];
17
+ toolResult?: ToolResult;
18
+ timestamp: number;
19
+ metadata?: Record<string, unknown>;
20
+ }
21
+ export interface Conversation {
22
+ id: string;
23
+ messages: Message[];
24
+ createdAt: number;
25
+ updatedAt: number;
26
+ }
27
+ export interface TaskAction {
28
+ taskId: string;
29
+ action: 'invoke' | 'skip' | 'defer' | 'cancel';
30
+ reason: string;
31
+ }
32
+ export interface CerebellumStatus {
33
+ healthy: boolean;
34
+ modelName: string;
35
+ uptimeSeconds: number;
36
+ tasksRegistered: number;
37
+ }
38
+ export interface OrchestratorConfig {
39
+ cerebrum: {
40
+ defaultProvider: string;
41
+ defaultModel: string;
42
+ };
43
+ cerebellum: {
44
+ enabled: boolean;
45
+ address: string;
46
+ };
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjF,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE;QACR,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@cereworker/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/Producible/CereWorker.git",
16
+ "directory": "packages/core"
17
+ },
18
+ "dependencies": {
19
+ "nanoid": "^5.0.9",
20
+ "@cereworker/config": "0.1.0"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "^5.7.3"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "typecheck": "tsc --noEmit",
28
+ "lint": "eslint src/",
29
+ "clean": "rm -rf dist"
30
+ }
31
+ }