@mozaik-ai/core 4.2.0-beta.0 → 4.2.0-beta.2

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 CHANGED
@@ -60,6 +60,30 @@ interface FunctionTool {
60
60
  invoke: (args: any) => Promise<any> | any;
61
61
  }
62
62
 
63
+ type SpaceRecord = {
64
+ id: string;
65
+ name: string;
66
+ participants: Participant[];
67
+ };
68
+ declare class Space {
69
+ private readonly id;
70
+ private name;
71
+ private participants;
72
+ private events;
73
+ constructor(id: string, name: string, participants: Participant[], events?: SpaceEvent[]);
74
+ getId(): string;
75
+ getName(): string;
76
+ addParticipant(participant: Participant): SpaceEvent | undefined;
77
+ getParticipant(id: string): Participant | undefined;
78
+ removeParticipant(participant: Participant): SpaceEvent;
79
+ getParticipants(): Participant[];
80
+ sendMessage(participant: Participant, message: string, occurredAt: Date): SpaceEvent;
81
+ getEvents(): SpaceEvent[];
82
+ static create(name: string, participants?: Participant[]): Space;
83
+ get record(): SpaceRecord;
84
+ static rehydrate({ id, name, participants }: SpaceRecord): Space;
85
+ }
86
+
63
87
  declare class RuntimeService<TSharedState extends SharedState> {
64
88
  readonly state: TSharedState;
65
89
  constructor(state: TSharedState);
@@ -71,6 +95,7 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
71
95
  }) => RuntimeService<TSharedState>;
72
96
  resolveRuntime: () => RuntimeService<TSharedState>;
73
97
  createParticipant: (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => Promise<Participant>;
98
+ createSpace: (name: string) => Promise<Space>;
74
99
  join: (spaceId: string, participantId: string) => Promise<void>;
75
100
  leave: (spaceId: string, participantId: string) => Promise<void>;
76
101
  sendMessage: (spaceId: string, participantId: string, message: string) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -60,6 +60,30 @@ interface FunctionTool {
60
60
  invoke: (args: any) => Promise<any> | any;
61
61
  }
62
62
 
63
+ type SpaceRecord = {
64
+ id: string;
65
+ name: string;
66
+ participants: Participant[];
67
+ };
68
+ declare class Space {
69
+ private readonly id;
70
+ private name;
71
+ private participants;
72
+ private events;
73
+ constructor(id: string, name: string, participants: Participant[], events?: SpaceEvent[]);
74
+ getId(): string;
75
+ getName(): string;
76
+ addParticipant(participant: Participant): SpaceEvent | undefined;
77
+ getParticipant(id: string): Participant | undefined;
78
+ removeParticipant(participant: Participant): SpaceEvent;
79
+ getParticipants(): Participant[];
80
+ sendMessage(participant: Participant, message: string, occurredAt: Date): SpaceEvent;
81
+ getEvents(): SpaceEvent[];
82
+ static create(name: string, participants?: Participant[]): Space;
83
+ get record(): SpaceRecord;
84
+ static rehydrate({ id, name, participants }: SpaceRecord): Space;
85
+ }
86
+
63
87
  declare class RuntimeService<TSharedState extends SharedState> {
64
88
  readonly state: TSharedState;
65
89
  constructor(state: TSharedState);
@@ -71,6 +95,7 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
71
95
  }) => RuntimeService<TSharedState>;
72
96
  resolveRuntime: () => RuntimeService<TSharedState>;
73
97
  createParticipant: (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => Promise<Participant>;
98
+ createSpace: (name: string) => Promise<Space>;
74
99
  join: (spaceId: string, participantId: string) => Promise<void>;
75
100
  leave: (spaceId: string, participantId: string) => Promise<void>;
76
101
  sendMessage: (spaceId: string, participantId: string, message: string) => Promise<void>;
package/dist/index.js CHANGED
@@ -39,6 +39,21 @@ var SpaceEvent = class _SpaceEvent {
39
39
  return new _SpaceEvent(type, producerId, occurredAt, payload);
40
40
  }
41
41
  };
42
+ var ParticipantJoinedEvent = class extends SpaceEvent {
43
+ static init(manifest, occurredAt) {
44
+ return SpaceEvent.create("participant.joined", manifest.id, occurredAt, manifest);
45
+ }
46
+ };
47
+ var ParticipantLeftEvent = class extends SpaceEvent {
48
+ static init(manifest, occurredAt) {
49
+ return SpaceEvent.create("participant.left", manifest.id, occurredAt, manifest);
50
+ }
51
+ };
52
+ var MessageSentEvent = class extends SpaceEvent {
53
+ static init(producerId, message, occurredAt) {
54
+ return SpaceEvent.create("message.sent", producerId, occurredAt, { message });
55
+ }
56
+ };
42
57
 
43
58
  // src/domain/space/participant.ts
44
59
  var Participant = class {
@@ -97,7 +112,7 @@ var ParticipantJoinedUseCase = class {
97
112
  this.spaceRepository = spaceRepository;
98
113
  this.eventPublisher = eventPublisher;
99
114
  }
100
- async execute(spaceId, participantId, occurredAt) {
115
+ async execute(spaceId, participantId) {
101
116
  const space = await this.spaceRepository.findById(spaceId);
102
117
  if (!space) {
103
118
  throw new Error("Space not found");
@@ -106,7 +121,7 @@ var ParticipantJoinedUseCase = class {
106
121
  if (!participant) {
107
122
  throw new Error("Participant not found");
108
123
  }
109
- const event = space.addParticipant(participant, occurredAt);
124
+ const event = space.addParticipant(participant);
110
125
  if (event) {
111
126
  this.eventPublisher.publish(event, space.getParticipants());
112
127
  }
@@ -125,9 +140,6 @@ var InMemorySpaceRepository = class {
125
140
  async findById(id) {
126
141
  return this.spaces.find((space) => space.getId() === id);
127
142
  }
128
- async findAllByOwnerId(ownerId) {
129
- return this.spaces.filter((space) => space.getOwnerId() === ownerId);
130
- }
131
143
  async delete(id) {
132
144
  this.spaces = this.spaces.filter((space) => space.getId() !== id);
133
145
  }
@@ -152,7 +164,7 @@ var ParticipantLefUseCase = class {
152
164
  this.spaceRepository = spaceRepository;
153
165
  this.eventPublisher = eventPublisher;
154
166
  }
155
- async execute(spaceId, participantId, occurredAt) {
167
+ async execute(spaceId, participantId) {
156
168
  const space = await this.spaceRepository.findById(spaceId);
157
169
  if (!space) {
158
170
  throw new Error("Space not found");
@@ -161,7 +173,7 @@ var ParticipantLefUseCase = class {
161
173
  if (!participant) {
162
174
  throw new Error("Participant not found");
163
175
  }
164
- const event = space.removeParticipant(participant, occurredAt);
176
+ const event = space.removeParticipant(participant);
165
177
  if (event) {
166
178
  this.eventPublisher.publish(event, space.getParticipants());
167
179
  }
@@ -192,6 +204,86 @@ var SendMessageUseCase = class {
192
204
  }
193
205
  };
194
206
 
207
+ // src/util/system-clock.ts
208
+ var SystemClock = class {
209
+ static now() {
210
+ return /* @__PURE__ */ new Date();
211
+ }
212
+ };
213
+
214
+ // src/domain/space/space.ts
215
+ var Space = class _Space {
216
+ constructor(id, name, participants, events = []) {
217
+ this.id = id;
218
+ this.name = name;
219
+ this.participants = participants;
220
+ this.events = events;
221
+ }
222
+ getId() {
223
+ return this.id;
224
+ }
225
+ getName() {
226
+ return this.name;
227
+ }
228
+ addParticipant(participant) {
229
+ const alreadyExists = this.participants.find((p) => p.getId() === participant.getId());
230
+ if (alreadyExists) return;
231
+ this.participants.push(participant);
232
+ const occurredAt = SystemClock.now();
233
+ return ParticipantJoinedEvent.init(participant.getManifest(), occurredAt);
234
+ }
235
+ getParticipant(id) {
236
+ const participant = this.getParticipants().find((p) => p.getId() === id);
237
+ if (!participant) {
238
+ throw new Error(`Participant ${id} not found`);
239
+ }
240
+ return participant;
241
+ }
242
+ removeParticipant(participant) {
243
+ this.participants = this.participants.filter((p) => p.getId() !== participant.getId());
244
+ const occurredAt = SystemClock.now();
245
+ return ParticipantLeftEvent.init(participant.getManifest(), occurredAt);
246
+ }
247
+ getParticipants() {
248
+ return [...this.participants];
249
+ }
250
+ sendMessage(participant, message, occurredAt) {
251
+ const event = MessageSentEvent.init(participant.getId(), message, occurredAt);
252
+ this.events.push(event);
253
+ return event;
254
+ }
255
+ getEvents() {
256
+ return [...this.events];
257
+ }
258
+ static create(name, participants = []) {
259
+ const id = UuidGenerator.create();
260
+ return new _Space(id, name, participants);
261
+ }
262
+ get record() {
263
+ return {
264
+ id: this.id,
265
+ name: this.name,
266
+ participants: this.participants
267
+ };
268
+ }
269
+ static rehydrate({ id, name, participants }) {
270
+ return new _Space(id, name, participants);
271
+ }
272
+ };
273
+
274
+ // src/application/use-cases/create-space.ts
275
+ var CreateSpaceUseCase = class {
276
+ constructor(spaceRepository) {
277
+ this.spaceRepository = spaceRepository;
278
+ }
279
+ async execute(name) {
280
+ const participants = [];
281
+ const space = Space.create(name, participants);
282
+ await this.spaceRepository.save(space);
283
+ return space;
284
+ }
285
+ };
286
+
195
287
  // src/define-runtime.ts
196
288
  function defineRuntime() {
197
289
  let runtime = null;
@@ -214,13 +306,17 @@ function defineRuntime() {
214
306
  };
215
307
  const spaceRepository = new InMemorySpaceRepository();
216
308
  const eventPublisher = new EventPublisher();
309
+ const createSpaceUseCase = new CreateSpaceUseCase(spaceRepository);
310
+ const createSpace = async (name) => {
311
+ return await createSpaceUseCase.execute(name);
312
+ };
217
313
  const participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher);
218
314
  const join = async (spaceId, participantId) => {
219
- return await participantJoinedUseCase.execute(spaceId, participantId, /* @__PURE__ */ new Date());
315
+ return await participantJoinedUseCase.execute(spaceId, participantId);
220
316
  };
221
317
  const participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher);
222
318
  const leave = async (spaceId, participantId) => {
223
- return await participantLeftUseCase.execute(spaceId, participantId, /* @__PURE__ */ new Date());
319
+ return await participantLeftUseCase.execute(spaceId, participantId);
224
320
  };
225
321
  const sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher);
226
322
  const sendMessage = async (spaceId, participantId, message) => {
@@ -249,6 +345,7 @@ function defineRuntime() {
249
345
  initializeRuntime,
250
346
  resolveRuntime,
251
347
  createParticipant,
348
+ createSpace,
252
349
  join,
253
350
  leave,
254
351
  sendMessage,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/domain/space/event.ts","../src/domain/space/participant.ts","../src/domain/space/runtime.ts","../src/util/uuid-generator.ts","../src/application/use-cases/create-participant.ts","../src/application/use-cases/participant-joined.ts","../src/infrastructure/repositories/in-memory-space-repository.ts","../src/domain/space/event-publisher.ts","../src/application/use-cases/participant-left.ts","../src/application/use-cases/send-message.ts","../src/define-runtime.ts","../src/domain/space/situation-specification.ts"],"sourcesContent":["import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { defineRuntime } from \"src/define-runtime\"\nimport { SituationContext, SituationHandler, SituationProcessor } from \"@domain/space/situation-handler\"\nimport { SituationSpecification } from \"@domain/space/situation-specification\"\n\nexport {\n\tdefineRuntime,\n\tSharedState,\n\tSpaceEvent,\n\tParticipant,\n\tSituationHandler,\n\tSituationProcessor,\n\tSituationSpecification,\n\tSituationContext,\n}\n","import { ParticipantManifest } from \"@domain/space/participant\"\n\nexport class SpaceEvent<TType extends string = string, TPayload = unknown> {\n\treadonly type: TType\n\treadonly producerId: string\n\treadonly occurredAt: Date\n\treadonly payload: TPayload\n\n\tconstructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload) {\n\t\tthis.type = type\n\t\tthis.producerId = producerId\n\t\tthis.occurredAt = occurredAt\n\t\tthis.payload = payload\n\t}\n\n\tstatic create<TType extends string = string, TPayload = unknown>(\n\t\ttype: TType,\n\t\tproducerId: string,\n\t\toccurredAt: Date,\n\t\tpayload: TPayload,\n\t): SpaceEvent<TType, TPayload> {\n\t\treturn new SpaceEvent(type, producerId, occurredAt, payload)\n\t}\n}\n\nexport class ParticipantJoinedEvent extends SpaceEvent<\"participant.joined\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantJoinedEvent {\n\t\treturn SpaceEvent.create(\"participant.joined\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class ParticipantLeftEvent extends SpaceEvent<\"participant.left\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantLeftEvent {\n\t\treturn SpaceEvent.create(\"participant.left\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class MessageSentEvent extends SpaceEvent<\"message.sent\", { message: string }> {\n\tstatic init(producerId: string, message: string, occurredAt: Date): MessageSentEvent {\n\t\treturn SpaceEvent.create(\"message.sent\", producerId, occurredAt, { message })\n\t}\n}\n\nexport class ModelAnswerEvent extends SpaceEvent<\"model.answer\", { answer: string }> {\n\tstatic init(producerId: string, answer: string, occurredAt: Date): ModelAnswerEvent {\n\t\treturn ModelAnswerEvent.create(\"model.answer\", producerId, occurredAt, { answer })\n\t}\n}\n","import { SituationHandler } from \"@domain/space/situation-handler\"\n\nexport type ParticipantRole = \"agent\" | \"external\"\n\nexport type ParticipantManifest = {\n\treadonly id: string\n\treadonly name: string\n\treadonly role: ParticipantRole\n\treadonly capabilities?: readonly string[]\n}\n\nexport class Participant {\n\tprivate manifest: ParticipantManifest\n\tprivate handlers: SituationHandler[]\n\n\tconstructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tthis.manifest = manifest\n\t\tthis.handlers = handlers\n\t}\n\n\tgetManifest(): ParticipantManifest {\n\t\treturn this.manifest\n\t}\n\n\tsetManifest(manifest: ParticipantManifest): void {\n\t\tthis.manifest = manifest\n\t}\n\n\tgetId(): string {\n\t\treturn this.manifest.id\n\t}\n\n\tgetHandlers(): SituationHandler[] {\n\t\treturn this.handlers\n\t}\n\n\tsetHandlers(handlers: SituationHandler[]): void {\n\t\tthis.handlers = handlers\n\t}\n}\n","import { SharedState } from \"@domain/space/shared-state\"\n\nexport class RuntimeService<TSharedState extends SharedState> {\n\tconstructor(public readonly state: TSharedState) {}\n}\n","export class UuidGenerator {\n\tstatic create(): string {\n\t\treturn crypto.randomUUID()\n\t}\n}\n","import { Participant, ParticipantManifest } from \"@domain/space/participant\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport class CreateParticipantUseCase {\n\tasync execute(name: string, capabilities: readonly string[], handlers: SituationHandler[]): Promise<Participant> {\n\t\tconst manifest: ParticipantManifest = {\n\t\t\tid: UuidGenerator.create(),\n\t\t\tname,\n\t\t\tcapabilities,\n\t\t\trole: \"external\",\n\t\t}\n\t\tconst participant = new Participant(manifest, handlers)\n\t\treturn participant\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantJoinedUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string, occurredAt: Date): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.addParticipant(participant, occurredAt)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\n\nexport class InMemorySpaceRepository implements SpaceRepository {\n\tprivate spaces: Space[] = []\n\n\tasync save(space: Space): Promise<void> {\n\t\tthis.spaces.push(space)\n\t}\n\n\tasync findById(id: string): Promise<Space | undefined> {\n\t\treturn this.spaces.find((space) => space.getId() === id)\n\t}\n\n\tasync findAllByOwnerId(ownerId: string): Promise<Space[]> {\n\t\treturn this.spaces.filter((space) => space.getOwnerId() === ownerId)\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\tthis.spaces = this.spaces.filter((space) => space.getId() !== id)\n\t}\n}\n","import { SpaceEvent } from \"./event\"\nimport { Participant } from \"./participant\"\n\nexport class EventPublisher {\n\tpublish(event: SpaceEvent, participants: Participant[]): void {\n\t\tfor (const participant of participants) {\n\t\t\tparticipant.getHandlers().forEach((handler) => {\n\t\t\t\tif (handler.specification.isSatisfiedBy({ event, participant })) {\n\t\t\t\t\thandler.processor.apply({ event, participant })\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantLefUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string, occurredAt: Date): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.removeParticipant(participant, occurredAt)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class SendMessageUseCase {\n\tconstructor(\n\t\tprivate readonly spaceRepository: SpaceRepository,\n\t\tprivate readonly eventPublisher: EventPublisher,\n\t) {}\n\n\tasync execute(spaceId: string, participantId: string, message: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.sendMessage(participant, message, new Date())\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { RuntimeService } from \"@domain/space/runtime\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { CreateParticipantUseCase } from \"@application/use-cases/create-participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { ParticipantJoinedUseCase } from \"@application/use-cases/participant-joined\"\nimport { InMemorySpaceRepository } from \"@infrastructure/repositories/in-memory-space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\nimport { ParticipantLefUseCase } from \"@application/use-cases/participant-left\"\nimport { SendMessageUseCase } from \"@application/use-cases/send-message\"\nimport { Tool } from \"@domain/inference/tool\"\n\nexport function defineRuntime<TSharedState extends SharedState>() {\n\tlet runtime: RuntimeService<TSharedState> | null = null\n\n\tfunction initializeRuntime(config: { state: TSharedState }): RuntimeService<TSharedState> {\n\t\tif (runtime) {\n\t\t\tthrow new Error(\"Runtime already initialized\")\n\t\t}\n\n\t\truntime = new RuntimeService(config.state)\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveRuntime(): RuntimeService<TSharedState> {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\treturn runtime\n\t}\n\n\tconst createParticipantUseCase = new CreateParticipantUseCase()\n\n\tconst createParticipant = async (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => {\n\t\treturn await createParticipantUseCase.execute(name, capabilities, handlers)\n\t}\n\n\tconst spaceRepository = new InMemorySpaceRepository()\n\tconst eventPublisher = new EventPublisher()\n\tconst participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher)\n\tconst join = async (spaceId: string, participantId: string) => {\n\t\treturn await participantJoinedUseCase.execute(spaceId, participantId, new Date())\n\t}\n\n\tconst participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher)\n\tconst leave = async (spaceId: string, participantId: string) => {\n\t\treturn await participantLeftUseCase.execute(spaceId, participantId, new Date())\n\t}\n\n\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\tconst sendMessage = async (spaceId: string, participantId: string, message: string) => {\n\t\treturn await sendMessageUseCase.execute(spaceId, participantId, message)\n\t}\n\n\tconst sendMessageTool: Tool = {\n\t\ttype: \"function\",\n\t\tname: \"send_message\",\n\t\tdescription: \"Send a message to the space. The message will be sent to all participants in the space.\",\n\t\tparameters: {\n\t\t\tspaceId: { type: \"string\" },\n\t\t\tsenderId: { type: \"string\" },\n\t\t\tmessage: { type: \"string\" },\n\t\t},\n\t\tstrict: true,\n\t\tinvoke: async (args: { spaceId: string; senderId: string; message: string }) => {\n\t\t\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\t\t\tawait sendMessageUseCase.execute(args.spaceId, args.senderId, args.message)\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tmessage: \"Message sent successfully\",\n\t\t\t}\n\t\t},\n\t}\n\n\treturn {\n\t\tinitializeRuntime,\n\t\tresolveRuntime,\n\t\tcreateParticipant,\n\t\tjoin,\n\t\tleave,\n\t\tsendMessage,\n\t\tsendMessageTool,\n\t}\n}\n","import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {\n\treadonly event: TEvent\n\treadonly participant: Participant\n}\n\nexport abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {\n\tabstract isSatisfiedBy(situationContext: SituationContext<TEvent>): boolean\n\n\tand(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new AndSituationSpecification(this, other)\n\t}\n\n\tor(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new OrSituationSpecification(this, other)\n\t}\n\n\tnot(): SituationSpecification<TEvent> {\n\t\treturn new NotSituationSpecification(this)\n\t}\n}\n\nclass AndSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass OrSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass NotSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(private readonly rule: SituationSpecification<TEvent>) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn !this.rule.isSatisfiedBy(situationContext)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,aAAN,MAAM,YAA8D;AAAA,EAM1E,YAAY,MAAa,YAAoB,YAAkB,SAAmB;AACjF,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,aAAa;AAClB,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,OAAO,OACN,MACA,YACA,YACA,SAC8B;AAC9B,WAAO,IAAI,YAAW,MAAM,YAAY,YAAY,OAAO;AAAA,EAC5D;AACD;;;ACZO,IAAM,cAAN,MAAkB;AAAA,EAIxB,YAAY,UAA+B,UAA8B;AACxE,SAAK,WAAW;AAChB,SAAK,WAAW;AAAA,EACjB;AAAA,EAEA,cAAmC;AAClC,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,YAAY,UAAqC;AAChD,SAAK,WAAW;AAAA,EACjB;AAAA,EAEA,QAAgB;AACf,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA,EAEA,cAAkC;AACjC,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,YAAY,UAAoC;AAC/C,SAAK,WAAW;AAAA,EACjB;AACD;;;ACr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gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,2BAAN,cAAkE,uBAA+B;AAAA,EAChG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YAA6B,MAAsC;AAClE,UAAM;AADsB;AAAA,EAE7B;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,CAAC,KAAK,KAAK,cAAc,gBAAgB;AAAA,EACjD;AACD;","names":["sendMessageUseCase"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/domain/space/event.ts","../src/domain/space/participant.ts","../src/domain/space/runtime.ts","../src/util/uuid-generator.ts","../src/application/use-cases/create-participant.ts","../src/application/use-cases/participant-joined.ts","../src/infrastructure/repositories/in-memory-space-repository.ts","../src/domain/space/event-publisher.ts","../src/application/use-cases/participant-left.ts","../src/application/use-cases/send-message.ts","../src/util/system-clock.ts","../src/domain/space/space.ts","../src/application/use-cases/create-space.ts","../src/define-runtime.ts","../src/domain/space/situation-specification.ts"],"sourcesContent":["import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { defineRuntime } from \"src/define-runtime\"\nimport { SituationContext, SituationHandler, SituationProcessor } from \"@domain/space/situation-handler\"\nimport { SituationSpecification } from \"@domain/space/situation-specification\"\n\nexport {\n\tdefineRuntime,\n\tSharedState,\n\tSpaceEvent,\n\tParticipant,\n\tSituationHandler,\n\tSituationProcessor,\n\tSituationSpecification,\n\tSituationContext,\n}\n","import { ParticipantManifest } from \"@domain/space/participant\"\n\nexport class SpaceEvent<TType extends string = string, TPayload = unknown> {\n\treadonly type: TType\n\treadonly producerId: string\n\treadonly occurredAt: Date\n\treadonly payload: TPayload\n\n\tconstructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload) {\n\t\tthis.type = type\n\t\tthis.producerId = producerId\n\t\tthis.occurredAt = occurredAt\n\t\tthis.payload = payload\n\t}\n\n\tstatic create<TType extends string = string, TPayload = unknown>(\n\t\ttype: TType,\n\t\tproducerId: string,\n\t\toccurredAt: Date,\n\t\tpayload: TPayload,\n\t): SpaceEvent<TType, TPayload> {\n\t\treturn new SpaceEvent(type, producerId, occurredAt, payload)\n\t}\n}\n\nexport class ParticipantJoinedEvent extends SpaceEvent<\"participant.joined\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantJoinedEvent {\n\t\treturn SpaceEvent.create(\"participant.joined\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class ParticipantLeftEvent extends SpaceEvent<\"participant.left\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantLeftEvent {\n\t\treturn SpaceEvent.create(\"participant.left\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class MessageSentEvent extends SpaceEvent<\"message.sent\", { message: string }> {\n\tstatic init(producerId: string, message: string, occurredAt: Date): MessageSentEvent {\n\t\treturn SpaceEvent.create(\"message.sent\", producerId, occurredAt, { message })\n\t}\n}\n\nexport class ModelAnswerEvent extends SpaceEvent<\"model.answer\", { answer: string }> {\n\tstatic init(producerId: string, answer: string, occurredAt: Date): ModelAnswerEvent {\n\t\treturn ModelAnswerEvent.create(\"model.answer\", producerId, occurredAt, { answer })\n\t}\n}\n","import { SituationHandler } from \"@domain/space/situation-handler\"\n\nexport type ParticipantRole = \"agent\" | \"external\"\n\nexport type ParticipantManifest = {\n\treadonly id: string\n\treadonly name: string\n\treadonly role: ParticipantRole\n\treadonly capabilities?: readonly string[]\n}\n\nexport class Participant {\n\tprivate manifest: ParticipantManifest\n\tprivate handlers: SituationHandler[]\n\n\tconstructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tthis.manifest = manifest\n\t\tthis.handlers = handlers\n\t}\n\n\tgetManifest(): ParticipantManifest {\n\t\treturn this.manifest\n\t}\n\n\tsetManifest(manifest: ParticipantManifest): void {\n\t\tthis.manifest = manifest\n\t}\n\n\tgetId(): string {\n\t\treturn this.manifest.id\n\t}\n\n\tgetHandlers(): SituationHandler[] {\n\t\treturn this.handlers\n\t}\n\n\tsetHandlers(handlers: SituationHandler[]): void {\n\t\tthis.handlers = handlers\n\t}\n}\n","import { SharedState } from \"@domain/space/shared-state\"\n\nexport class RuntimeService<TSharedState extends SharedState> {\n\tconstructor(public readonly state: TSharedState) {}\n}\n","export class UuidGenerator {\n\tstatic create(): string {\n\t\treturn crypto.randomUUID()\n\t}\n}\n","import { Participant, ParticipantManifest } from \"@domain/space/participant\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport class CreateParticipantUseCase {\n\tasync execute(name: string, capabilities: readonly string[], handlers: SituationHandler[]): Promise<Participant> {\n\t\tconst manifest: ParticipantManifest = {\n\t\t\tid: UuidGenerator.create(),\n\t\t\tname,\n\t\t\tcapabilities,\n\t\t\trole: \"external\",\n\t\t}\n\t\tconst participant = new Participant(manifest, handlers)\n\t\treturn participant\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantJoinedUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.addParticipant(participant)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\n\nexport class InMemorySpaceRepository implements SpaceRepository {\n\tprivate spaces: Space[] = []\n\n\tasync save(space: Space): Promise<void> {\n\t\tthis.spaces.push(space)\n\t}\n\n\tasync findById(id: string): Promise<Space | undefined> {\n\t\treturn this.spaces.find((space) => space.getId() === id)\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\tthis.spaces = this.spaces.filter((space) => space.getId() !== id)\n\t}\n}\n","import { SpaceEvent } from \"./event\"\nimport { Participant } from \"./participant\"\n\nexport class EventPublisher {\n\tpublish(event: SpaceEvent, participants: Participant[]): void {\n\t\tfor (const participant of participants) {\n\t\t\tparticipant.getHandlers().forEach((handler) => {\n\t\t\t\tif (handler.specification.isSatisfiedBy({ event, participant })) {\n\t\t\t\t\thandler.processor.apply({ event, participant })\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantLefUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.removeParticipant(participant)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class SendMessageUseCase {\n\tconstructor(\n\t\tprivate readonly spaceRepository: SpaceRepository,\n\t\tprivate readonly eventPublisher: EventPublisher,\n\t) {}\n\n\tasync execute(spaceId: string, participantId: string, message: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.sendMessage(participant, message, new Date())\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","export class SystemClock {\n\tstatic now(): Date {\n\t\treturn new Date()\n\t}\n}\n","import { MessageSentEvent, ParticipantJoinedEvent, ParticipantLeftEvent, SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\nimport { SystemClock } from \"@util/system-clock\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport type SpaceRecord = {\n\tid: string\n\tname: string\n\tparticipants: Participant[]\n}\n\nexport class Space {\n\tprivate readonly id: string\n\tprivate name: string\n\tprivate participants: Participant[]\n\tprivate events: SpaceEvent[]\n\n\tconstructor(id: string, name: string, participants: Participant[], events: SpaceEvent[] = []) {\n\t\tthis.id = id\n\t\tthis.name = name\n\t\tthis.participants = participants\n\t\tthis.events = events\n\t}\n\n\tgetId(): string {\n\t\treturn this.id\n\t}\n\n\tgetName(): string {\n\t\treturn this.name\n\t}\n\n\taddParticipant(participant: Participant): SpaceEvent | undefined {\n\t\tconst alreadyExists = this.participants.find((p) => p.getId() === participant.getId())\n\n\t\tif (alreadyExists) return\n\n\t\tthis.participants.push(participant)\n\n\t\tconst occurredAt = SystemClock.now()\n\t\treturn ParticipantJoinedEvent.init(participant.getManifest(), occurredAt)\n\t}\n\n\tgetParticipant(id: string): Participant | undefined {\n\t\tconst participant = this.getParticipants().find((p) => p.getId() === id)\n\t\tif (!participant) {\n\t\t\tthrow new Error(`Participant ${id} not found`)\n\t\t}\n\n\t\treturn participant\n\t}\n\n\tremoveParticipant(participant: Participant): SpaceEvent {\n\t\tthis.participants = this.participants.filter((p) => p.getId() !== participant.getId())\n\n\t\tconst occurredAt = SystemClock.now()\n\t\treturn ParticipantLeftEvent.init(participant.getManifest(), occurredAt)\n\t}\n\n\tgetParticipants(): Participant[] {\n\t\treturn [...this.participants]\n\t}\n\n\tsendMessage(participant: Participant, message: string, occurredAt: Date): SpaceEvent {\n\t\tconst event = MessageSentEvent.init(participant.getId(), message, occurredAt)\n\t\tthis.events.push(event)\n\t\treturn event\n\t}\n\n\tgetEvents(): SpaceEvent[] {\n\t\treturn [...this.events]\n\t}\n\n\tstatic create(name: string, participants: Participant[] = []): Space {\n\t\tconst id = UuidGenerator.create()\n\t\treturn new Space(id, name, participants)\n\t}\n\n\tget record(): SpaceRecord {\n\t\treturn {\n\t\t\tid: this.id,\n\t\t\tname: this.name,\n\t\t\tparticipants: this.participants,\n\t\t}\n\t}\n\n\tstatic rehydrate({ id, name, participants }: SpaceRecord): Space {\n\t\treturn new Space(id, name, participants)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport class CreateSpaceUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\n\tconstructor(spaceRepository: SpaceRepository) {\n\t\tthis.spaceRepository = spaceRepository\n\t}\n\n\tasync execute(name: string): Promise<Space> {\n\t\tconst participants: Participant[] = []\n\t\tconst space = Space.create(name, participants)\n\n\t\tawait this.spaceRepository.save(space)\n\t\treturn space\n\t}\n}\n","import { RuntimeService } from \"@domain/space/runtime\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { CreateParticipantUseCase } from \"@application/use-cases/create-participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { ParticipantJoinedUseCase } from \"@application/use-cases/participant-joined\"\nimport { InMemorySpaceRepository } from \"@infrastructure/repositories/in-memory-space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\nimport { ParticipantLefUseCase } from \"@application/use-cases/participant-left\"\nimport { SendMessageUseCase } from \"@application/use-cases/send-message\"\nimport { Tool } from \"@domain/inference/tool\"\nimport { CreateSpaceUseCase } from \"@application/use-cases/create-space\"\n\nexport function defineRuntime<TSharedState extends SharedState>() {\n\tlet runtime: RuntimeService<TSharedState> | null = null\n\n\tfunction initializeRuntime(config: { state: TSharedState }): RuntimeService<TSharedState> {\n\t\tif (runtime) {\n\t\t\tthrow new Error(\"Runtime already initialized\")\n\t\t}\n\n\t\truntime = new RuntimeService(config.state)\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveRuntime(): RuntimeService<TSharedState> {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\treturn runtime\n\t}\n\n\tconst createParticipantUseCase = new CreateParticipantUseCase()\n\n\tconst createParticipant = async (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => {\n\t\treturn await createParticipantUseCase.execute(name, capabilities, handlers)\n\t}\n\n\tconst spaceRepository = new InMemorySpaceRepository()\n\tconst eventPublisher = new EventPublisher()\n\n\tconst createSpaceUseCase = new CreateSpaceUseCase(spaceRepository)\n\tconst createSpace = async (name: string) => {\n\t\treturn await createSpaceUseCase.execute(name)\n\t}\n\n\tconst participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher)\n\tconst join = async (spaceId: string, participantId: string) => {\n\t\treturn await participantJoinedUseCase.execute(spaceId, participantId)\n\t}\n\n\tconst participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher)\n\tconst leave = async (spaceId: string, participantId: string) => {\n\t\treturn await participantLeftUseCase.execute(spaceId, participantId)\n\t}\n\n\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\tconst sendMessage = async (spaceId: string, participantId: string, message: string) => {\n\t\treturn await sendMessageUseCase.execute(spaceId, participantId, message)\n\t}\n\n\tconst sendMessageTool: Tool = {\n\t\ttype: \"function\",\n\t\tname: \"send_message\",\n\t\tdescription: \"Send a message to the space. The message will be sent to all participants in the space.\",\n\t\tparameters: {\n\t\t\tspaceId: { type: \"string\" },\n\t\t\tsenderId: { type: \"string\" },\n\t\t\tmessage: { type: \"string\" },\n\t\t},\n\t\tstrict: true,\n\t\tinvoke: async (args: { spaceId: string; senderId: string; message: string }) => {\n\t\t\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\t\t\tawait sendMessageUseCase.execute(args.spaceId, args.senderId, args.message)\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tmessage: \"Message sent successfully\",\n\t\t\t}\n\t\t},\n\t}\n\n\treturn {\n\t\tinitializeRuntime,\n\t\tresolveRuntime,\n\t\tcreateParticipant,\n\t\tcreateSpace,\n\t\tjoin,\n\t\tleave,\n\t\tsendMessage,\n\t\tsendMessageTool,\n\t}\n}\n","import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {\n\treadonly event: TEvent\n\treadonly participant: Participant\n}\n\nexport abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {\n\tabstract isSatisfiedBy(situationContext: SituationContext<TEvent>): boolean\n\n\tand(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new AndSituationSpecification(this, other)\n\t}\n\n\tor(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new OrSituationSpecification(this, other)\n\t}\n\n\tnot(): SituationSpecification<TEvent> {\n\t\treturn new NotSituationSpecification(this)\n\t}\n}\n\nclass AndSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass OrSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass NotSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(private readonly rule: SituationSpecification<TEvent>) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn !this.rule.isSatisfiedBy(situationContext)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,aAAN,MAAM,YAA8D;AAAA,EAM1E,YAAY,MAAa,YAAoB,YAAkB,SAAmB;AACjF,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,aAAa;AAClB,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,OAAO,OACN,MACA,YACA,YACA,SAC8B;AAC9B,WAAO,IAAI,YAAW,MAAM,YAAY,YAAY,OAAO;AAAA,EAC5D;AACD;AAEO,IAAM,yBAAN,cAAqC,WAAsD;AAAA,EACjG,OAAO,KAAK,UAA+B,YAA0C;AACpF,WAAO,WAAW,OAAO,sBAAsB,SAAS,IAAI,YAAY,QAAQ;AAAA,EACjF;AACD;AAEO,IAAM,u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B,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,2BAAN,cAAkE,uBAA+B;AAAA,EAChG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YAA6B,MAAsC;AAClE,UAAM;AADsB;AAAA,EAE7B;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,CAAC,KAAK,KAAK,cAAc,gBAAgB;AAAA,EACjD;AACD;","names":["sendMessageUseCase"]}
package/dist/index.mjs CHANGED
@@ -10,6 +10,21 @@ var SpaceEvent = class _SpaceEvent {
10
10
  return new _SpaceEvent(type, producerId, occurredAt, payload);
11
11
  }
12
12
  };
13
+ var ParticipantJoinedEvent = class extends SpaceEvent {
14
+ static init(manifest, occurredAt) {
15
+ return SpaceEvent.create("participant.joined", manifest.id, occurredAt, manifest);
16
+ }
17
+ };
18
+ var ParticipantLeftEvent = class extends SpaceEvent {
19
+ static init(manifest, occurredAt) {
20
+ return SpaceEvent.create("participant.left", manifest.id, occurredAt, manifest);
21
+ }
22
+ };
23
+ var MessageSentEvent = class extends SpaceEvent {
24
+ static init(producerId, message, occurredAt) {
25
+ return SpaceEvent.create("message.sent", producerId, occurredAt, { message });
26
+ }
27
+ };
13
28
 
14
29
  // src/domain/space/participant.ts
15
30
  var Participant = class {
@@ -68,7 +83,7 @@ var ParticipantJoinedUseCase = class {
68
83
  this.spaceRepository = spaceRepository;
69
84
  this.eventPublisher = eventPublisher;
70
85
  }
71
- async execute(spaceId, participantId, occurredAt) {
86
+ async execute(spaceId, participantId) {
72
87
  const space = await this.spaceRepository.findById(spaceId);
73
88
  if (!space) {
74
89
  throw new Error("Space not found");
@@ -77,7 +92,7 @@ var ParticipantJoinedUseCase = class {
77
92
  if (!participant) {
78
93
  throw new Error("Participant not found");
79
94
  }
80
- const event = space.addParticipant(participant, occurredAt);
95
+ const event = space.addParticipant(participant);
81
96
  if (event) {
82
97
  this.eventPublisher.publish(event, space.getParticipants());
83
98
  }
@@ -96,9 +111,6 @@ var InMemorySpaceRepository = class {
96
111
  async findById(id) {
97
112
  return this.spaces.find((space) => space.getId() === id);
98
113
  }
99
- async findAllByOwnerId(ownerId) {
100
- return this.spaces.filter((space) => space.getOwnerId() === ownerId);
101
- }
102
114
  async delete(id) {
103
115
  this.spaces = this.spaces.filter((space) => space.getId() !== id);
104
116
  }
@@ -123,7 +135,7 @@ var ParticipantLefUseCase = class {
123
135
  this.spaceRepository = spaceRepository;
124
136
  this.eventPublisher = eventPublisher;
125
137
  }
126
- async execute(spaceId, participantId, occurredAt) {
138
+ async execute(spaceId, participantId) {
127
139
  const space = await this.spaceRepository.findById(spaceId);
128
140
  if (!space) {
129
141
  throw new Error("Space not found");
@@ -132,7 +144,7 @@ var ParticipantLefUseCase = class {
132
144
  if (!participant) {
133
145
  throw new Error("Participant not found");
134
146
  }
135
- const event = space.removeParticipant(participant, occurredAt);
147
+ const event = space.removeParticipant(participant);
136
148
  if (event) {
137
149
  this.eventPublisher.publish(event, space.getParticipants());
138
150
  }
@@ -163,6 +175,86 @@ var SendMessageUseCase = class {
163
175
  }
164
176
  };
165
177
 
178
+ // src/util/system-clock.ts
179
+ var SystemClock = class {
180
+ static now() {
181
+ return /* @__PURE__ */ new Date();
182
+ }
183
+ };
184
+
185
+ // src/domain/space/space.ts
186
+ var Space = class _Space {
187
+ constructor(id, name, participants, events = []) {
188
+ this.id = id;
189
+ this.name = name;
190
+ this.participants = participants;
191
+ this.events = events;
192
+ }
193
+ getId() {
194
+ return this.id;
195
+ }
196
+ getName() {
197
+ return this.name;
198
+ }
199
+ addParticipant(participant) {
200
+ const alreadyExists = this.participants.find((p) => p.getId() === participant.getId());
201
+ if (alreadyExists) return;
202
+ this.participants.push(participant);
203
+ const occurredAt = SystemClock.now();
204
+ return ParticipantJoinedEvent.init(participant.getManifest(), occurredAt);
205
+ }
206
+ getParticipant(id) {
207
+ const participant = this.getParticipants().find((p) => p.getId() === id);
208
+ if (!participant) {
209
+ throw new Error(`Participant ${id} not found`);
210
+ }
211
+ return participant;
212
+ }
213
+ removeParticipant(participant) {
214
+ this.participants = this.participants.filter((p) => p.getId() !== participant.getId());
215
+ const occurredAt = SystemClock.now();
216
+ return ParticipantLeftEvent.init(participant.getManifest(), occurredAt);
217
+ }
218
+ getParticipants() {
219
+ return [...this.participants];
220
+ }
221
+ sendMessage(participant, message, occurredAt) {
222
+ const event = MessageSentEvent.init(participant.getId(), message, occurredAt);
223
+ this.events.push(event);
224
+ return event;
225
+ }
226
+ getEvents() {
227
+ return [...this.events];
228
+ }
229
+ static create(name, participants = []) {
230
+ const id = UuidGenerator.create();
231
+ return new _Space(id, name, participants);
232
+ }
233
+ get record() {
234
+ return {
235
+ id: this.id,
236
+ name: this.name,
237
+ participants: this.participants
238
+ };
239
+ }
240
+ static rehydrate({ id, name, participants }) {
241
+ return new _Space(id, name, participants);
242
+ }
243
+ };
244
+
245
+ // src/application/use-cases/create-space.ts
246
+ var CreateSpaceUseCase = class {
247
+ constructor(spaceRepository) {
248
+ this.spaceRepository = spaceRepository;
249
+ }
250
+ async execute(name) {
251
+ const participants = [];
252
+ const space = Space.create(name, participants);
253
+ await this.spaceRepository.save(space);
254
+ return space;
255
+ }
256
+ };
257
+
166
258
  // src/define-runtime.ts
167
259
  function defineRuntime() {
168
260
  let runtime = null;
@@ -185,13 +277,17 @@ function defineRuntime() {
185
277
  };
186
278
  const spaceRepository = new InMemorySpaceRepository();
187
279
  const eventPublisher = new EventPublisher();
280
+ const createSpaceUseCase = new CreateSpaceUseCase(spaceRepository);
281
+ const createSpace = async (name) => {
282
+ return await createSpaceUseCase.execute(name);
283
+ };
188
284
  const participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher);
189
285
  const join = async (spaceId, participantId) => {
190
- return await participantJoinedUseCase.execute(spaceId, participantId, /* @__PURE__ */ new Date());
286
+ return await participantJoinedUseCase.execute(spaceId, participantId);
191
287
  };
192
288
  const participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher);
193
289
  const leave = async (spaceId, participantId) => {
194
- return await participantLeftUseCase.execute(spaceId, participantId, /* @__PURE__ */ new Date());
290
+ return await participantLeftUseCase.execute(spaceId, participantId);
195
291
  };
196
292
  const sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher);
197
293
  const sendMessage = async (spaceId, participantId, message) => {
@@ -220,6 +316,7 @@ function defineRuntime() {
220
316
  initializeRuntime,
221
317
  resolveRuntime,
222
318
  createParticipant,
319
+ createSpace,
223
320
  join,
224
321
  leave,
225
322
  sendMessage,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/domain/space/event.ts","../src/domain/space/participant.ts","../src/domain/space/runtime.ts","../src/util/uuid-generator.ts","../src/application/use-cases/create-participant.ts","../src/application/use-cases/participant-joined.ts","../src/infrastructure/repositories/in-memory-space-repository.ts","../src/domain/space/event-publisher.ts","../src/application/use-cases/participant-left.ts","../src/application/use-cases/send-message.ts","../src/define-runtime.ts","../src/domain/space/situation-specification.ts"],"sourcesContent":["import { ParticipantManifest } from \"@domain/space/participant\"\n\nexport class SpaceEvent<TType extends string = string, TPayload = unknown> {\n\treadonly type: TType\n\treadonly producerId: string\n\treadonly occurredAt: Date\n\treadonly payload: TPayload\n\n\tconstructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload) {\n\t\tthis.type = type\n\t\tthis.producerId = producerId\n\t\tthis.occurredAt = occurredAt\n\t\tthis.payload = payload\n\t}\n\n\tstatic create<TType extends string = string, TPayload = unknown>(\n\t\ttype: TType,\n\t\tproducerId: string,\n\t\toccurredAt: Date,\n\t\tpayload: TPayload,\n\t): SpaceEvent<TType, TPayload> {\n\t\treturn new SpaceEvent(type, producerId, occurredAt, payload)\n\t}\n}\n\nexport class ParticipantJoinedEvent extends SpaceEvent<\"participant.joined\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantJoinedEvent {\n\t\treturn SpaceEvent.create(\"participant.joined\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class ParticipantLeftEvent extends SpaceEvent<\"participant.left\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantLeftEvent {\n\t\treturn SpaceEvent.create(\"participant.left\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class MessageSentEvent extends SpaceEvent<\"message.sent\", { message: string }> {\n\tstatic init(producerId: string, message: string, occurredAt: Date): MessageSentEvent {\n\t\treturn SpaceEvent.create(\"message.sent\", producerId, occurredAt, { message })\n\t}\n}\n\nexport class ModelAnswerEvent extends SpaceEvent<\"model.answer\", { answer: string }> {\n\tstatic init(producerId: string, answer: string, occurredAt: Date): ModelAnswerEvent {\n\t\treturn ModelAnswerEvent.create(\"model.answer\", producerId, occurredAt, { answer })\n\t}\n}\n","import { SituationHandler } from \"@domain/space/situation-handler\"\n\nexport type ParticipantRole = \"agent\" | \"external\"\n\nexport type ParticipantManifest = {\n\treadonly id: string\n\treadonly name: string\n\treadonly role: ParticipantRole\n\treadonly capabilities?: readonly string[]\n}\n\nexport class Participant {\n\tprivate manifest: ParticipantManifest\n\tprivate handlers: SituationHandler[]\n\n\tconstructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tthis.manifest = manifest\n\t\tthis.handlers = handlers\n\t}\n\n\tgetManifest(): ParticipantManifest {\n\t\treturn this.manifest\n\t}\n\n\tsetManifest(manifest: ParticipantManifest): void {\n\t\tthis.manifest = manifest\n\t}\n\n\tgetId(): string {\n\t\treturn this.manifest.id\n\t}\n\n\tgetHandlers(): SituationHandler[] {\n\t\treturn this.handlers\n\t}\n\n\tsetHandlers(handlers: SituationHandler[]): void {\n\t\tthis.handlers = handlers\n\t}\n}\n","import { SharedState } from \"@domain/space/shared-state\"\n\nexport class RuntimeService<TSharedState extends SharedState> {\n\tconstructor(public readonly state: TSharedState) {}\n}\n","export class UuidGenerator {\n\tstatic create(): string {\n\t\treturn crypto.randomUUID()\n\t}\n}\n","import { Participant, ParticipantManifest } from \"@domain/space/participant\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport class CreateParticipantUseCase {\n\tasync execute(name: string, capabilities: readonly string[], handlers: SituationHandler[]): Promise<Participant> {\n\t\tconst manifest: ParticipantManifest = {\n\t\t\tid: UuidGenerator.create(),\n\t\t\tname,\n\t\t\tcapabilities,\n\t\t\trole: \"external\",\n\t\t}\n\t\tconst participant = new Participant(manifest, handlers)\n\t\treturn participant\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantJoinedUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string, occurredAt: Date): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.addParticipant(participant, occurredAt)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\n\nexport class InMemorySpaceRepository implements SpaceRepository {\n\tprivate spaces: Space[] = []\n\n\tasync save(space: Space): Promise<void> {\n\t\tthis.spaces.push(space)\n\t}\n\n\tasync findById(id: string): Promise<Space | undefined> {\n\t\treturn this.spaces.find((space) => space.getId() === id)\n\t}\n\n\tasync findAllByOwnerId(ownerId: string): Promise<Space[]> {\n\t\treturn this.spaces.filter((space) => space.getOwnerId() === ownerId)\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\tthis.spaces = this.spaces.filter((space) => space.getId() !== id)\n\t}\n}\n","import { SpaceEvent } from \"./event\"\nimport { Participant } from \"./participant\"\n\nexport class EventPublisher {\n\tpublish(event: SpaceEvent, participants: Participant[]): void {\n\t\tfor (const participant of participants) {\n\t\t\tparticipant.getHandlers().forEach((handler) => {\n\t\t\t\tif (handler.specification.isSatisfiedBy({ event, participant })) {\n\t\t\t\t\thandler.processor.apply({ event, participant })\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantLefUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string, occurredAt: Date): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.removeParticipant(participant, occurredAt)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class SendMessageUseCase {\n\tconstructor(\n\t\tprivate readonly spaceRepository: SpaceRepository,\n\t\tprivate readonly eventPublisher: EventPublisher,\n\t) {}\n\n\tasync execute(spaceId: string, participantId: string, message: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.sendMessage(participant, message, new Date())\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { RuntimeService } from \"@domain/space/runtime\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { CreateParticipantUseCase } from \"@application/use-cases/create-participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { ParticipantJoinedUseCase } from \"@application/use-cases/participant-joined\"\nimport { InMemorySpaceRepository } from \"@infrastructure/repositories/in-memory-space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\nimport { ParticipantLefUseCase } from \"@application/use-cases/participant-left\"\nimport { SendMessageUseCase } from \"@application/use-cases/send-message\"\nimport { Tool } from \"@domain/inference/tool\"\n\nexport function defineRuntime<TSharedState extends SharedState>() {\n\tlet runtime: RuntimeService<TSharedState> | null = null\n\n\tfunction initializeRuntime(config: { state: TSharedState }): RuntimeService<TSharedState> {\n\t\tif (runtime) {\n\t\t\tthrow new Error(\"Runtime already initialized\")\n\t\t}\n\n\t\truntime = new RuntimeService(config.state)\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveRuntime(): RuntimeService<TSharedState> {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\treturn runtime\n\t}\n\n\tconst createParticipantUseCase = new CreateParticipantUseCase()\n\n\tconst createParticipant = async (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => {\n\t\treturn await createParticipantUseCase.execute(name, capabilities, handlers)\n\t}\n\n\tconst spaceRepository = new InMemorySpaceRepository()\n\tconst eventPublisher = new EventPublisher()\n\tconst participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher)\n\tconst join = async (spaceId: string, participantId: string) => {\n\t\treturn await participantJoinedUseCase.execute(spaceId, participantId, new Date())\n\t}\n\n\tconst participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher)\n\tconst leave = async (spaceId: string, participantId: string) => {\n\t\treturn await participantLeftUseCase.execute(spaceId, participantId, new Date())\n\t}\n\n\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\tconst sendMessage = async (spaceId: string, participantId: string, message: string) => {\n\t\treturn await sendMessageUseCase.execute(spaceId, participantId, message)\n\t}\n\n\tconst sendMessageTool: Tool = {\n\t\ttype: \"function\",\n\t\tname: \"send_message\",\n\t\tdescription: \"Send a message to the space. The message will be sent to all participants in the space.\",\n\t\tparameters: {\n\t\t\tspaceId: { type: \"string\" },\n\t\t\tsenderId: { type: \"string\" },\n\t\t\tmessage: { type: \"string\" },\n\t\t},\n\t\tstrict: true,\n\t\tinvoke: async (args: { spaceId: string; senderId: string; message: string }) => {\n\t\t\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\t\t\tawait sendMessageUseCase.execute(args.spaceId, args.senderId, args.message)\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tmessage: \"Message sent successfully\",\n\t\t\t}\n\t\t},\n\t}\n\n\treturn {\n\t\tinitializeRuntime,\n\t\tresolveRuntime,\n\t\tcreateParticipant,\n\t\tjoin,\n\t\tleave,\n\t\tsendMessage,\n\t\tsendMessageTool,\n\t}\n}\n","import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {\n\treadonly event: TEvent\n\treadonly participant: Participant\n}\n\nexport abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {\n\tabstract isSatisfiedBy(situationContext: SituationContext<TEvent>): boolean\n\n\tand(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new AndSituationSpecification(this, other)\n\t}\n\n\tor(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new OrSituationSpecification(this, other)\n\t}\n\n\tnot(): SituationSpecification<TEvent> {\n\t\treturn new NotSituationSpecification(this)\n\t}\n}\n\nclass AndSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass OrSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass NotSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(private readonly rule: SituationSpecification<TEvent>) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn !this.rule.isSatisfiedBy(situationContext)\n\t}\n}\n"],"mappings":";AAEO,IAAM,aAAN,MAAM,YAA8D;AAAA,EAM1E,YAAY,MAAa,YAAoB,YAAkB,SAAmB;AACjF,SAAK,OAAO;AACZ,SAAK,aAAa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AEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;AC5EO,IAAe,yBAAf,MAA8E;AAAA,EAGpF,IAAI,OAAuE;AAC1E,WAAO,IAAI,0BAA0B,MAAM,KAAK;AAAA,EACjD;AAAA,EAEA,GAAG,OAAuE;AACzE,WAAO,IAAI,yBAAyB,MAAM,KAAK;AAAA,EAChD;AAAA,EAEA,MAAsC;AACrC,WAAO,IAAI,0BAA0B,IAAI;AAAA,EAC1C;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,2BAAN,cAAkE,uBAA+B;AAAA,EAChG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YAA6B,MAAsC;AAClE,UAAM;AADsB;AAAA,EAE7B;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,CAAC,KAAK,KAAK,cAAc,gBAAgB;AAAA,EACjD;AACD;","names":["sendMessageUseCase"]}
1
+ {"version":3,"sources":["../src/domain/space/event.ts","../src/domain/space/participant.ts","../src/domain/space/runtime.ts","../src/util/uuid-generator.ts","../src/application/use-cases/create-participant.ts","../src/application/use-cases/participant-joined.ts","../src/infrastructure/repositories/in-memory-space-repository.ts","../src/domain/space/event-publisher.ts","../src/application/use-cases/participant-left.ts","../src/application/use-cases/send-message.ts","../src/util/system-clock.ts","../src/domain/space/space.ts","../src/application/use-cases/create-space.ts","../src/define-runtime.ts","../src/domain/space/situation-specification.ts"],"sourcesContent":["import { ParticipantManifest } from \"@domain/space/participant\"\n\nexport class SpaceEvent<TType extends string = string, TPayload = unknown> {\n\treadonly type: TType\n\treadonly producerId: string\n\treadonly occurredAt: Date\n\treadonly payload: TPayload\n\n\tconstructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload) {\n\t\tthis.type = type\n\t\tthis.producerId = producerId\n\t\tthis.occurredAt = occurredAt\n\t\tthis.payload = payload\n\t}\n\n\tstatic create<TType extends string = string, TPayload = unknown>(\n\t\ttype: TType,\n\t\tproducerId: string,\n\t\toccurredAt: Date,\n\t\tpayload: TPayload,\n\t): SpaceEvent<TType, TPayload> {\n\t\treturn new SpaceEvent(type, producerId, occurredAt, payload)\n\t}\n}\n\nexport class ParticipantJoinedEvent extends SpaceEvent<\"participant.joined\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantJoinedEvent {\n\t\treturn SpaceEvent.create(\"participant.joined\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class ParticipantLeftEvent extends SpaceEvent<\"participant.left\", ParticipantManifest> {\n\tstatic init(manifest: ParticipantManifest, occurredAt: Date): ParticipantLeftEvent {\n\t\treturn SpaceEvent.create(\"participant.left\", manifest.id, occurredAt, manifest)\n\t}\n}\n\nexport class MessageSentEvent extends SpaceEvent<\"message.sent\", { message: string }> {\n\tstatic init(producerId: string, message: string, occurredAt: Date): MessageSentEvent {\n\t\treturn SpaceEvent.create(\"message.sent\", producerId, occurredAt, { message })\n\t}\n}\n\nexport class ModelAnswerEvent extends SpaceEvent<\"model.answer\", { answer: string }> {\n\tstatic init(producerId: string, answer: string, occurredAt: Date): ModelAnswerEvent {\n\t\treturn ModelAnswerEvent.create(\"model.answer\", producerId, occurredAt, { answer })\n\t}\n}\n","import { SituationHandler } from \"@domain/space/situation-handler\"\n\nexport type ParticipantRole = \"agent\" | \"external\"\n\nexport type ParticipantManifest = {\n\treadonly id: string\n\treadonly name: string\n\treadonly role: ParticipantRole\n\treadonly capabilities?: readonly string[]\n}\n\nexport class Participant {\n\tprivate manifest: ParticipantManifest\n\tprivate handlers: SituationHandler[]\n\n\tconstructor(manifest: ParticipantManifest, handlers: SituationHandler[]) {\n\t\tthis.manifest = manifest\n\t\tthis.handlers = handlers\n\t}\n\n\tgetManifest(): ParticipantManifest {\n\t\treturn this.manifest\n\t}\n\n\tsetManifest(manifest: ParticipantManifest): void {\n\t\tthis.manifest = manifest\n\t}\n\n\tgetId(): string {\n\t\treturn this.manifest.id\n\t}\n\n\tgetHandlers(): SituationHandler[] {\n\t\treturn this.handlers\n\t}\n\n\tsetHandlers(handlers: SituationHandler[]): void {\n\t\tthis.handlers = handlers\n\t}\n}\n","import { SharedState } from \"@domain/space/shared-state\"\n\nexport class RuntimeService<TSharedState extends SharedState> {\n\tconstructor(public readonly state: TSharedState) {}\n}\n","export class UuidGenerator {\n\tstatic create(): string {\n\t\treturn crypto.randomUUID()\n\t}\n}\n","import { Participant, ParticipantManifest } from \"@domain/space/participant\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport class CreateParticipantUseCase {\n\tasync execute(name: string, capabilities: readonly string[], handlers: SituationHandler[]): Promise<Participant> {\n\t\tconst manifest: ParticipantManifest = {\n\t\t\tid: UuidGenerator.create(),\n\t\t\tname,\n\t\t\tcapabilities,\n\t\t\trole: \"external\",\n\t\t}\n\t\tconst participant = new Participant(manifest, handlers)\n\t\treturn participant\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantJoinedUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.addParticipant(participant)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\n\nexport class InMemorySpaceRepository implements SpaceRepository {\n\tprivate spaces: Space[] = []\n\n\tasync save(space: Space): Promise<void> {\n\t\tthis.spaces.push(space)\n\t}\n\n\tasync findById(id: string): Promise<Space | undefined> {\n\t\treturn this.spaces.find((space) => space.getId() === id)\n\t}\n\n\tasync delete(id: string): Promise<void> {\n\t\tthis.spaces = this.spaces.filter((space) => space.getId() !== id)\n\t}\n}\n","import { SpaceEvent } from \"./event\"\nimport { Participant } from \"./participant\"\n\nexport class EventPublisher {\n\tpublish(event: SpaceEvent, participants: Participant[]): void {\n\t\tfor (const participant of participants) {\n\t\t\tparticipant.getHandlers().forEach((handler) => {\n\t\t\t\tif (handler.specification.isSatisfiedBy({ event, participant })) {\n\t\t\t\t\thandler.processor.apply({ event, participant })\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class ParticipantLefUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\tprivate readonly eventPublisher: EventPublisher\n\n\tconstructor(spaceRepository: SpaceRepository, eventPublisher: EventPublisher) {\n\t\tthis.spaceRepository = spaceRepository\n\t\tthis.eventPublisher = eventPublisher\n\t}\n\n\tasync execute(spaceId: string, participantId: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.removeParticipant(participant)\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","import { SpaceRepository } from \"@domain/space/space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\n\nexport class SendMessageUseCase {\n\tconstructor(\n\t\tprivate readonly spaceRepository: SpaceRepository,\n\t\tprivate readonly eventPublisher: EventPublisher,\n\t) {}\n\n\tasync execute(spaceId: string, participantId: string, message: string): Promise<void> {\n\t\tconst space = await this.spaceRepository.findById(spaceId)\n\t\tif (!space) {\n\t\t\tthrow new Error(\"Space not found\")\n\t\t}\n\t\tconst participant = space.getParticipant(participantId)\n\t\tif (!participant) {\n\t\t\tthrow new Error(\"Participant not found\")\n\t\t}\n\t\tconst event = space.sendMessage(participant, message, new Date())\n\t\tif (event) {\n\t\t\tthis.eventPublisher.publish(event, space.getParticipants())\n\t\t}\n\t\tawait this.spaceRepository.save(space)\n\t}\n}\n","export class SystemClock {\n\tstatic now(): Date {\n\t\treturn new Date()\n\t}\n}\n","import { MessageSentEvent, ParticipantJoinedEvent, ParticipantLeftEvent, SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\nimport { SystemClock } from \"@util/system-clock\"\nimport { UuidGenerator } from \"@util/uuid-generator\"\n\nexport type SpaceRecord = {\n\tid: string\n\tname: string\n\tparticipants: Participant[]\n}\n\nexport class Space {\n\tprivate readonly id: string\n\tprivate name: string\n\tprivate participants: Participant[]\n\tprivate events: SpaceEvent[]\n\n\tconstructor(id: string, name: string, participants: Participant[], events: SpaceEvent[] = []) {\n\t\tthis.id = id\n\t\tthis.name = name\n\t\tthis.participants = participants\n\t\tthis.events = events\n\t}\n\n\tgetId(): string {\n\t\treturn this.id\n\t}\n\n\tgetName(): string {\n\t\treturn this.name\n\t}\n\n\taddParticipant(participant: Participant): SpaceEvent | undefined {\n\t\tconst alreadyExists = this.participants.find((p) => p.getId() === participant.getId())\n\n\t\tif (alreadyExists) return\n\n\t\tthis.participants.push(participant)\n\n\t\tconst occurredAt = SystemClock.now()\n\t\treturn ParticipantJoinedEvent.init(participant.getManifest(), occurredAt)\n\t}\n\n\tgetParticipant(id: string): Participant | undefined {\n\t\tconst participant = this.getParticipants().find((p) => p.getId() === id)\n\t\tif (!participant) {\n\t\t\tthrow new Error(`Participant ${id} not found`)\n\t\t}\n\n\t\treturn participant\n\t}\n\n\tremoveParticipant(participant: Participant): SpaceEvent {\n\t\tthis.participants = this.participants.filter((p) => p.getId() !== participant.getId())\n\n\t\tconst occurredAt = SystemClock.now()\n\t\treturn ParticipantLeftEvent.init(participant.getManifest(), occurredAt)\n\t}\n\n\tgetParticipants(): Participant[] {\n\t\treturn [...this.participants]\n\t}\n\n\tsendMessage(participant: Participant, message: string, occurredAt: Date): SpaceEvent {\n\t\tconst event = MessageSentEvent.init(participant.getId(), message, occurredAt)\n\t\tthis.events.push(event)\n\t\treturn event\n\t}\n\n\tgetEvents(): SpaceEvent[] {\n\t\treturn [...this.events]\n\t}\n\n\tstatic create(name: string, participants: Participant[] = []): Space {\n\t\tconst id = UuidGenerator.create()\n\t\treturn new Space(id, name, participants)\n\t}\n\n\tget record(): SpaceRecord {\n\t\treturn {\n\t\t\tid: this.id,\n\t\t\tname: this.name,\n\t\t\tparticipants: this.participants,\n\t\t}\n\t}\n\n\tstatic rehydrate({ id, name, participants }: SpaceRecord): Space {\n\t\treturn new Space(id, name, participants)\n\t}\n}\n","import { Space } from \"@domain/space/space\"\nimport { SpaceRepository } from \"@domain/space/space-repository\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport class CreateSpaceUseCase {\n\tprivate readonly spaceRepository: SpaceRepository\n\n\tconstructor(spaceRepository: SpaceRepository) {\n\t\tthis.spaceRepository = spaceRepository\n\t}\n\n\tasync execute(name: string): Promise<Space> {\n\t\tconst participants: Participant[] = []\n\t\tconst space = Space.create(name, participants)\n\n\t\tawait this.spaceRepository.save(space)\n\t\treturn space\n\t}\n}\n","import { RuntimeService } from \"@domain/space/runtime\"\nimport { SituationHandler } from \"@domain/space/situation-handler\"\nimport { CreateParticipantUseCase } from \"@application/use-cases/create-participant\"\nimport { SharedState } from \"@domain/space/shared-state\"\nimport { ParticipantJoinedUseCase } from \"@application/use-cases/participant-joined\"\nimport { InMemorySpaceRepository } from \"@infrastructure/repositories/in-memory-space-repository\"\nimport { EventPublisher } from \"@domain/space/event-publisher\"\nimport { ParticipantLefUseCase } from \"@application/use-cases/participant-left\"\nimport { SendMessageUseCase } from \"@application/use-cases/send-message\"\nimport { Tool } from \"@domain/inference/tool\"\nimport { CreateSpaceUseCase } from \"@application/use-cases/create-space\"\n\nexport function defineRuntime<TSharedState extends SharedState>() {\n\tlet runtime: RuntimeService<TSharedState> | null = null\n\n\tfunction initializeRuntime(config: { state: TSharedState }): RuntimeService<TSharedState> {\n\t\tif (runtime) {\n\t\t\tthrow new Error(\"Runtime already initialized\")\n\t\t}\n\n\t\truntime = new RuntimeService(config.state)\n\n\t\treturn runtime\n\t}\n\n\tfunction resolveRuntime(): RuntimeService<TSharedState> {\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"Runtime not initialized\")\n\t\t}\n\n\t\treturn runtime\n\t}\n\n\tconst createParticipantUseCase = new CreateParticipantUseCase()\n\n\tconst createParticipant = async (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => {\n\t\treturn await createParticipantUseCase.execute(name, capabilities, handlers)\n\t}\n\n\tconst spaceRepository = new InMemorySpaceRepository()\n\tconst eventPublisher = new EventPublisher()\n\n\tconst createSpaceUseCase = new CreateSpaceUseCase(spaceRepository)\n\tconst createSpace = async (name: string) => {\n\t\treturn await createSpaceUseCase.execute(name)\n\t}\n\n\tconst participantJoinedUseCase = new ParticipantJoinedUseCase(spaceRepository, eventPublisher)\n\tconst join = async (spaceId: string, participantId: string) => {\n\t\treturn await participantJoinedUseCase.execute(spaceId, participantId)\n\t}\n\n\tconst participantLeftUseCase = new ParticipantLefUseCase(spaceRepository, eventPublisher)\n\tconst leave = async (spaceId: string, participantId: string) => {\n\t\treturn await participantLeftUseCase.execute(spaceId, participantId)\n\t}\n\n\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\tconst sendMessage = async (spaceId: string, participantId: string, message: string) => {\n\t\treturn await sendMessageUseCase.execute(spaceId, participantId, message)\n\t}\n\n\tconst sendMessageTool: Tool = {\n\t\ttype: \"function\",\n\t\tname: \"send_message\",\n\t\tdescription: \"Send a message to the space. The message will be sent to all participants in the space.\",\n\t\tparameters: {\n\t\t\tspaceId: { type: \"string\" },\n\t\t\tsenderId: { type: \"string\" },\n\t\t\tmessage: { type: \"string\" },\n\t\t},\n\t\tstrict: true,\n\t\tinvoke: async (args: { spaceId: string; senderId: string; message: string }) => {\n\t\t\tconst sendMessageUseCase = new SendMessageUseCase(spaceRepository, eventPublisher)\n\t\t\tawait sendMessageUseCase.execute(args.spaceId, args.senderId, args.message)\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tmessage: \"Message sent successfully\",\n\t\t\t}\n\t\t},\n\t}\n\n\treturn {\n\t\tinitializeRuntime,\n\t\tresolveRuntime,\n\t\tcreateParticipant,\n\t\tcreateSpace,\n\t\tjoin,\n\t\tleave,\n\t\tsendMessage,\n\t\tsendMessageTool,\n\t}\n}\n","import { SpaceEvent } from \"@domain/space/event\"\nimport { Participant } from \"@domain/space/participant\"\n\nexport type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {\n\treadonly event: TEvent\n\treadonly participant: Participant\n}\n\nexport abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {\n\tabstract isSatisfiedBy(situationContext: SituationContext<TEvent>): boolean\n\n\tand(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new AndSituationSpecification(this, other)\n\t}\n\n\tor(other: SituationSpecification<TEvent>): SituationSpecification<TEvent> {\n\t\treturn new OrSituationSpecification(this, other)\n\t}\n\n\tnot(): SituationSpecification<TEvent> {\n\t\treturn new NotSituationSpecification(this)\n\t}\n}\n\nclass AndSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass OrSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(\n\t\tprivate readonly left: SituationSpecification<TEvent>,\n\t\tprivate readonly right: SituationSpecification<TEvent>,\n\t) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext)\n\t}\n}\n\nclass NotSituationSpecification<TEvent extends SpaceEvent> extends SituationSpecification<TEvent> {\n\tconstructor(private readonly rule: SituationSpecification<TEvent>) {\n\t\tsuper()\n\t}\n\n\tisSatisfiedBy(situationContext: SituationContext<TEvent>): boolean {\n\t\treturn !this.rule.isSatisfiedBy(situationContext)\n\t}\n}\n"],"mappings":";AAEO,IAAM,aAAN,MAAM,YAA8D;AAAA,EAM1E,YAAY,MAAa,YAAoB,YAAkB,SAAmB;AACjF,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,aAAa;AAClB,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,OAAO,OACN,MACA,YACA,YACA,SAC8B;AAC9B,WAAO,IAAI,YAAW,MAAM,YAAY,YAAY,OAAO;AAAA,EAC5D;AACD;AAEO,IAAM,yBAA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AAM,KAAK;AAAA,EAChD;AAAA,EAEA,MAAsC;AACrC,WAAO,IAAI,0BAA0B,IAAI;AAAA,EAC1C;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,2BAAN,cAAkE,uBAA+B;AAAA,EAChG,YACkB,MACA,OAChB;AACD,UAAM;AAHW;AACA;AAAA,EAGlB;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,KAAK,KAAK,cAAc,gBAAgB,KAAK,KAAK,MAAM,cAAc,gBAAgB;AAAA,EAC9F;AACD;AAEA,IAAM,4BAAN,cAAmE,uBAA+B;AAAA,EACjG,YAA6B,MAAsC;AAClE,UAAM;AADsB;AAAA,EAE7B;AAAA,EAEA,cAAc,kBAAqD;AAClE,WAAO,CAAC,KAAK,KAAK,cAAc,gBAAgB;AAAA,EACjD;AACD;","names":["sendMessageUseCase"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mozaik-ai/core",
3
- "version": "4.2.0-beta.0",
3
+ "version": "4.2.0-beta.2",
4
4
  "description": "A TypeScript framework for building interoperable AI agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",