@agentxjs/core 2.0.0 → 3.0.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.
- package/dist/{Processor-DT0N1qI6.d.ts → Processor-CeMyXtsX.d.ts} +1 -1
- package/dist/agent/engine/internal/index.d.ts +4 -5
- package/dist/agent/engine/internal/index.js +1 -1
- package/dist/agent/engine/mealy/index.d.ts +4 -4
- package/dist/agent/engine/mealy/index.js +1 -1
- package/dist/agent/index.d.ts +91 -91
- package/dist/agent/index.js +6 -6
- package/dist/agent/types/index.d.ts +4 -4
- package/dist/agent/types/index.js +1 -1
- package/dist/bash/index.d.ts +4 -4
- package/dist/{chunk-LTVNPHST.js → chunk-22NTRYNO.js} +60 -60
- package/dist/chunk-22NTRYNO.js.map +1 -0
- package/dist/{chunk-7ZDX3O6I.js → chunk-AAFPAF67.js} +2 -2
- package/dist/{chunk-7ZDX3O6I.js.map → chunk-AAFPAF67.js.map} +1 -1
- package/dist/{chunk-EKHT54KN.js → chunk-APCBNCOW.js} +1 -1
- package/dist/{chunk-EKHT54KN.js.map → chunk-APCBNCOW.js.map} +1 -1
- package/dist/{chunk-JTKCV7IS.js → chunk-RWIYC65R.js} +111 -111
- package/dist/{chunk-JTKCV7IS.js.map → chunk-RWIYC65R.js.map} +1 -1
- package/dist/{chunk-DEAR6N3O.js → chunk-TUFZ2YH6.js} +1 -1
- package/dist/chunk-TUFZ2YH6.js.map +1 -0
- package/dist/{chunk-23UUBQXR.js → chunk-YSZG6XIM.js} +1 -1
- package/dist/chunk-YSZG6XIM.js.map +1 -0
- package/dist/{combinators-nEa5dD0T.d.ts → combinators-Dy-7lxKV.d.ts} +50 -50
- package/dist/common/logger/index.js +14 -14
- package/dist/common/logger/index.js.map +1 -1
- package/dist/container/index.d.ts +3 -3
- package/dist/driver/index.d.ts +2 -2
- package/dist/event/index.d.ts +1 -1
- package/dist/event/index.js +2 -2
- package/dist/event/types/index.d.ts +199 -199
- package/dist/event/types/index.js +1 -1
- package/dist/{event-DNWOBSBO.d.ts → event-DNsF9EkO.d.ts} +4 -6
- package/dist/image/index.d.ts +3 -3
- package/dist/image/index.js.map +1 -1
- package/dist/{index-CuS1i5V-.d.ts → index--gxNpY5W.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/{message-03TJzvIX.d.ts → message-Dn-I2vr0.d.ts} +1 -1
- package/dist/mq/index.d.ts +25 -25
- package/dist/mq/index.js +1 -1
- package/dist/mq/index.js.map +1 -1
- package/dist/network/index.d.ts +2 -220
- package/dist/network/index.js +27 -27
- package/dist/network/index.js.map +1 -1
- package/dist/persistence/index.d.ts +2 -2
- package/dist/platform/index.d.ts +14 -6
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/index.js.map +1 -1
- package/dist/session/index.d.ts +3 -3
- package/dist/{RpcClient-BcJ_zAGu.d.ts → types-CTV8Z9PI.d.ts} +225 -7
- package/dist/{types-aE74Eo6G.d.ts → types-Cb8tKM6Y.d.ts} +1 -1
- package/package.json +1 -1
- package/src/agent/AgentStateMachine.ts +2 -2
- package/src/agent/__tests__/AgentStateMachine.test.ts +2 -2
- package/src/agent/__tests__/createAgent.test.ts +4 -4
- package/src/agent/__tests__/engine/internal/messageAssemblerProcessor.test.ts +10 -10
- package/src/agent/__tests__/engine/internal/stateEventProcessor.test.ts +6 -6
- package/src/agent/__tests__/engine/internal/turnTrackerProcessor.test.ts +4 -4
- package/src/agent/__tests__/engine/mealy/Mealy.test.ts +3 -3
- package/src/agent/__tests__/engine/mealy/Store.test.ts +1 -1
- package/src/agent/__tests__/engine/mealy/combinators.test.ts +4 -4
- package/src/agent/createAgent.ts +15 -15
- package/src/agent/engine/AgentProcessor.ts +7 -7
- package/src/agent/engine/MealyMachine.ts +3 -3
- package/src/agent/engine/internal/index.ts +11 -11
- package/src/agent/engine/internal/messageAssemblerProcessor.ts +14 -14
- package/src/agent/engine/internal/stateEventProcessor.ts +13 -15
- package/src/agent/engine/internal/turnTrackerProcessor.ts +4 -4
- package/src/agent/engine/mealy/Mealy.ts +2 -2
- package/src/agent/engine/mealy/combinators.ts +10 -10
- package/src/agent/engine/mealy/index.ts +9 -11
- package/src/agent/index.ts +30 -32
- package/src/agent/types/engine.ts +3 -3
- package/src/agent/types/event.ts +4 -8
- package/src/agent/types/index.ts +85 -85
- package/src/bash/index.ts +1 -1
- package/src/common/logger/ConsoleLogger.ts +1 -1
- package/src/common/logger/LoggerFactoryImpl.ts +14 -14
- package/src/common/logger/index.ts +3 -3
- package/src/container/index.ts +4 -5
- package/src/container/types.ts +1 -1
- package/src/driver/index.ts +15 -17
- package/src/driver/types.ts +89 -79
- package/src/event/EventBus.ts +10 -10
- package/src/event/__tests__/EventBus.test.ts +1 -1
- package/src/event/index.ts +2 -3
- package/src/event/types/agent.ts +186 -180
- package/src/event/types/bus.ts +1 -1
- package/src/event/types/command.ts +292 -265
- package/src/event/types/container.ts +207 -222
- package/src/event/types/driver.ts +153 -155
- package/src/event/types/index.ts +6 -12
- package/src/event/types/session.ts +117 -130
- package/src/image/Image.ts +1 -1
- package/src/image/index.ts +4 -5
- package/src/mq/OffsetGenerator.ts +1 -1
- package/src/mq/__tests__/OffsetGenerator.test.ts +1 -1
- package/src/mq/index.ts +4 -5
- package/src/network/RpcClient.ts +10 -10
- package/src/network/index.ts +41 -44
- package/src/network/jsonrpc.ts +5 -5
- package/src/persistence/index.ts +5 -5
- package/src/platform/types.ts +15 -5
- package/src/runtime/AgentXRuntime.ts +15 -15
- package/src/runtime/__tests__/AgentXRuntime.test.ts +5 -5
- package/src/runtime/index.ts +5 -6
- package/src/runtime/types.ts +1 -1
- package/src/session/index.ts +2 -3
- package/dist/chunk-23UUBQXR.js.map +0 -1
- package/dist/chunk-DEAR6N3O.js.map +0 -1
- package/dist/chunk-LTVNPHST.js.map +0 -1
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* Tests the stateless event transformer: Stream Events -> State Events
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
8
8
|
import {
|
|
9
|
-
stateEventProcessor,
|
|
10
9
|
createInitialStateEventProcessorContext,
|
|
11
10
|
type StateEventProcessorContext,
|
|
12
11
|
type StateEventProcessorInput,
|
|
13
12
|
type StateEventProcessorOutput,
|
|
13
|
+
stateEventProcessor,
|
|
14
14
|
} from "../../../engine/internal/stateEventProcessor";
|
|
15
15
|
|
|
16
16
|
// Helper to create test events
|
|
@@ -67,7 +67,7 @@ describe("stateEventProcessor", () => {
|
|
|
67
67
|
it("should emit conversation_end for end_turn stop reason", () => {
|
|
68
68
|
const event = createStreamEvent("message_stop", { stopReason: "end_turn" });
|
|
69
69
|
|
|
70
|
-
const [
|
|
70
|
+
const [_newContext, outputs] = stateEventProcessor(context, event);
|
|
71
71
|
|
|
72
72
|
expect(outputs).toHaveLength(1);
|
|
73
73
|
expect(outputs[0].type).toBe("conversation_end");
|
|
@@ -106,7 +106,7 @@ describe("stateEventProcessor", () => {
|
|
|
106
106
|
it("should emit conversation_responding event", () => {
|
|
107
107
|
const event = createStreamEvent("text_delta", { text: "Hello" });
|
|
108
108
|
|
|
109
|
-
const [
|
|
109
|
+
const [_newContext, outputs] = stateEventProcessor(context, event);
|
|
110
110
|
|
|
111
111
|
expect(outputs).toHaveLength(1);
|
|
112
112
|
expect(outputs[0].type).toBe("conversation_responding");
|
|
@@ -122,7 +122,7 @@ describe("stateEventProcessor", () => {
|
|
|
122
122
|
toolName: "search",
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
const [
|
|
125
|
+
const [_newContext, outputs] = stateEventProcessor(context, event);
|
|
126
126
|
|
|
127
127
|
expect(outputs).toHaveLength(2);
|
|
128
128
|
|
|
@@ -157,7 +157,7 @@ describe("stateEventProcessor", () => {
|
|
|
157
157
|
errorCode: "rate_limit",
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
const [
|
|
160
|
+
const [_newContext, outputs] = stateEventProcessor(context, event);
|
|
161
161
|
|
|
162
162
|
expect(outputs).toHaveLength(1);
|
|
163
163
|
expect(outputs[0].type).toBe("error_occurred");
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* - message_stop → turn_response
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
11
11
|
import {
|
|
12
|
-
turnTrackerProcessor,
|
|
13
12
|
createInitialTurnTrackerState,
|
|
14
|
-
type TurnTrackerState,
|
|
15
13
|
type TurnTrackerInput,
|
|
16
14
|
type TurnTrackerOutput,
|
|
15
|
+
type TurnTrackerState,
|
|
16
|
+
turnTrackerProcessor,
|
|
17
17
|
} from "../../../engine/internal/turnTrackerProcessor";
|
|
18
18
|
|
|
19
19
|
// Helper to create test events
|
|
@@ -77,7 +77,7 @@ describe("turnTrackerProcessor", () => {
|
|
|
77
77
|
const [state2] = turnTrackerProcessor(state1, createMessageStopEvent("end_turn"));
|
|
78
78
|
|
|
79
79
|
// Start new turn
|
|
80
|
-
const [
|
|
80
|
+
const [_state3, outputs3] = turnTrackerProcessor(state2, createMessageStartEvent("msg_2"));
|
|
81
81
|
|
|
82
82
|
expect(outputs1[0].data.turnId).not.toBe(outputs3[0].data.turnId);
|
|
83
83
|
});
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Mealy.test.ts - Unit tests for Mealy Machine runtime
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { MemoryStore } from "../../../engine/mealy/Store";
|
|
5
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
6
|
+
import { createMealy, Mealy, type MealyConfig } from "../../../engine/mealy/Mealy";
|
|
8
7
|
import type { Processor } from "../../../engine/mealy/Processor";
|
|
9
8
|
import type { Sink, SinkDefinition } from "../../../engine/mealy/Sink";
|
|
9
|
+
import { MemoryStore } from "../../../engine/mealy/Store";
|
|
10
10
|
|
|
11
11
|
// Test types
|
|
12
12
|
interface TestState {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Store.test.ts - Unit tests for MemoryStore
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
6
6
|
import { MemoryStore, type Store } from "../../../engine/mealy/Store";
|
|
7
7
|
|
|
8
8
|
describe("MemoryStore", () => {
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* combinators.test.ts - Unit tests for Mealy processor combinators
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { describe,
|
|
5
|
+
import { describe, expect, it } from "bun:test";
|
|
6
6
|
import {
|
|
7
|
-
combineProcessors,
|
|
8
|
-
combineInitialStates,
|
|
9
7
|
chainProcessors,
|
|
8
|
+
combineInitialStates,
|
|
9
|
+
combineProcessors,
|
|
10
10
|
filterProcessor,
|
|
11
|
+
identityProcessor,
|
|
11
12
|
mapOutput,
|
|
12
13
|
withLogging,
|
|
13
|
-
identityProcessor,
|
|
14
14
|
} from "../../../engine/mealy/combinators";
|
|
15
15
|
import type { Processor } from "../../../engine/mealy/Processor";
|
|
16
16
|
|
package/src/agent/createAgent.ts
CHANGED
|
@@ -21,29 +21,29 @@
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { createLogger } from "commonxjs/logger";
|
|
25
|
+
import { isDriveableEvent } from "../event";
|
|
26
|
+
import { AgentStateMachine } from "./AgentStateMachine";
|
|
27
|
+
import { MealyMachine } from "./engine/MealyMachine";
|
|
24
28
|
import type {
|
|
25
29
|
AgentEngine,
|
|
26
|
-
|
|
30
|
+
AgentEventBus,
|
|
31
|
+
AgentInterceptor,
|
|
32
|
+
AgentMiddleware,
|
|
33
|
+
AgentOutput,
|
|
27
34
|
AgentOutputCallback,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
AgentPresenter,
|
|
36
|
+
AgentSource,
|
|
37
|
+
AgentState,
|
|
38
|
+
CreateAgentOptions,
|
|
31
39
|
EventHandlerMap,
|
|
40
|
+
MessageQueue,
|
|
32
41
|
ReactHandlerMap,
|
|
33
|
-
|
|
34
|
-
CreateAgentOptions,
|
|
35
|
-
AgentSource,
|
|
36
|
-
AgentPresenter,
|
|
37
|
-
AgentEventBus,
|
|
42
|
+
StateChangeHandler,
|
|
38
43
|
StreamEvent,
|
|
39
44
|
Unsubscribe,
|
|
40
|
-
|
|
41
|
-
AgentInterceptor,
|
|
45
|
+
UserMessage,
|
|
42
46
|
} from "./types";
|
|
43
|
-
import { MealyMachine } from "./engine/MealyMachine";
|
|
44
|
-
import { AgentStateMachine } from "./AgentStateMachine";
|
|
45
|
-
import { createLogger } from "commonxjs/logger";
|
|
46
|
-
import { isDriveableEvent } from "../event";
|
|
47
47
|
|
|
48
48
|
const logger = createLogger("agent/AgentEngine");
|
|
49
49
|
|
|
@@ -5,24 +5,24 @@
|
|
|
5
5
|
* Composes MessageAssembler, StateMachine, and TurnTracker processors.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type { AgentOutput } from "../types";
|
|
9
9
|
// Note: StreamEventType and MessageEventType are part of AgentOutput (from Presenter)
|
|
10
10
|
// They flow through the system but AgentProcessor doesn't need to import them directly
|
|
11
11
|
import {
|
|
12
|
-
messageAssemblerProcessor,
|
|
13
|
-
stateEventProcessor,
|
|
14
|
-
turnTrackerProcessor,
|
|
15
12
|
createInitialMessageAssemblerState,
|
|
16
13
|
createInitialStateEventProcessorContext,
|
|
17
14
|
createInitialTurnTrackerState,
|
|
15
|
+
type MessageAssemblerOutput,
|
|
18
16
|
type MessageAssemblerState,
|
|
17
|
+
messageAssemblerProcessor,
|
|
19
18
|
type StateEventProcessorContext,
|
|
20
|
-
type TurnTrackerState,
|
|
21
|
-
type MessageAssemblerOutput,
|
|
22
19
|
type StateEventProcessorOutput,
|
|
20
|
+
stateEventProcessor,
|
|
23
21
|
type TurnTrackerOutput,
|
|
22
|
+
type TurnTrackerState,
|
|
23
|
+
turnTrackerProcessor,
|
|
24
24
|
} from "./internal";
|
|
25
|
-
import type
|
|
25
|
+
import { combineInitialStates, combineProcessors, type Processor } from "./mealy";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Combined state type for the full agent engine
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
|
+
import { createLogger } from "commonxjs/logger";
|
|
49
|
+
import type { AgentOutput, StreamEvent } from "../types";
|
|
48
50
|
import {
|
|
51
|
+
type AgentEngineState,
|
|
49
52
|
agentProcessor,
|
|
50
53
|
createInitialAgentEngineState,
|
|
51
|
-
type AgentEngineState,
|
|
52
54
|
} from "./AgentProcessor";
|
|
53
55
|
import { MemoryStore } from "./mealy";
|
|
54
|
-
import type { AgentOutput, StreamEvent } from "../types";
|
|
55
|
-
import { createLogger } from "commonxjs/logger";
|
|
56
56
|
|
|
57
57
|
const logger = createLogger("engine/MealyMachine");
|
|
58
58
|
|
|
@@ -6,30 +6,30 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
|
-
|
|
10
|
-
messageAssemblerProcessorDef,
|
|
9
|
+
createInitialMessageAssemblerState,
|
|
11
10
|
type MessageAssemblerInput,
|
|
12
11
|
type MessageAssemblerOutput,
|
|
13
12
|
type MessageAssemblerState,
|
|
13
|
+
messageAssemblerProcessor,
|
|
14
|
+
messageAssemblerProcessorDef,
|
|
14
15
|
type PendingContent,
|
|
15
|
-
createInitialMessageAssemblerState,
|
|
16
16
|
} from "./messageAssemblerProcessor";
|
|
17
17
|
|
|
18
18
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
createInitialStateEventProcessorContext,
|
|
20
|
+
type StateEventProcessorContext,
|
|
21
21
|
type StateEventProcessorInput,
|
|
22
22
|
type StateEventProcessorOutput,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
stateEventProcessor,
|
|
24
|
+
stateEventProcessorDef,
|
|
25
25
|
} from "./stateEventProcessor";
|
|
26
26
|
|
|
27
27
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
createInitialTurnTrackerState,
|
|
29
|
+
type PendingTurn,
|
|
30
30
|
type TurnTrackerInput,
|
|
31
31
|
type TurnTrackerOutput,
|
|
32
32
|
type TurnTrackerState,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
turnTrackerProcessor,
|
|
34
|
+
turnTrackerProcessorDef,
|
|
35
35
|
} from "./turnTrackerProcessor";
|
|
@@ -18,29 +18,29 @@
|
|
|
18
18
|
* - tool_result_message (Message - tool execution result)
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import type { Processor, ProcessorDefinition } from "../mealy";
|
|
22
21
|
import type {
|
|
23
|
-
// Input: StreamEvent (from agent layer)
|
|
24
|
-
StreamEvent,
|
|
25
|
-
MessageStartEvent,
|
|
26
|
-
TextDeltaEvent,
|
|
27
|
-
ToolUseStartEvent,
|
|
28
|
-
InputJsonDeltaEvent,
|
|
29
|
-
ToolResultEvent,
|
|
30
|
-
MessageStopEvent,
|
|
31
|
-
// Output: Message events
|
|
32
|
-
AssistantMessageEvent,
|
|
33
|
-
ToolResultMessageEvent,
|
|
34
|
-
ErrorMessageEvent,
|
|
35
22
|
// Message types
|
|
36
23
|
AssistantMessage,
|
|
37
|
-
|
|
24
|
+
// Output: Message events
|
|
25
|
+
AssistantMessageEvent,
|
|
38
26
|
ErrorMessage,
|
|
27
|
+
ErrorMessageEvent,
|
|
28
|
+
InputJsonDeltaEvent,
|
|
29
|
+
MessageStartEvent,
|
|
30
|
+
MessageStopEvent,
|
|
31
|
+
// Input: StreamEvent (from agent layer)
|
|
32
|
+
StreamEvent,
|
|
33
|
+
TextDeltaEvent,
|
|
39
34
|
// Content parts
|
|
40
35
|
TextPart,
|
|
41
36
|
ToolCallPart,
|
|
37
|
+
ToolResultEvent,
|
|
38
|
+
ToolResultMessage,
|
|
39
|
+
ToolResultMessageEvent,
|
|
42
40
|
ToolResultPart,
|
|
41
|
+
ToolUseStartEvent,
|
|
43
42
|
} from "../../types";
|
|
43
|
+
import type { Processor, ProcessorDefinition } from "../mealy";
|
|
44
44
|
|
|
45
45
|
// ===== State Types =====
|
|
46
46
|
|
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
* - tool_executing
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import
|
|
21
|
+
import { createLogger } from "commonxjs/logger";
|
|
22
22
|
import type {
|
|
23
|
+
ConversationEndEvent,
|
|
24
|
+
ConversationInterruptedEvent,
|
|
25
|
+
ConversationRespondingEvent,
|
|
26
|
+
// Output: State events
|
|
27
|
+
ConversationStartEvent,
|
|
23
28
|
// Base type
|
|
24
29
|
EngineEvent,
|
|
25
|
-
|
|
26
|
-
StreamEvent,
|
|
30
|
+
ErrorOccurredEvent,
|
|
27
31
|
MessageStartEvent,
|
|
28
32
|
MessageStopEvent,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ConversationStartEvent,
|
|
32
|
-
ConversationRespondingEvent,
|
|
33
|
-
ConversationEndEvent,
|
|
34
|
-
ConversationInterruptedEvent,
|
|
35
|
-
ToolPlannedEvent,
|
|
33
|
+
// Input: StreamEvent (from agent layer)
|
|
34
|
+
StreamEvent,
|
|
36
35
|
ToolExecutingEvent,
|
|
37
|
-
|
|
36
|
+
ToolPlannedEvent,
|
|
37
|
+
ToolUseStartEvent,
|
|
38
38
|
} from "../../types";
|
|
39
|
-
import {
|
|
39
|
+
import type { Processor, ProcessorDefinition } from "../mealy";
|
|
40
40
|
|
|
41
41
|
const logger = createLogger("engine/stateEventProcessor");
|
|
42
42
|
|
|
@@ -50,9 +50,7 @@ const logger = createLogger("engine/stateEventProcessor");
|
|
|
50
50
|
*
|
|
51
51
|
* Currently empty - no context needed as all information comes from events.
|
|
52
52
|
*/
|
|
53
|
-
export
|
|
54
|
-
// Empty - all information comes from events
|
|
55
|
-
}
|
|
53
|
+
export type StateEventProcessorContext = {};
|
|
56
54
|
|
|
57
55
|
/**
|
|
58
56
|
* Initial context factory for StateEventProcessor
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
* - turn_response
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type { Processor, ProcessorDefinition } from "../mealy";
|
|
17
16
|
import type {
|
|
18
|
-
StreamEvent,
|
|
19
17
|
MessageStartEvent,
|
|
20
18
|
MessageStopEvent,
|
|
19
|
+
StreamEvent,
|
|
20
|
+
// Data types
|
|
21
|
+
TokenUsage,
|
|
21
22
|
// Output: Turn events
|
|
22
23
|
TurnRequestEvent,
|
|
23
24
|
TurnResponseEvent,
|
|
24
|
-
// Data types
|
|
25
|
-
TokenUsage,
|
|
26
25
|
} from "../../types";
|
|
26
|
+
import type { Processor, ProcessorDefinition } from "../mealy";
|
|
27
27
|
|
|
28
28
|
// ===== State Types =====
|
|
29
29
|
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
import { createLogger } from "commonxjs/logger";
|
|
34
35
|
import type { Processor } from "./Processor";
|
|
35
|
-
import type { Store } from "./Store";
|
|
36
36
|
import type { Sink, SinkDefinition } from "./Sink";
|
|
37
|
-
import {
|
|
37
|
+
import type { Store } from "./Store";
|
|
38
38
|
|
|
39
39
|
const logger = createLogger("engine/Mealy");
|
|
40
40
|
|
|
@@ -28,13 +28,11 @@ import type { Processor } from "./Processor";
|
|
|
28
28
|
* });
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export function combineProcessors<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
[K in keyof TState]: Processor<TState[K], TInput, TOutput>;
|
|
37
|
-
}): Processor<TState, TInput, TOutput> {
|
|
31
|
+
export function combineProcessors<TState extends Record<string, unknown>, TInput, TOutput>(
|
|
32
|
+
processors: {
|
|
33
|
+
[K in keyof TState]: Processor<TState[K], TInput, TOutput>;
|
|
34
|
+
}
|
|
35
|
+
): Processor<TState, TInput, TOutput> {
|
|
38
36
|
return (state: Readonly<TState>, event: TInput): [TState, TOutput[]] => {
|
|
39
37
|
const newState = {} as TState;
|
|
40
38
|
const allOutputs: TOutput[] = [];
|
|
@@ -55,9 +53,11 @@ export function combineProcessors<
|
|
|
55
53
|
/**
|
|
56
54
|
* combineInitialStates - Helper to create initial state for combined processors
|
|
57
55
|
*/
|
|
58
|
-
export function combineInitialStates<TState extends Record<string, unknown>>(
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
export function combineInitialStates<TState extends Record<string, unknown>>(
|
|
57
|
+
initialStates: {
|
|
58
|
+
[K in keyof TState]: () => TState[K];
|
|
59
|
+
}
|
|
60
|
+
): () => TState {
|
|
61
61
|
return () => {
|
|
62
62
|
const state = {} as TState;
|
|
63
63
|
for (const key in initialStates) {
|
|
@@ -16,30 +16,28 @@
|
|
|
16
16
|
|
|
17
17
|
// ===== Core Components =====
|
|
18
18
|
|
|
19
|
-
// Source - Input (input adapter)
|
|
20
|
-
export { type Source, type SourceDefinition } from "./Source";
|
|
21
|
-
|
|
22
19
|
// Processor - Processing (pure Mealy transition function)
|
|
23
|
-
export {
|
|
24
|
-
|
|
20
|
+
export type { Processor, ProcessorDefinition, ProcessorResult } from "./Processor";
|
|
25
21
|
// Sink - Output (output adapter)
|
|
26
|
-
export {
|
|
22
|
+
export type { Sink, SinkDefinition } from "./Sink";
|
|
23
|
+
// Source - Input (input adapter)
|
|
24
|
+
export type { Source, SourceDefinition } from "./Source";
|
|
27
25
|
|
|
28
26
|
// Store - State storage
|
|
29
|
-
export { type Store
|
|
27
|
+
export { MemoryStore, type Store } from "./Store";
|
|
30
28
|
|
|
31
29
|
// ===== Mealy Runtime =====
|
|
32
30
|
|
|
33
|
-
export {
|
|
31
|
+
export { createMealy, Mealy, type MealyConfig, type ProcessResult } from "./Mealy";
|
|
34
32
|
|
|
35
33
|
// ===== Combinators =====
|
|
36
34
|
|
|
37
35
|
export {
|
|
38
|
-
combineProcessors,
|
|
39
|
-
combineInitialStates,
|
|
40
36
|
chainProcessors,
|
|
37
|
+
combineInitialStates,
|
|
38
|
+
combineProcessors,
|
|
41
39
|
filterProcessor,
|
|
40
|
+
identityProcessor,
|
|
42
41
|
mapOutput,
|
|
43
42
|
withLogging,
|
|
44
|
-
identityProcessor,
|
|
45
43
|
} from "./combinators";
|
package/src/agent/index.ts
CHANGED
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
// Core API
|
|
31
31
|
// ============================================================================
|
|
32
32
|
|
|
33
|
-
export { createAgent } from "./createAgent";
|
|
34
33
|
export { AgentStateMachine } from "./AgentStateMachine";
|
|
34
|
+
export { createAgent } from "./createAgent";
|
|
35
35
|
export type { AgentEngine, CreateAgentOptions } from "./types";
|
|
36
36
|
|
|
37
37
|
// ============================================================================
|
|
@@ -44,63 +44,61 @@ export * from "./types";
|
|
|
44
44
|
// Engine (Stateless)
|
|
45
45
|
// ============================================================================
|
|
46
46
|
|
|
47
|
-
// MealyMachine
|
|
48
|
-
export { MealyMachine, createMealyMachine } from "./engine/MealyMachine";
|
|
49
|
-
|
|
50
47
|
// AgentProcessor (for advanced use cases)
|
|
51
48
|
export {
|
|
52
|
-
agentProcessor,
|
|
53
|
-
createInitialAgentEngineState,
|
|
54
49
|
type AgentEngineState,
|
|
55
50
|
type AgentProcessorInput,
|
|
56
51
|
type AgentProcessorOutput,
|
|
52
|
+
agentProcessor,
|
|
53
|
+
createInitialAgentEngineState,
|
|
57
54
|
} from "./engine/AgentProcessor";
|
|
58
|
-
|
|
59
55
|
// Internal Processors (for advanced use cases)
|
|
60
56
|
export {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
createInitialMessageAssemblerState,
|
|
58
|
+
createInitialStateEventProcessorContext,
|
|
59
|
+
createInitialTurnTrackerState,
|
|
64
60
|
type MessageAssemblerInput,
|
|
65
61
|
type MessageAssemblerOutput,
|
|
66
62
|
type MessageAssemblerState,
|
|
63
|
+
// MessageAssembler
|
|
64
|
+
messageAssemblerProcessor,
|
|
65
|
+
messageAssemblerProcessorDef,
|
|
67
66
|
type PendingContent,
|
|
68
|
-
|
|
67
|
+
type PendingTurn,
|
|
68
|
+
type StateEventProcessorContext,
|
|
69
|
+
type StateEventProcessorInput,
|
|
70
|
+
type StateEventProcessorOutput,
|
|
69
71
|
// StateEventProcessor
|
|
70
72
|
stateEventProcessor,
|
|
71
73
|
stateEventProcessorDef,
|
|
72
|
-
type StateEventProcessorInput,
|
|
73
|
-
type StateEventProcessorOutput,
|
|
74
|
-
type StateEventProcessorContext,
|
|
75
|
-
createInitialStateEventProcessorContext,
|
|
76
|
-
// TurnTracker
|
|
77
|
-
turnTrackerProcessor,
|
|
78
|
-
turnTrackerProcessorDef,
|
|
79
74
|
type TurnTrackerInput,
|
|
80
75
|
type TurnTrackerOutput,
|
|
81
76
|
type TurnTrackerState,
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
// TurnTracker
|
|
78
|
+
turnTrackerProcessor,
|
|
79
|
+
turnTrackerProcessorDef,
|
|
84
80
|
} from "./engine/internal";
|
|
81
|
+
// MealyMachine
|
|
82
|
+
export { createMealyMachine, MealyMachine } from "./engine/MealyMachine";
|
|
85
83
|
|
|
86
84
|
// Mealy Machine Core (for building custom processors)
|
|
87
85
|
export {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
chainProcessors,
|
|
87
|
+
combineInitialStates,
|
|
88
|
+
// Combinators
|
|
89
|
+
combineProcessors,
|
|
90
|
+
filterProcessor,
|
|
91
|
+
identityProcessor,
|
|
92
|
+
MemoryStore,
|
|
93
|
+
mapOutput,
|
|
91
94
|
type Processor,
|
|
92
|
-
type ProcessorResult,
|
|
93
95
|
type ProcessorDefinition,
|
|
96
|
+
type ProcessorResult,
|
|
94
97
|
type Sink,
|
|
95
98
|
type SinkDefinition,
|
|
99
|
+
// Core types
|
|
100
|
+
type Source,
|
|
101
|
+
type SourceDefinition,
|
|
96
102
|
type Store,
|
|
97
|
-
MemoryStore,
|
|
98
|
-
// Combinators
|
|
99
|
-
combineProcessors,
|
|
100
|
-
combineInitialStates,
|
|
101
|
-
chainProcessors,
|
|
102
|
-
filterProcessor,
|
|
103
|
-
mapOutput,
|
|
104
103
|
withLogging,
|
|
105
|
-
identityProcessor,
|
|
106
104
|
} from "./engine/mealy";
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
* @packageDocumentation
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type { UserMessage } from "./message";
|
|
17
16
|
import type {
|
|
18
|
-
AgentState,
|
|
19
17
|
AgentOutput,
|
|
18
|
+
AgentOutputCallback,
|
|
19
|
+
AgentState,
|
|
20
20
|
StreamEvent,
|
|
21
21
|
Unsubscribe,
|
|
22
|
-
AgentOutputCallback,
|
|
23
22
|
} from "./event";
|
|
23
|
+
import type { UserMessage } from "./message";
|
|
24
24
|
|
|
25
25
|
// =============================================================================
|
|
26
26
|
// Message Queue
|
package/src/agent/types/event.ts
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
|
-
UserMessage,
|
|
17
16
|
AssistantMessage,
|
|
18
|
-
ToolResultMessage,
|
|
19
17
|
ErrorMessage,
|
|
20
18
|
TokenUsage,
|
|
19
|
+
ToolResultMessage,
|
|
20
|
+
UserMessage,
|
|
21
21
|
} from "./message";
|
|
22
22
|
|
|
23
23
|
// =============================================================================
|
|
@@ -234,13 +234,9 @@ export interface ConversationStartData {
|
|
|
234
234
|
messageId: string;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
export
|
|
238
|
-
// Empty
|
|
239
|
-
}
|
|
237
|
+
export type ConversationThinkingData = {};
|
|
240
238
|
|
|
241
|
-
export
|
|
242
|
-
// Empty
|
|
243
|
-
}
|
|
239
|
+
export type ConversationRespondingData = {};
|
|
244
240
|
|
|
245
241
|
export interface ConversationEndData {
|
|
246
242
|
reason: "completed" | "interrupted" | "error";
|