@eventcatalog/core 3.0.0-beta.2 → 3.0.0-beta.21

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.
Files changed (103) hide show
  1. package/README.md +10 -0
  2. package/dist/__mocks__/astro-content.cjs +32 -0
  3. package/dist/__mocks__/astro-content.d.cts +13 -0
  4. package/dist/__mocks__/astro-content.d.ts +13 -0
  5. package/dist/__mocks__/astro-content.js +7 -0
  6. package/dist/analytics/analytics.cjs +1 -1
  7. package/dist/analytics/analytics.js +2 -2
  8. package/dist/analytics/log-build.cjs +1 -1
  9. package/dist/analytics/log-build.js +3 -3
  10. package/dist/{chunk-JSONCD7V.js → chunk-2FUEBPD3.js} +1 -1
  11. package/dist/{chunk-3W6JYTHP.js → chunk-HABY2LVH.js} +6 -2
  12. package/dist/{chunk-H4QHE5YZ.js → chunk-KQAMO3R4.js} +1 -1
  13. package/dist/chunk-Q6KRYWPV.js +44 -0
  14. package/dist/{chunk-PQL6O5YA.js → chunk-RRP2B7BL.js} +1 -1
  15. package/dist/constants.cjs +1 -1
  16. package/dist/constants.js +1 -1
  17. package/dist/eventcatalog.cjs +84 -65
  18. package/dist/eventcatalog.config.d.cts +4 -0
  19. package/dist/eventcatalog.config.d.ts +4 -0
  20. package/dist/eventcatalog.js +45 -57
  21. package/dist/generate.cjs +48 -2
  22. package/dist/generate.js +3 -1
  23. package/dist/utils/cli-logger.cjs +82 -0
  24. package/dist/utils/cli-logger.d.cts +10 -0
  25. package/dist/utils/cli-logger.d.ts +10 -0
  26. package/dist/utils/cli-logger.js +7 -0
  27. package/eventcatalog/astro.config.mjs +4 -1
  28. package/eventcatalog/integrations/ecstudio-watcher.mjs +1 -1
  29. package/eventcatalog/integrations/eventcatalog-features.ts +69 -0
  30. package/eventcatalog/public/icons/asyncapi-black.svg +2 -0
  31. package/eventcatalog/public/icons/graphql-black.svg +1 -0
  32. package/eventcatalog/public/icons/openapi-black.svg +1 -0
  33. package/eventcatalog/src/components/ChatPanel/ChatPanel.tsx +821 -0
  34. package/eventcatalog/src/components/ChatPanel/ChatPanelButton.tsx +24 -0
  35. package/eventcatalog/src/components/Grids/DomainGrid.tsx +1 -3
  36. package/eventcatalog/src/components/Grids/MessageGrid.tsx +8 -8
  37. package/eventcatalog/src/components/Header.astro +25 -5
  38. package/eventcatalog/src/components/MDX/NodeGraph/NodeGraph.tsx +14 -3
  39. package/eventcatalog/src/components/Search/Search.astro +2 -2
  40. package/eventcatalog/src/components/Search/SearchModal.tsx +16 -7
  41. package/eventcatalog/src/components/SideNav/NestedSideBar/SearchBar.tsx +9 -2
  42. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/domain.ts +7 -6
  43. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/service.ts +6 -3
  44. package/eventcatalog/src/components/SideNav/NestedSideBar/builders/shared.ts +1 -0
  45. package/eventcatalog/src/components/SideNav/NestedSideBar/index.tsx +23 -8
  46. package/eventcatalog/src/components/SideNav/NestedSideBar/sidebar-builder.ts +57 -11
  47. package/eventcatalog/src/content.config.ts +1 -10
  48. package/eventcatalog/src/enterprise/ai/chat-api.ts +262 -0
  49. package/eventcatalog/src/enterprise/auth/[...auth].ts +3 -0
  50. package/eventcatalog/src/enterprise/auth/login.astro +420 -0
  51. package/eventcatalog/src/enterprise/collections/index.ts +0 -1
  52. package/eventcatalog/src/layouts/Footer.astro +8 -5
  53. package/eventcatalog/src/layouts/VerticalSideBarLayout.astro +30 -19
  54. package/eventcatalog/src/pages/_index.astro +8 -9
  55. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/asyncapi/[filename].astro +19 -3
  56. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/changelog/index.astro +7 -7
  57. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/graphql/[filename].astro +1 -1
  58. package/eventcatalog/src/pages/docs/[type]/[id]/[version]/index.astro +5 -5
  59. package/eventcatalog/src/pages/docs/teams/[id].mdx.ts +36 -0
  60. package/eventcatalog/src/pages/docs/users/[id].mdx.ts +36 -0
  61. package/eventcatalog/src/pages/schemas/explorer/_index.data.ts +178 -0
  62. package/eventcatalog/src/pages/schemas/explorer/index.astro +5 -155
  63. package/eventcatalog/src/remark-plugins/directives.ts +30 -9
  64. package/eventcatalog/src/utils/collections/schemas.ts +31 -7
  65. package/eventcatalog/src/utils/feature.ts +8 -4
  66. package/eventcatalog/src/utils/resource-files.ts +86 -0
  67. package/package.json +12 -15
  68. package/default-files-for-collections/changelogs.md +0 -5
  69. package/default-files-for-collections/channels.md +0 -8
  70. package/default-files-for-collections/commands.md +0 -8
  71. package/default-files-for-collections/domains.md +0 -8
  72. package/default-files-for-collections/events.md +0 -8
  73. package/default-files-for-collections/flows.md +0 -11
  74. package/default-files-for-collections/queries.md +0 -8
  75. package/default-files-for-collections/services.md +0 -8
  76. package/default-files-for-collections/ubiquitousLanguages.md +0 -7
  77. package/eventcatalog/src/enterprise/collections/chat-prompts.ts +0 -32
  78. package/eventcatalog/src/enterprise/eventcatalog-chat/components/Chat.tsx +0 -60
  79. package/eventcatalog/src/enterprise/eventcatalog-chat/components/ChatMessage.tsx +0 -414
  80. package/eventcatalog/src/enterprise/eventcatalog-chat/components/ChatSidebar.tsx +0 -169
  81. package/eventcatalog/src/enterprise/eventcatalog-chat/components/InputModal.tsx +0 -244
  82. package/eventcatalog/src/enterprise/eventcatalog-chat/components/MentionInput.tsx +0 -211
  83. package/eventcatalog/src/enterprise/eventcatalog-chat/components/WelcomePromptArea.tsx +0 -176
  84. package/eventcatalog/src/enterprise/eventcatalog-chat/components/default-prompts.ts +0 -93
  85. package/eventcatalog/src/enterprise/eventcatalog-chat/components/hooks/ChatProvider.tsx +0 -143
  86. package/eventcatalog/src/enterprise/eventcatalog-chat/components/windows/ChatWindow.server.tsx +0 -387
  87. package/eventcatalog/src/enterprise/eventcatalog-chat/pages/api/chat.ts +0 -59
  88. package/eventcatalog/src/enterprise/eventcatalog-chat/pages/chat/index.astro +0 -104
  89. package/eventcatalog/src/enterprise/eventcatalog-chat/providers/ai-provider.ts +0 -140
  90. package/eventcatalog/src/enterprise/eventcatalog-chat/providers/anthropic.ts +0 -28
  91. package/eventcatalog/src/enterprise/eventcatalog-chat/providers/google.ts +0 -41
  92. package/eventcatalog/src/enterprise/eventcatalog-chat/providers/index.ts +0 -26
  93. package/eventcatalog/src/enterprise/eventcatalog-chat/providers/openai.ts +0 -61
  94. package/eventcatalog/src/enterprise/eventcatalog-chat/utils/chat-prompts.ts +0 -50
  95. package/eventcatalog/src/pages/auth/login.astro +0 -280
  96. package/eventcatalog/src/pages/chat/feature.astro +0 -179
  97. package/eventcatalog/src/pages/chat/index.astro +0 -10
  98. package/eventcatalog/src/pages/nav-index.json.ts +0 -30
  99. /package/eventcatalog/src/{pages → enterprise}/auth/error.astro +0 -0
  100. /package/eventcatalog/src/{middleware-auth.ts → enterprise/auth/middleware/middleware-auth.ts} +0 -0
  101. /package/eventcatalog/src/{middleware.ts → enterprise/auth/middleware/middleware.ts} +0 -0
  102. /package/eventcatalog/src/{pages/unauthorized/index.astro → enterprise/auth/unauthorized.astro} +0 -0
  103. /package/eventcatalog/src/{pages → enterprise}/plans/index.astro +0 -0
@@ -7,7 +7,7 @@ import fs from 'fs';
7
7
  import path from 'path';
8
8
 
9
9
  // Enterprise Collections
10
- import { chatPromptsSchema, customPagesSchema } from './enterprise/collections';
10
+ import { customPagesSchema } from './enterprise/collections';
11
11
 
12
12
  export const projectDirBase = (() => {
13
13
  if (process.platform === 'win32') {
@@ -469,14 +469,6 @@ const customPages = defineCollection({
469
469
  schema: customPagesSchema,
470
470
  });
471
471
 
472
- const chatPrompts = defineCollection({
473
- loader: glob({
474
- pattern: ['chat-prompts/*.(md|mdx)', 'chat-prompts/**/*.@(md|mdx)'],
475
- base: projectDirBase,
476
- }),
477
- schema: chatPromptsSchema,
478
- });
479
-
480
472
  const domains = defineCollection({
481
473
  loader: glob({
482
474
  pattern: [
@@ -722,7 +714,6 @@ export const collections = {
722
714
 
723
715
  // EventCatalog Pro Collections
724
716
  customPages,
725
- chatPrompts,
726
717
 
727
718
  // EventCatalog Studio Collections
728
719
  designs,
@@ -0,0 +1,262 @@
1
+ import type { APIContext } from 'astro';
2
+ import { convertToModelMessages, stepCountIs, streamText, tool, type LanguageModel, type ModelMessage, type UIMessage } from 'ai';
3
+ import { join } from 'node:path';
4
+ import { isEventCatalogScaleEnabled } from '@utils/feature';
5
+ import { z, getCollection, getEntry } from 'astro:content';
6
+ import { getConsumersOfMessage, getProducersOfMessage } from '@utils/collections/services';
7
+ import { getSchemasFromResource } from '@utils/collections/schemas';
8
+ import fs from 'fs';
9
+
10
+ const catalogDirectory = process.env.PROJECT_DIR || process.cwd();
11
+
12
+ export const defaultConfiguration = {
13
+ temperature: 0.4,
14
+ topP: 0.9,
15
+ topK: 40,
16
+ frequencyPenalty: 0.1,
17
+ presencePenalty: 0.0,
18
+ maxTokens: 1000,
19
+ };
20
+
21
+ let hasChatConfiguration = false;
22
+ let model: LanguageModel;
23
+ let modelConfiguration: any;
24
+
25
+ try {
26
+ const providerConfiguration = await import(/* @vite-ignore */ join(catalogDirectory, 'eventcatalog.chat.js'));
27
+ model = await providerConfiguration.default();
28
+ modelConfiguration = providerConfiguration.configuration || defaultConfiguration;
29
+ hasChatConfiguration = true;
30
+ } catch (error) {
31
+ hasChatConfiguration = false;
32
+ }
33
+
34
+ const getBaseSystemPrompt = (
35
+ referrer: string
36
+ ) => `You are an expert in software architecture and domain-driven design, specializing in the open source tool EventCatalog.
37
+
38
+ You assist developers, architects, and business stakeholders who need information about their software architecture catalog.
39
+
40
+ There are many different resource types in EventCatalog, including:
41
+ - Events (collection name 'events') (asynchronous messages that notify about something that has happened)
42
+ - Commands (collection name 'commands') (requests to perform an action)
43
+ - Queries (collection name 'queries') (requests for information)
44
+ - Services (collection name 'services') (bounded contexts or applications that produce/consume events)
45
+ - Domains (collection name 'domains') (business capabilities or functional areas)
46
+ - Flows (collection name 'flows') (state machines)
47
+ - Channels (collection name 'channels') (communication channels)
48
+ - Entities (collection name 'entities') (data objects)
49
+ - Containers (collection name 'containers') (at the moment these are data stores (databases))
50
+
51
+ The user will ask you some questions about the software architecture catalog, you should use the tools provided to you to get the information they need.
52
+
53
+ At point the referer url will be the URL of the page the user is on, you should use this to help you answer the question,
54
+ You may be able to get the resource from the URL, example if the URL is /docs/events/MyEvent/1.0.0 you can get the resource from the URL, in this case the id is MyEvent and the version is 1.0.0 and collection is events.
55
+
56
+ The referer URL is ${referrer}
57
+
58
+ Some other examples
59
+
60
+ - /docs/events/MyEvent/1.0.0 -> id: MyEvent, version: 1.0.0, collection: events
61
+ - /architecture/domains/E-Commerce/1.0.0 -> id: E-Commerce, version: 1.0.0, collection: domains
62
+ - /visualiser/domains/E-Commerce/1.0.0
63
+
64
+ Sometimes the user will be on the specification page (openapi, asyncapi, graphql) for a resource too
65
+ - /docs/services/OrdersService/0.0.3/asyncapi/order-service-asyncapi -> id: OrdersService, version: 0.0.3, collection: services, schema (specification): asyncapi
66
+ - /docs/services/OrdersService/0.0.3/spec/openapi-v2 -> id: OrdersService, version: 0.0.3, collection: services, schema (specification): openapi
67
+
68
+ Your primary goal is to help users understand their software architecture through accurate documentation interpretation.
69
+ Use the tools provided to get the context you need to an answer the question.
70
+
71
+ When responding:
72
+ 1. Explain connections between resources when relevant.
73
+ 2.. Use appropriate technical terminology.
74
+ 3.. Use clear formatting with headings and bullet points when helpful.
75
+ 4. State clearly when information is missing rather than making assumptions.
76
+ 5. Don't provide code examples unless specifically requested.
77
+ 6. When you refer to a resource in EventCatalog, try and create a link to the resource in the response
78
+ - Example, if you return a message in the text, rather than than just the id or version you should return a markdown link to the resource e.g [MyEvent - 1.0.0](/docs/events/MyEvent/1.0.0)
79
+ - NEVER return "latest" in the markdown link, always use the specific version
80
+ - The link options are:
81
+ - If you want to get the documentation for a resource use the /docs/ prefix (e.g /docs/{collection}/{id}/{version})
82
+ - If you want to let the user know they can visualize a resource use the /visualiser/ prefix (e.g /visualiser/{collection}/{id}/{version})
83
+ - If you want to let the user know they can see the architecture of a resource use the /architecture/ prefix (e.g /architecture/{collection}/{id}/{version})
84
+ 7. When you return a schema, use code blocks to render the schema to the user too, for example if the schema is in JSON format use \`\`\`json and if the schema is in YAML format use \`\`\`yaml
85
+
86
+ If you have additional context, use it to answer the question.`;
87
+
88
+ interface Message {
89
+ content: string;
90
+ }
91
+
92
+ export const GET = async ({ request }: APIContext<{ question: string; messages: Message[]; additionalContext?: string }>) => {
93
+ // return 404
94
+ return new Response(JSON.stringify({ error: 'Not found' }), {
95
+ status: 404,
96
+ headers: { 'Content-Type': 'application/json' },
97
+ });
98
+ };
99
+
100
+ export const POST = async ({ request }: APIContext<{ question: string; messages: Message[]; additionalContext?: string }>) => {
101
+ const { messages }: { messages: UIMessage[] } = await request.json();
102
+
103
+ if (!isEventCatalogScaleEnabled()) {
104
+ return new Response(JSON.stringify({ error: 'Chat is not enabled, please upgrade to the scale plan to use this feature' }), {
105
+ status: 403,
106
+ headers: { 'Content-Type': 'application/json' },
107
+ });
108
+ }
109
+
110
+ if (!hasChatConfiguration) {
111
+ return new Response(JSON.stringify({ error: 'No chat configuration found' }), {
112
+ status: 404,
113
+ headers: { 'Content-Type': 'application/json' },
114
+ });
115
+ }
116
+
117
+ // Get the URL of the request
118
+ const referrer = request.headers.get('referer');
119
+
120
+ const result = await streamText({
121
+ model,
122
+ system: getBaseSystemPrompt(referrer ?? ''),
123
+ messages: convertToModelMessages(messages) as ModelMessage[],
124
+ temperature: modelConfiguration?.temperature ?? 0.7,
125
+ stopWhen: stepCountIs(5),
126
+ // maxTokens: 4000, // Increased to handle large tool results
127
+ onError: (error) => {
128
+ console.error('[Chat] On error', error);
129
+ },
130
+ // maxOutputTokens: 40000,
131
+ // tools: tools,
132
+ tools: {
133
+ getResources: tool({
134
+ description:
135
+ 'Use this tool to get events, services, commands, queries, flows, domains, channels, entities from EventCatalog',
136
+ inputSchema: z.object({
137
+ collection: z
138
+ .enum(['events', 'services', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
139
+ .describe('The collection to get the events from'),
140
+ }),
141
+ execute: async ({ collection }) => {
142
+ const resources = await getCollection(collection as any);
143
+ return resources.map((resource: any) => ({
144
+ id: resource.data.id,
145
+ version: resource.data.version,
146
+ name: resource.data.name,
147
+ }));
148
+ },
149
+ }),
150
+ getResource: tool({
151
+ description: 'Use this tool to get a specific resource from EventCatalog by its id and version',
152
+ inputSchema: z.object({
153
+ collection: z
154
+ .enum(['events', 'services', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
155
+ .describe('The collection to get the events from'),
156
+ id: z.string().describe('The id of the resource to get'),
157
+ version: z.string().describe('The version of the resource to get'),
158
+ }),
159
+ execute: async ({ collection, id, version }) => {
160
+ const resource = await getEntry(collection as any, `${id}-${version}`);
161
+ return resource;
162
+ },
163
+ }),
164
+ getMessagesProducedOrConsumedByResource: tool({
165
+ description:
166
+ 'Use this tool to get the messages produced or consumed by a resource by its id and version. Look at the `sends` and `receives` properties to get the messages produced or consumed by the resource',
167
+ inputSchema: z.object({
168
+ resourceId: z.string().describe('The id of the resource to get the messages produced or consumed for'),
169
+ resourceVersion: z.string().describe('The version of the resource to get the messages produced or consumed for'),
170
+ resourceCollection: z
171
+ .enum(['services', 'events', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
172
+ .describe('The collection of the resource to get the messages produced or consumed for')
173
+ .default('services'),
174
+ }),
175
+ execute: async ({ resourceId, resourceVersion, resourceCollection }) => {
176
+ const resource = await getEntry(resourceCollection as any, `${resourceId}-${resourceVersion}`);
177
+ if (!resource) {
178
+ return {
179
+ error: `Resource not found with id ${resourceId} and version ${resourceVersion} and collection ${resourceCollection}`,
180
+ };
181
+ }
182
+ return resource;
183
+ },
184
+ }),
185
+ getProducerAndConsumerForMessage: tool({
186
+ description: 'Use this tool to get the producers and consumers for a message by its id and version',
187
+ inputSchema: z.object({
188
+ messageId: z.string().describe('The id of the message to get the producers and consumers for'),
189
+ messageVersion: z.string().describe('The version of the message to get the producers and consumers for'),
190
+ messageCollection: z
191
+ .enum(['events', 'commands', 'queries'])
192
+ .describe('The collection of the message to get the producers and consumers for')
193
+ .default('events'),
194
+ }),
195
+ execute: async ({ messageId, messageVersion, messageCollection }) => {
196
+ const services = await getCollection('services');
197
+ const message = await getEntry(messageCollection as any, `${messageId}-${messageVersion}`);
198
+ const consumers = await getProducersOfMessage(services, message as any);
199
+ return consumers;
200
+ },
201
+ }),
202
+ getConsumersOfMessage: tool({
203
+ description: 'Use this tool to get the consumers for a message by its id and version',
204
+ inputSchema: z.object({
205
+ messageId: z.string().describe('The id of the message to get the consumers for'),
206
+ messageVersion: z.string().describe('The version of the message to get the consumers for'),
207
+ messageCollection: z
208
+ .enum(['events', 'commands', 'queries'])
209
+ .describe('The collection of the message to get the consumers for')
210
+ .default('events'),
211
+ }),
212
+ execute: async ({ messageId, messageVersion, messageCollection }) => {
213
+ const services = await getCollection('services');
214
+ const message = await getEntry(messageCollection as any, `${messageId}-${messageVersion}`);
215
+ const consumers = await getConsumersOfMessage(services, message as any);
216
+ return consumers;
217
+ },
218
+ }),
219
+ getSchemaForResource: tool({
220
+ description:
221
+ 'Use this tool to get the schema or specifications (openapi or asyncapi or graphql) for a resource by its id and version, you will use code blocks to render the schema to the user too',
222
+ inputSchema: z.object({
223
+ resourceId: z.string().describe('The id of the resource to get the schema for'),
224
+ resourceVersion: z.string().describe('The version of the resource to get the schema for'),
225
+ resourceCollection: z
226
+ .enum(['services', 'events', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
227
+ .describe('The collection of the resource to get the schema for')
228
+ .default('services'),
229
+ }),
230
+ execute: async ({ resourceId, resourceVersion, resourceCollection }) => {
231
+ const resource = await getEntry(resourceCollection as any, `${resourceId}-${resourceVersion}`);
232
+
233
+ if (!resource) {
234
+ return {
235
+ error: `Resource not found with id ${resourceId} and version ${resourceVersion} and collection ${resourceCollection}`,
236
+ };
237
+ }
238
+
239
+ const schema = await getSchemasFromResource(resource);
240
+
241
+ // If we have any schemas back then read them and return them
242
+ if (schema.length > 0) {
243
+ return schema.map((schemaItem) => ({
244
+ url: schemaItem.url,
245
+ format: schemaItem.format,
246
+ code: fs.readFileSync(schemaItem.url, 'utf-8'),
247
+ }));
248
+ }
249
+
250
+ return [];
251
+ },
252
+ }),
253
+ },
254
+ });
255
+ return result.toUIMessageStreamResponse({
256
+ headers: {
257
+ 'Content-Type': 'text/event-stream',
258
+ },
259
+ });
260
+ };
261
+
262
+ export const prerender = false;
@@ -0,0 +1,3 @@
1
+ import { AstroAuth } from 'auth-astro/server';
2
+ export const prerender = false;
3
+ export const { GET, POST } = AstroAuth();