@mozaik-ai/core 4.2.0-beta.16 → 4.2.0-beta.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/dist/index.d.mts +31 -29
- package/dist/index.d.ts +31 -29
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
type SituationContext$1<TEvent extends SpaceEvent = SpaceEvent> = {
|
|
1
|
+
type SituationContext$1<TParticipant, TEvent extends SpaceEvent = SpaceEvent> = {
|
|
2
2
|
readonly event: TEvent;
|
|
3
|
-
readonly participant: Participant
|
|
3
|
+
readonly participant: Participant<TParticipant>;
|
|
4
4
|
};
|
|
5
|
-
declare abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {
|
|
6
|
-
abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
|
|
7
|
-
and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
|
|
8
|
-
or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
|
|
9
|
-
not(): SituationSpecification<TEvent>;
|
|
5
|
+
declare abstract class SituationSpecification<TParticipant, TEvent extends SpaceEvent = SpaceEvent> {
|
|
6
|
+
abstract isSatisfiedBy(situationContext: SituationContext$1<TParticipant, TEvent>): boolean;
|
|
7
|
+
and(other: SituationSpecification<TParticipant, TEvent>): SituationSpecification<TParticipant, TEvent>;
|
|
8
|
+
or(other: SituationSpecification<TParticipant, TEvent>): SituationSpecification<TParticipant, TEvent>;
|
|
9
|
+
not(): SituationSpecification<TParticipant, TEvent>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface SituationHandler {
|
|
13
|
-
readonly specification: SituationSpecification
|
|
14
|
-
readonly processor: SituationProcessor
|
|
12
|
+
interface SituationHandler<TParticipant> {
|
|
13
|
+
readonly specification: SituationSpecification<TParticipant>;
|
|
14
|
+
readonly processor: SituationProcessor<TParticipant>;
|
|
15
15
|
}
|
|
16
|
-
type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {
|
|
16
|
+
type SituationContext<TParticipant, TEvent extends SpaceEvent = SpaceEvent> = {
|
|
17
17
|
readonly event: TEvent;
|
|
18
|
-
readonly participant: Participant
|
|
18
|
+
readonly participant: Participant<TParticipant>;
|
|
19
19
|
};
|
|
20
|
-
interface SituationProcessor {
|
|
21
|
-
apply(context: SituationContext): void | Promise<void>;
|
|
20
|
+
interface SituationProcessor<TParticipant> {
|
|
21
|
+
apply(context: SituationContext<TParticipant>): void | Promise<void>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
type ParticipantRole = "agent" | "external";
|
|
@@ -28,15 +28,17 @@ type ParticipantManifest = {
|
|
|
28
28
|
readonly role: ParticipantRole;
|
|
29
29
|
readonly capabilities?: readonly string[];
|
|
30
30
|
};
|
|
31
|
-
declare class Participant {
|
|
31
|
+
declare class Participant<TParticipant> {
|
|
32
32
|
private manifest;
|
|
33
33
|
private handlers;
|
|
34
|
-
|
|
34
|
+
private _self;
|
|
35
|
+
constructor(manifest: ParticipantManifest, handlers: SituationHandler<TParticipant>[], self: TParticipant);
|
|
36
|
+
get self(): TParticipant;
|
|
35
37
|
getManifest(): ParticipantManifest;
|
|
36
38
|
setManifest(manifest: ParticipantManifest): void;
|
|
37
39
|
getId(): string;
|
|
38
|
-
getHandlers(): SituationHandler[];
|
|
39
|
-
setHandlers(handlers: SituationHandler[]): void;
|
|
40
|
+
getHandlers(): SituationHandler<TParticipant>[];
|
|
41
|
+
setHandlers(handlers: SituationHandler<TParticipant>[]): void;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
declare class SpaceEvent<TType extends string = string, TPayload = unknown> {
|
|
@@ -64,23 +66,23 @@ type Tool = FunctionTool;
|
|
|
64
66
|
type SpaceRecord = {
|
|
65
67
|
id: string;
|
|
66
68
|
name: string;
|
|
67
|
-
participants: Participant[];
|
|
69
|
+
participants: Participant<unknown>[];
|
|
68
70
|
};
|
|
69
71
|
declare class Space {
|
|
70
72
|
private readonly id;
|
|
71
73
|
private name;
|
|
72
74
|
private participants;
|
|
73
75
|
private events;
|
|
74
|
-
constructor(id: string, name: string, participants: Participant[], events?: SpaceEvent[]);
|
|
76
|
+
constructor(id: string, name: string, participants: Participant<any>[], events?: SpaceEvent[]);
|
|
75
77
|
getId(): string;
|
|
76
78
|
getName(): string;
|
|
77
|
-
addParticipant(participant: Participant): SpaceEvent | undefined;
|
|
78
|
-
getParticipant(id: string): Participant | undefined;
|
|
79
|
-
removeParticipant(participant: Participant): SpaceEvent;
|
|
80
|
-
getParticipants(): Participant[];
|
|
81
|
-
sendMessage(participant: Participant
|
|
79
|
+
addParticipant(participant: Participant<unknown>): SpaceEvent | undefined;
|
|
80
|
+
getParticipant(id: string): Participant<unknown> | undefined;
|
|
81
|
+
removeParticipant(participant: Participant<unknown>): SpaceEvent;
|
|
82
|
+
getParticipants(): Participant<unknown>[];
|
|
83
|
+
sendMessage(participant: Participant<unknown>, message: string, occurredAt: Date): SpaceEvent;
|
|
82
84
|
getEvents(): SpaceEvent[];
|
|
83
|
-
static create(name: string, participants?: Participant[]): Space;
|
|
85
|
+
static create(name: string, participants?: Participant<unknown>[]): Space;
|
|
84
86
|
get record(): SpaceRecord;
|
|
85
87
|
static rehydrate({ id, name, participants }: SpaceRecord): Space;
|
|
86
88
|
}
|
|
@@ -95,9 +97,9 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
|
|
|
95
97
|
state: TSharedState;
|
|
96
98
|
}) => RuntimeService<TSharedState>;
|
|
97
99
|
resolveRuntime: () => RuntimeService<TSharedState>;
|
|
98
|
-
createParticipant: (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => Promise<Participant
|
|
100
|
+
createParticipant: <TParticipant>(name: string, capabilities: readonly string[], handlers: SituationHandler<TParticipant>[], self: TParticipant) => Promise<Participant<unknown>>;
|
|
99
101
|
createSpace: (name: string) => Promise<Space>;
|
|
100
|
-
join: (spaceId: string, participant: Participant) => Promise<void>;
|
|
102
|
+
join: (spaceId: string, participant: Participant<unknown>) => Promise<void>;
|
|
101
103
|
leave: (spaceId: string, participantId: string) => Promise<void>;
|
|
102
104
|
sendMessage: (spaceId: string, participantId: string, message: string) => Promise<void>;
|
|
103
105
|
sendMessageTool: FunctionTool;
|
|
@@ -492,4 +494,4 @@ declare function defineAgentModule(config: AgentModuleConfig): {
|
|
|
492
494
|
runLoop: (loopId: string) => Promise<Loop>;
|
|
493
495
|
};
|
|
494
496
|
|
|
495
|
-
export { Agent, type AgentModuleConfig, type AgentRepository, AwaitingInference, AwaitingRequest, AwaitingToolOutput, CompleteAction, type GenerativeModel, InferenceAction, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, ModelAnswered, type ModelMessageItem, Participant, RequestPreparationAction, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, ToolUseAction, type ToolUseRequest, type ToolUseResult, type ToolUseRunner, WaitAction, defaultRules, defineAgentModule, defineRuntime };
|
|
497
|
+
export { Agent, type AgentModuleConfig, type AgentRepository, AwaitingInference, AwaitingRequest, AwaitingToolOutput, CompleteAction, type GenerativeModel, InferenceAction, type InferenceRequest, type InferenceResult, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, ModelAnswered, type ModelMessageItem, Participant, RequestPreparationAction, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, ToolUseAction, type ToolUseRequest, type ToolUseResult, type ToolUseRunner, WaitAction, defaultRules, defineAgentModule, defineRuntime };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
type SituationContext$1<TEvent extends SpaceEvent = SpaceEvent> = {
|
|
1
|
+
type SituationContext$1<TParticipant, TEvent extends SpaceEvent = SpaceEvent> = {
|
|
2
2
|
readonly event: TEvent;
|
|
3
|
-
readonly participant: Participant
|
|
3
|
+
readonly participant: Participant<TParticipant>;
|
|
4
4
|
};
|
|
5
|
-
declare abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {
|
|
6
|
-
abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
|
|
7
|
-
and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
|
|
8
|
-
or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
|
|
9
|
-
not(): SituationSpecification<TEvent>;
|
|
5
|
+
declare abstract class SituationSpecification<TParticipant, TEvent extends SpaceEvent = SpaceEvent> {
|
|
6
|
+
abstract isSatisfiedBy(situationContext: SituationContext$1<TParticipant, TEvent>): boolean;
|
|
7
|
+
and(other: SituationSpecification<TParticipant, TEvent>): SituationSpecification<TParticipant, TEvent>;
|
|
8
|
+
or(other: SituationSpecification<TParticipant, TEvent>): SituationSpecification<TParticipant, TEvent>;
|
|
9
|
+
not(): SituationSpecification<TParticipant, TEvent>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface SituationHandler {
|
|
13
|
-
readonly specification: SituationSpecification
|
|
14
|
-
readonly processor: SituationProcessor
|
|
12
|
+
interface SituationHandler<TParticipant> {
|
|
13
|
+
readonly specification: SituationSpecification<TParticipant>;
|
|
14
|
+
readonly processor: SituationProcessor<TParticipant>;
|
|
15
15
|
}
|
|
16
|
-
type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {
|
|
16
|
+
type SituationContext<TParticipant, TEvent extends SpaceEvent = SpaceEvent> = {
|
|
17
17
|
readonly event: TEvent;
|
|
18
|
-
readonly participant: Participant
|
|
18
|
+
readonly participant: Participant<TParticipant>;
|
|
19
19
|
};
|
|
20
|
-
interface SituationProcessor {
|
|
21
|
-
apply(context: SituationContext): void | Promise<void>;
|
|
20
|
+
interface SituationProcessor<TParticipant> {
|
|
21
|
+
apply(context: SituationContext<TParticipant>): void | Promise<void>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
type ParticipantRole = "agent" | "external";
|
|
@@ -28,15 +28,17 @@ type ParticipantManifest = {
|
|
|
28
28
|
readonly role: ParticipantRole;
|
|
29
29
|
readonly capabilities?: readonly string[];
|
|
30
30
|
};
|
|
31
|
-
declare class Participant {
|
|
31
|
+
declare class Participant<TParticipant> {
|
|
32
32
|
private manifest;
|
|
33
33
|
private handlers;
|
|
34
|
-
|
|
34
|
+
private _self;
|
|
35
|
+
constructor(manifest: ParticipantManifest, handlers: SituationHandler<TParticipant>[], self: TParticipant);
|
|
36
|
+
get self(): TParticipant;
|
|
35
37
|
getManifest(): ParticipantManifest;
|
|
36
38
|
setManifest(manifest: ParticipantManifest): void;
|
|
37
39
|
getId(): string;
|
|
38
|
-
getHandlers(): SituationHandler[];
|
|
39
|
-
setHandlers(handlers: SituationHandler[]): void;
|
|
40
|
+
getHandlers(): SituationHandler<TParticipant>[];
|
|
41
|
+
setHandlers(handlers: SituationHandler<TParticipant>[]): void;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
declare class SpaceEvent<TType extends string = string, TPayload = unknown> {
|
|
@@ -64,23 +66,23 @@ type Tool = FunctionTool;
|
|
|
64
66
|
type SpaceRecord = {
|
|
65
67
|
id: string;
|
|
66
68
|
name: string;
|
|
67
|
-
participants: Participant[];
|
|
69
|
+
participants: Participant<unknown>[];
|
|
68
70
|
};
|
|
69
71
|
declare class Space {
|
|
70
72
|
private readonly id;
|
|
71
73
|
private name;
|
|
72
74
|
private participants;
|
|
73
75
|
private events;
|
|
74
|
-
constructor(id: string, name: string, participants: Participant[], events?: SpaceEvent[]);
|
|
76
|
+
constructor(id: string, name: string, participants: Participant<any>[], events?: SpaceEvent[]);
|
|
75
77
|
getId(): string;
|
|
76
78
|
getName(): string;
|
|
77
|
-
addParticipant(participant: Participant): SpaceEvent | undefined;
|
|
78
|
-
getParticipant(id: string): Participant | undefined;
|
|
79
|
-
removeParticipant(participant: Participant): SpaceEvent;
|
|
80
|
-
getParticipants(): Participant[];
|
|
81
|
-
sendMessage(participant: Participant
|
|
79
|
+
addParticipant(participant: Participant<unknown>): SpaceEvent | undefined;
|
|
80
|
+
getParticipant(id: string): Participant<unknown> | undefined;
|
|
81
|
+
removeParticipant(participant: Participant<unknown>): SpaceEvent;
|
|
82
|
+
getParticipants(): Participant<unknown>[];
|
|
83
|
+
sendMessage(participant: Participant<unknown>, message: string, occurredAt: Date): SpaceEvent;
|
|
82
84
|
getEvents(): SpaceEvent[];
|
|
83
|
-
static create(name: string, participants?: Participant[]): Space;
|
|
85
|
+
static create(name: string, participants?: Participant<unknown>[]): Space;
|
|
84
86
|
get record(): SpaceRecord;
|
|
85
87
|
static rehydrate({ id, name, participants }: SpaceRecord): Space;
|
|
86
88
|
}
|
|
@@ -95,9 +97,9 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
|
|
|
95
97
|
state: TSharedState;
|
|
96
98
|
}) => RuntimeService<TSharedState>;
|
|
97
99
|
resolveRuntime: () => RuntimeService<TSharedState>;
|
|
98
|
-
createParticipant: (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => Promise<Participant
|
|
100
|
+
createParticipant: <TParticipant>(name: string, capabilities: readonly string[], handlers: SituationHandler<TParticipant>[], self: TParticipant) => Promise<Participant<unknown>>;
|
|
99
101
|
createSpace: (name: string) => Promise<Space>;
|
|
100
|
-
join: (spaceId: string, participant: Participant) => Promise<void>;
|
|
102
|
+
join: (spaceId: string, participant: Participant<unknown>) => Promise<void>;
|
|
101
103
|
leave: (spaceId: string, participantId: string) => Promise<void>;
|
|
102
104
|
sendMessage: (spaceId: string, participantId: string, message: string) => Promise<void>;
|
|
103
105
|
sendMessageTool: FunctionTool;
|
|
@@ -492,4 +494,4 @@ declare function defineAgentModule(config: AgentModuleConfig): {
|
|
|
492
494
|
runLoop: (loopId: string) => Promise<Loop>;
|
|
493
495
|
};
|
|
494
496
|
|
|
495
|
-
export { Agent, type AgentModuleConfig, type AgentRepository, AwaitingInference, AwaitingRequest, AwaitingToolOutput, CompleteAction, type GenerativeModel, InferenceAction, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, ModelAnswered, type ModelMessageItem, Participant, RequestPreparationAction, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, ToolUseAction, type ToolUseRequest, type ToolUseResult, type ToolUseRunner, WaitAction, defaultRules, defineAgentModule, defineRuntime };
|
|
497
|
+
export { Agent, type AgentModuleConfig, type AgentRepository, AwaitingInference, AwaitingRequest, AwaitingToolOutput, CompleteAction, type GenerativeModel, InferenceAction, type InferenceRequest, type InferenceResult, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, ModelAnswered, type ModelMessageItem, Participant, RequestPreparationAction, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, ToolUseAction, type ToolUseRequest, type ToolUseResult, type ToolUseRunner, WaitAction, defaultRules, defineAgentModule, defineRuntime };
|
package/dist/index.js
CHANGED
|
@@ -79,9 +79,13 @@ var MessageSentEvent = class extends SpaceEvent {
|
|
|
79
79
|
|
|
80
80
|
// src/domain/space/participant.ts
|
|
81
81
|
var Participant = class {
|
|
82
|
-
constructor(manifest, handlers) {
|
|
82
|
+
constructor(manifest, handlers, self) {
|
|
83
83
|
this.manifest = manifest;
|
|
84
84
|
this.handlers = handlers;
|
|
85
|
+
this._self = self;
|
|
86
|
+
}
|
|
87
|
+
get self() {
|
|
88
|
+
return this._self;
|
|
85
89
|
}
|
|
86
90
|
getManifest() {
|
|
87
91
|
return this.manifest;
|
|
@@ -116,14 +120,14 @@ var UuidGenerator = class {
|
|
|
116
120
|
|
|
117
121
|
// src/application/use-cases/create-participant.ts
|
|
118
122
|
var CreateParticipantUseCase = class {
|
|
119
|
-
async execute(name, capabilities, handlers) {
|
|
123
|
+
async execute(name, capabilities, handlers, self) {
|
|
120
124
|
const manifest = {
|
|
121
125
|
id: UuidGenerator.create(),
|
|
122
126
|
name,
|
|
123
127
|
capabilities,
|
|
124
128
|
role: "external"
|
|
125
129
|
};
|
|
126
|
-
const participant = new Participant(manifest, handlers);
|
|
130
|
+
const participant = new Participant(manifest, handlers, self);
|
|
127
131
|
return participant;
|
|
128
132
|
}
|
|
129
133
|
};
|
|
@@ -320,8 +324,8 @@ function defineRuntime() {
|
|
|
320
324
|
return runtime;
|
|
321
325
|
}
|
|
322
326
|
const createParticipantUseCase = new CreateParticipantUseCase();
|
|
323
|
-
const createParticipant = async (name, capabilities, handlers) => {
|
|
324
|
-
return await createParticipantUseCase.execute(name, capabilities, handlers);
|
|
327
|
+
const createParticipant = async (name, capabilities, handlers, self) => {
|
|
328
|
+
return await createParticipantUseCase.execute(name, capabilities, handlers, self);
|
|
325
329
|
};
|
|
326
330
|
const spaceRepository = new InMemorySpaceRepository();
|
|
327
331
|
const eventPublisher = new EventPublisher();
|