@eventcatalog/core 3.0.0-beta.9 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -98
- package/dist/__mocks__/astro-content.cjs +32 -0
- package/dist/__mocks__/astro-content.d.cts +13 -0
- package/dist/__mocks__/astro-content.d.ts +13 -0
- package/dist/__mocks__/astro-content.js +7 -0
- package/dist/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/catalog-to-astro-content-directory.cjs +2 -19
- package/dist/catalog-to-astro-content-directory.d.cts +1 -2
- package/dist/catalog-to-astro-content-directory.d.ts +1 -2
- package/dist/catalog-to-astro-content-directory.js +3 -5
- package/dist/{chunk-RAJ7TGWN.js → chunk-2WGZFERB.js} +1 -1
- package/dist/{chunk-R2BJ7MJG.js → chunk-6Z6ARMQS.js} +1 -17
- package/dist/{chunk-TC3R47V6.js → chunk-ESUL7UE6.js} +1 -1
- package/dist/{chunk-2VPX4WIJ.js → chunk-I3CW5KQI.js} +1 -1
- package/dist/{chunk-TT4LZO2Q.js → chunk-KBO4IL2D.js} +1 -1
- package/dist/{chunk-A4MGWK5T.js → chunk-URR33SNK.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +20 -64
- package/dist/eventcatalog.config.d.cts +11 -0
- package/dist/eventcatalog.config.d.ts +11 -0
- package/dist/eventcatalog.js +26 -52
- package/dist/generate.cjs +1 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/astro.config.mjs +4 -1
- package/eventcatalog/integrations/eventcatalog-features.ts +69 -0
- package/eventcatalog/public/icons/asyncapi-black.svg +2 -0
- package/eventcatalog/public/icons/graphql-black.svg +1 -0
- package/eventcatalog/public/icons/openapi-black.svg +1 -0
- package/eventcatalog/src/components/ChatPanel/ChatPanel.tsx +1010 -0
- package/eventcatalog/src/components/ChatPanel/ChatPanelButton.tsx +24 -0
- package/eventcatalog/src/components/Checkbox.astro +7 -4
- package/eventcatalog/src/components/CopyAsMarkdown.tsx +15 -15
- package/eventcatalog/src/components/EnvironmentDropdown.tsx +15 -7
- package/eventcatalog/src/components/FavoriteButton.tsx +1 -1
- package/eventcatalog/src/components/Grids/DomainGrid.tsx +322 -173
- package/eventcatalog/src/components/Grids/MessageGrid.tsx +317 -178
- package/eventcatalog/src/components/Grids/specification-utils.ts +106 -0
- package/eventcatalog/src/components/Header.astro +40 -15
- package/eventcatalog/src/components/Lists/OwnersList.tsx +17 -10
- package/eventcatalog/src/components/Lists/PillListFlat.styles.css +12 -0
- package/eventcatalog/src/components/Lists/PillListFlat.tsx +15 -15
- package/eventcatalog/src/components/Lists/VersionList.astro +15 -5
- package/eventcatalog/src/components/MDX/Accordion/Accordion.tsx +3 -3
- package/eventcatalog/src/components/MDX/Admonition.tsx +49 -9
- package/eventcatalog/src/components/MDX/Attachments.astro +15 -11
- package/eventcatalog/src/components/MDX/ChannelInformation/ChannelInformation.tsx +29 -15
- package/eventcatalog/src/components/MDX/EntityPropertiesTable/EntityPropertiesTable.astro +20 -13
- package/eventcatalog/src/components/MDX/Link/Link.astro +1 -1
- package/eventcatalog/src/components/MDX/MessageTable/MessageTable.client.tsx +50 -29
- package/eventcatalog/src/components/MDX/NodeGraph/NodeGraph.tsx +28 -15
- package/eventcatalog/src/components/MDX/NodeGraph/StepWalkthrough.tsx +4 -4
- package/eventcatalog/src/components/MDX/NodeGraph/StudioModal.tsx +4 -4
- package/eventcatalog/src/components/MDX/NodeGraph/VisualiserSearch.tsx +2 -2
- package/eventcatalog/src/components/MDX/ResourceGroupTable/ResourceGroupTable.client.tsx +54 -33
- package/eventcatalog/src/components/MDX/ResourceLink/ResourceLink.astro +1 -1
- package/eventcatalog/src/components/MDX/Steps/Step.astro +2 -2
- package/eventcatalog/src/components/MDX/Steps/Steps.astro +3 -3
- package/eventcatalog/src/components/MDX/Tabs/Tabs.astro +13 -9
- package/eventcatalog/src/components/MDX/Tiles/Tile.astro +25 -13
- package/eventcatalog/src/components/MDX/Tiles/Tiles.astro +1 -1
- package/eventcatalog/src/components/SchemaExplorer/ApiAccessSection.tsx +95 -90
- package/eventcatalog/src/components/SchemaExplorer/ApiContentViewer.tsx +144 -0
- package/eventcatalog/src/components/SchemaExplorer/AvroSchemaViewer.tsx +29 -25
- package/eventcatalog/src/components/SchemaExplorer/DiffViewer.tsx +3 -3
- package/eventcatalog/src/components/SchemaExplorer/JSONSchemaViewer.tsx +61 -42
- package/eventcatalog/src/components/SchemaExplorer/OwnersSection.tsx +13 -9
- package/eventcatalog/src/components/SchemaExplorer/Pagination.tsx +36 -8
- package/eventcatalog/src/components/SchemaExplorer/ProducersConsumersSection.tsx +17 -13
- package/eventcatalog/src/components/SchemaExplorer/SchemaContentViewer.tsx +37 -10
- package/eventcatalog/src/components/SchemaExplorer/SchemaDetailsHeader.tsx +152 -109
- package/eventcatalog/src/components/SchemaExplorer/SchemaDetailsPanel.tsx +6 -15
- package/eventcatalog/src/components/SchemaExplorer/SchemaExplorer.tsx +257 -61
- package/eventcatalog/src/components/SchemaExplorer/SchemaFilters.tsx +64 -126
- package/eventcatalog/src/components/SchemaExplorer/SchemaListItem.tsx +53 -43
- package/eventcatalog/src/components/SchemaExplorer/SchemaViewerModal.tsx +8 -8
- package/eventcatalog/src/components/Search/Search.astro +5 -5
- package/eventcatalog/src/components/Search/SearchDataLoader.astro +25 -0
- package/eventcatalog/src/components/Search/SearchModal.tsx +65 -36
- package/eventcatalog/src/components/SideNav/NestedSideBar/SearchBar.tsx +37 -24
- package/eventcatalog/src/components/SideNav/NestedSideBar/index.tsx +117 -56
- package/eventcatalog/src/components/SideNav/SideNav.astro +0 -15
- package/eventcatalog/src/components/Tables/Table.tsx +97 -77
- package/eventcatalog/src/components/Tables/columns/ContainersTableColumns.tsx +114 -74
- package/eventcatalog/src/components/Tables/columns/DomainTableColumns.tsx +77 -55
- package/eventcatalog/src/components/Tables/columns/FlowTableColumns.tsx +36 -36
- package/eventcatalog/src/components/Tables/columns/MessageTableColumns.tsx +116 -77
- package/eventcatalog/src/components/Tables/columns/ServiceTableColumns.tsx +111 -94
- package/eventcatalog/src/components/Tables/columns/SharedColumns.tsx +31 -26
- package/eventcatalog/src/components/Tables/columns/TeamsTableColumns.tsx +123 -215
- package/eventcatalog/src/components/Tables/columns/UserTableColumns.tsx +156 -243
- package/eventcatalog/src/components/ThemeToggle.tsx +18 -0
- package/eventcatalog/src/content.config.ts +1 -13
- package/eventcatalog/src/enterprise/ai/chat-api.ts +360 -0
- package/eventcatalog/src/enterprise/auth/[...auth].ts +3 -0
- package/eventcatalog/src/enterprise/auth/login.astro +420 -0
- package/eventcatalog/src/enterprise/collections/index.ts +0 -1
- package/eventcatalog/src/enterprise/custom-documentation/components/CustomDocsNav/components/NestedItem.tsx +15 -7
- package/eventcatalog/src/enterprise/custom-documentation/components/CustomDocsNav/components/NoResultsFound.tsx +2 -2
- package/eventcatalog/src/enterprise/custom-documentation/components/CustomDocsNav/index.tsx +19 -15
- package/eventcatalog/src/enterprise/custom-documentation/pages/docs/custom/index.astro +50 -17
- package/eventcatalog/src/layouts/DirectoryLayout.astro +11 -6
- package/eventcatalog/src/layouts/DiscoverLayout.astro +13 -8
- package/eventcatalog/src/layouts/Footer.astro +14 -11
- package/eventcatalog/src/layouts/VerticalSideBarLayout.astro +187 -123
- package/eventcatalog/src/pages/_index.astro +213 -573
- package/eventcatalog/src/pages/architecture/[type]/[id]/[version]/_index.data.ts +8 -2
- package/eventcatalog/src/pages/architecture/[type]/[id]/[version]/index.astro +9 -5
- package/eventcatalog/src/pages/directory/[type]/index.astro +6 -0
- package/eventcatalog/src/pages/docs/[type]/[id]/[version]/asyncapi/[filename].astro +19 -3
- package/eventcatalog/src/pages/docs/[type]/[id]/[version]/changelog/index.astro +7 -7
- package/eventcatalog/src/pages/docs/[type]/[id]/[version]/graphql/[filename].astro +5 -5
- package/eventcatalog/src/pages/docs/[type]/[id]/[version]/index.astro +81 -64
- package/eventcatalog/src/pages/docs/[type]/[id]/language/[dictionaryId]/index.astro +23 -24
- package/eventcatalog/src/pages/docs/[type]/[id]/language/index.astro +214 -125
- package/eventcatalog/src/pages/docs/custom/index.astro +2 -2
- package/eventcatalog/src/pages/docs/teams/[id]/index.astro +98 -70
- package/eventcatalog/src/pages/docs/teams/[id].mdx.ts +36 -0
- package/eventcatalog/src/pages/docs/users/[id]/index.astro +60 -45
- package/eventcatalog/src/pages/docs/users/[id].mdx.ts +36 -0
- package/eventcatalog/src/pages/schemas/explorer/_index.data.ts +178 -0
- package/eventcatalog/src/pages/schemas/explorer/index.astro +7 -157
- package/eventcatalog/src/pages/studio.astro +155 -75
- package/eventcatalog/src/remark-plugins/directives.ts +36 -15
- package/eventcatalog/src/remark-plugins/mermaid.ts +2 -2
- package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/container.ts +10 -1
- package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/domain.ts +17 -7
- package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/message.ts +10 -1
- package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/service.ts +11 -4
- package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/shared.ts +14 -0
- package/eventcatalog/src/stores/{sidebar-store.ts → sidebar-store/index.ts} +1 -1
- package/eventcatalog/src/stores/theme-store.ts +93 -0
- package/eventcatalog/src/styles/theme.css +255 -0
- package/eventcatalog/src/styles/themes/forest.css +230 -0
- package/eventcatalog/src/styles/themes/ocean.css +235 -0
- package/eventcatalog/src/styles/themes/sapphire.css +230 -0
- package/eventcatalog/src/styles/themes/sunset.css +230 -0
- package/eventcatalog/src/utils/collections/channels.ts +0 -2
- package/eventcatalog/src/utils/collections/commands.ts +0 -2
- package/eventcatalog/src/utils/collections/containers.ts +0 -2
- package/eventcatalog/src/utils/collections/domains.ts +0 -2
- package/eventcatalog/src/utils/collections/entities.ts +0 -2
- package/eventcatalog/src/utils/collections/events.ts +0 -2
- package/eventcatalog/src/utils/collections/flows.ts +0 -2
- package/eventcatalog/src/utils/collections/queries.ts +0 -2
- package/eventcatalog/src/utils/collections/schemas.ts +45 -7
- package/eventcatalog/src/utils/collections/services.ts +0 -2
- package/eventcatalog/src/utils/feature.ts +13 -5
- package/eventcatalog/src/utils/node-graphs/services-node-graph.ts +1 -1
- package/eventcatalog/src/utils/resource-files.ts +86 -0
- package/eventcatalog/tailwind.config.mjs +6 -3
- package/package.json +12 -15
- package/default-files-for-collections/changelogs.md +0 -5
- package/default-files-for-collections/channels.md +0 -8
- package/default-files-for-collections/commands.md +0 -8
- package/default-files-for-collections/domains.md +0 -8
- package/default-files-for-collections/events.md +0 -8
- package/default-files-for-collections/flows.md +0 -11
- package/default-files-for-collections/queries.md +0 -8
- package/default-files-for-collections/services.md +0 -8
- package/default-files-for-collections/ubiquitousLanguages.md +0 -7
- package/eventcatalog/src/enterprise/collections/chat-prompts.ts +0 -32
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/Chat.tsx +0 -60
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/ChatMessage.tsx +0 -414
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/ChatSidebar.tsx +0 -169
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/InputModal.tsx +0 -244
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/MentionInput.tsx +0 -211
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/WelcomePromptArea.tsx +0 -176
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/default-prompts.ts +0 -93
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/hooks/ChatProvider.tsx +0 -143
- package/eventcatalog/src/enterprise/eventcatalog-chat/components/windows/ChatWindow.server.tsx +0 -387
- package/eventcatalog/src/enterprise/eventcatalog-chat/pages/api/chat.ts +0 -59
- package/eventcatalog/src/enterprise/eventcatalog-chat/pages/chat/index.astro +0 -104
- package/eventcatalog/src/enterprise/eventcatalog-chat/providers/ai-provider.ts +0 -140
- package/eventcatalog/src/enterprise/eventcatalog-chat/providers/anthropic.ts +0 -28
- package/eventcatalog/src/enterprise/eventcatalog-chat/providers/google.ts +0 -41
- package/eventcatalog/src/enterprise/eventcatalog-chat/providers/index.ts +0 -26
- package/eventcatalog/src/enterprise/eventcatalog-chat/providers/openai.ts +0 -61
- package/eventcatalog/src/enterprise/eventcatalog-chat/utils/chat-prompts.ts +0 -50
- package/eventcatalog/src/pages/auth/login.astro +0 -280
- package/eventcatalog/src/pages/chat/feature.astro +0 -179
- package/eventcatalog/src/pages/chat/index.astro +0 -10
- package/eventcatalog/src/pages/docs/_default-docs.mdx +0 -25
- package/eventcatalog/src/pages/docs/index.astro +0 -33
- package/eventcatalog/src/pages/nav-index.json.ts +0 -30
- /package/eventcatalog/src/{pages → enterprise}/auth/error.astro +0 -0
- /package/eventcatalog/src/{middleware-auth.ts → enterprise/auth/middleware/middleware-auth.ts} +0 -0
- /package/eventcatalog/src/{middleware.ts → enterprise/auth/middleware/middleware.ts} +0 -0
- /package/eventcatalog/src/{pages/unauthorized/index.astro → enterprise/auth/unauthorized.astro} +0 -0
- /package/eventcatalog/src/{pages → enterprise}/plans/index.astro +0 -0
- /package/eventcatalog/src/{components/SideNav/NestedSideBar → stores/sidebar-store}/builders/flow.ts +0 -0
- /package/eventcatalog/src/{components/SideNav/NestedSideBar/sidebar-builder.ts → stores/sidebar-store/state.ts} +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
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
|
+
let extendedTools: any;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const providerConfiguration = await import(/* @vite-ignore */ join(catalogDirectory, 'eventcatalog.chat.js'));
|
|
28
|
+
model = await providerConfiguration.default();
|
|
29
|
+
modelConfiguration = providerConfiguration.configuration || defaultConfiguration;
|
|
30
|
+
hasChatConfiguration = true;
|
|
31
|
+
extendedTools = providerConfiguration.tools || {};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error('[Chat] Error loading chat configuration', error);
|
|
34
|
+
hasChatConfiguration = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Built-in tools metadata for client visibility
|
|
38
|
+
const builtInToolsMetadata = [
|
|
39
|
+
{
|
|
40
|
+
name: 'getResources',
|
|
41
|
+
description: 'Get events, services, commands, queries, flows, domains, channels, entities from EventCatalog',
|
|
42
|
+
},
|
|
43
|
+
{ name: 'getResource', description: 'Get a specific resource by its id and version' },
|
|
44
|
+
{ name: 'getProducersAndConsumersFromSchema', description: 'Get the producers and consumers for a schema' },
|
|
45
|
+
{ name: 'getMessagesProducedOrConsumedByResource', description: 'Get messages produced or consumed by a resource' },
|
|
46
|
+
{ name: 'getProducerAndConsumerForMessage', description: 'Get the producers and consumers for a message' },
|
|
47
|
+
{ name: 'getConsumersOfMessage', description: 'Get the consumers for a message' },
|
|
48
|
+
{ name: 'getSchemaForResource', description: 'Get the schema or specifications (OpenAPI, AsyncAPI, GraphQL) for a resource' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
// Get extended tools metadata from user configuration
|
|
52
|
+
const getExtendedToolsMetadata = () => {
|
|
53
|
+
if (!extendedTools || typeof extendedTools !== 'object') return [];
|
|
54
|
+
return Object.entries(extendedTools).map(([name, toolConfig]: [string, any]) => ({
|
|
55
|
+
name,
|
|
56
|
+
description: toolConfig?.description || 'Custom tool',
|
|
57
|
+
isCustom: true,
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getBaseSystemPrompt = (
|
|
62
|
+
referrer: string
|
|
63
|
+
) => `You are an expert in software architecture and domain-driven design, specializing in the open source tool EventCatalog.
|
|
64
|
+
|
|
65
|
+
You assist developers, architects, and business stakeholders who need information about their software architecture catalog.
|
|
66
|
+
|
|
67
|
+
There are many different resource types in EventCatalog, including:
|
|
68
|
+
- Events (collection name 'events') (asynchronous messages that notify about something that has happened)
|
|
69
|
+
- example docs url: /docs/events/MyEvent/1.0.0
|
|
70
|
+
- Commands (collection name 'commands') (requests to perform an action)
|
|
71
|
+
- example docs url: /docs/commands/MyCommand/1.0.0
|
|
72
|
+
- Queries (collection name 'queries') (requests for information)
|
|
73
|
+
- example docs url: /docs/queries/MyQuery/1.0.0
|
|
74
|
+
- Services (collection name 'services') (bounded contexts or applications that produce/consume events)
|
|
75
|
+
- example docs url: /docs/services/MyService/1.0.0
|
|
76
|
+
- Domains (collection name 'domains') (business capabilities or functional areas)
|
|
77
|
+
- example docs url: /docs/domains/MyDomain/1.0.0
|
|
78
|
+
- Flows (collection name 'flows') (state machines)
|
|
79
|
+
- example docs url: /docs/flows/MyFlow/1.0.0
|
|
80
|
+
- Channels (collection name 'channels') (communication channels)
|
|
81
|
+
- example docs url: /docs/channels/MyChannel/1.0.0
|
|
82
|
+
- Entities (collection name 'entities') (data objects)
|
|
83
|
+
- example docs url: /docs/entities/MyEntity/1.0.0
|
|
84
|
+
- Containers (collection name 'containers') (at the moment these are data stores (databases))
|
|
85
|
+
- example docs url: /docs/containers/MyContainer/1.0.0
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
89
|
+
At point the referer url (${referrer}) will be the URL of the page the user is on, you should use this to help you answer the question,
|
|
90
|
+
You may be able to get the resource from the URL
|
|
91
|
+
- Example if the url is like /docs|visualiser|architecture/{collection}/{id}/{version}
|
|
92
|
+
- (e.g /docs/events/MyEvent/1.0.0) in this case the id is MyEvent and the version is 1.0.0 and collection is events.
|
|
93
|
+
- (e.g /visualiser/domains/MyDomain/1.0.0) in this case the id is MyDomain and the version is 1.0.0 and collection is domains.
|
|
94
|
+
- (e.g /architecture/services/MyService/1.0.0) in this case the id is MyService and the version is 1.0.0 and collection is services.
|
|
95
|
+
|
|
96
|
+
The referer URL is: ${referrer}
|
|
97
|
+
|
|
98
|
+
Sometimes the user will be on the specification page (openapi, asyncapi, graphql) for a resource too
|
|
99
|
+
- /docs/services/OrdersService/0.0.3/asyncapi/order-service-asyncapi -> id: OrdersService, version: 0.0.3, collection: services, schema (specification): asyncapi
|
|
100
|
+
- /docs/services/OrdersService/0.0.3/spec/openapi-v2 -> id: OrdersService, version: 0.0.3, collection: services, schema (specification): openapi
|
|
101
|
+
|
|
102
|
+
Your primary goal is to help users understand their software architecture through accurate documentation interpretation.
|
|
103
|
+
|
|
104
|
+
Use the tools provided to get the context you need to an answer the question.
|
|
105
|
+
|
|
106
|
+
When responding:
|
|
107
|
+
1. Explain connections between resources when relevant.
|
|
108
|
+
2. Use appropriate technical terminology.
|
|
109
|
+
3. Use clear formatting with headings and bullet points when helpful.
|
|
110
|
+
4. State clearly when information is missing rather than making assumptions.
|
|
111
|
+
5. Don't provide code examples unless specifically requested.
|
|
112
|
+
6. When you refer to a resource in EventCatalog, try and create a link to the resource in the response
|
|
113
|
+
- 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)
|
|
114
|
+
- NEVER return "latest" in the markdown link, always use the specific version
|
|
115
|
+
- The link options are:
|
|
116
|
+
- If you want to get the documentation for a resource use the /docs/ prefix (e.g /docs/{collection}/{id}/{version})
|
|
117
|
+
- If you want to let the user know they can visualize a resource use the /visualiser/ prefix (e.g /visualiser/{collection}/{id}/{version})
|
|
118
|
+
- 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})
|
|
119
|
+
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
|
|
120
|
+
|
|
121
|
+
If you have additional context, use it to answer the question.`;
|
|
122
|
+
|
|
123
|
+
interface Message {
|
|
124
|
+
content: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const GET = async ({ request }: APIContext<{ question: string; messages: Message[]; additionalContext?: string }>) => {
|
|
128
|
+
if (!isEventCatalogScaleEnabled()) {
|
|
129
|
+
return new Response(JSON.stringify({ error: 'Chat is not enabled' }), {
|
|
130
|
+
status: 403,
|
|
131
|
+
headers: { 'Content-Type': 'application/json' },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!hasChatConfiguration) {
|
|
136
|
+
return new Response(JSON.stringify({ error: 'No chat configuration found' }), {
|
|
137
|
+
status: 404,
|
|
138
|
+
headers: { 'Content-Type': 'application/json' },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Return available tools metadata
|
|
143
|
+
const tools = [...builtInToolsMetadata, ...getExtendedToolsMetadata()];
|
|
144
|
+
return new Response(JSON.stringify({ tools }), {
|
|
145
|
+
status: 200,
|
|
146
|
+
headers: { 'Content-Type': 'application/json' },
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const POST = async ({ request }: APIContext<{ question: string; messages: Message[]; additionalContext?: string }>) => {
|
|
151
|
+
const { messages }: { messages: UIMessage[] } = await request.json();
|
|
152
|
+
|
|
153
|
+
if (!isEventCatalogScaleEnabled()) {
|
|
154
|
+
return new Response(JSON.stringify({ error: 'Chat is not enabled, please upgrade to the scale plan to use this feature' }), {
|
|
155
|
+
status: 403,
|
|
156
|
+
headers: { 'Content-Type': 'application/json' },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!hasChatConfiguration) {
|
|
161
|
+
return new Response(JSON.stringify({ error: 'No chat configuration found' }), {
|
|
162
|
+
status: 404,
|
|
163
|
+
headers: { 'Content-Type': 'application/json' },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Get the URL of the request
|
|
168
|
+
const referrer = request.headers.get('referer');
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const result = await streamText({
|
|
172
|
+
model,
|
|
173
|
+
system: getBaseSystemPrompt(referrer ?? ''),
|
|
174
|
+
messages: convertToModelMessages(messages) as ModelMessage[],
|
|
175
|
+
temperature: modelConfiguration?.temperature ?? 0.7,
|
|
176
|
+
stopWhen: stepCountIs(5),
|
|
177
|
+
// maxTokens: 4000, // Increased to handle large tool results
|
|
178
|
+
onError: (error) => {
|
|
179
|
+
console.error('[Chat] On error', error);
|
|
180
|
+
},
|
|
181
|
+
// maxOutputTokens: 40000,
|
|
182
|
+
// tools: tools,
|
|
183
|
+
tools: {
|
|
184
|
+
getResources: tool({
|
|
185
|
+
description:
|
|
186
|
+
'Use this tool to get events, services, commands, queries, flows, domains, channels, entities from EventCatalog',
|
|
187
|
+
inputSchema: z.object({
|
|
188
|
+
collection: z
|
|
189
|
+
.enum(['events', 'services', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities', 'containers'])
|
|
190
|
+
.describe('The collection to get the events from'),
|
|
191
|
+
}),
|
|
192
|
+
execute: async ({ collection }) => {
|
|
193
|
+
const resources = await getCollection(collection as any);
|
|
194
|
+
return resources.map((resource: any) => ({
|
|
195
|
+
id: resource.data.id,
|
|
196
|
+
version: resource.data.version,
|
|
197
|
+
name: resource.data.name,
|
|
198
|
+
}));
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
getResource: tool({
|
|
202
|
+
description: 'Use this tool to get a specific resource from EventCatalog by its id and version',
|
|
203
|
+
inputSchema: z.object({
|
|
204
|
+
collection: z
|
|
205
|
+
.enum(['events', 'services', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities', 'containers'])
|
|
206
|
+
.describe('The collection to get the events from'),
|
|
207
|
+
id: z.string().describe('The id of the resource to get'),
|
|
208
|
+
version: z.string().describe('The version of the resource to get'),
|
|
209
|
+
}),
|
|
210
|
+
execute: async ({ collection, id, version }) => {
|
|
211
|
+
const resource = await getEntry(collection as any, `${id}-${version}`);
|
|
212
|
+
return resource;
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
getProducersAndConsumersFromSchema: tool({
|
|
216
|
+
description: 'Use this tool to get the producers and consumers for a schema by its id and version',
|
|
217
|
+
inputSchema: z.object({
|
|
218
|
+
collection: z
|
|
219
|
+
.enum(['events', 'commands', 'queries'])
|
|
220
|
+
.describe('The collection to get the producers and consumers from'),
|
|
221
|
+
id: z.string().describe('The id of the message to get the producers and consumers for'),
|
|
222
|
+
version: z.string().describe('The version of the message to get the producers and consumers for'),
|
|
223
|
+
}),
|
|
224
|
+
execute: async ({ collection, id, version }) => {
|
|
225
|
+
const resource = await getEntry(collection as any, `${id}-${version}`);
|
|
226
|
+
const producers = resource.data.producers || [];
|
|
227
|
+
const consumers = resource.data.consumers || [];
|
|
228
|
+
return {
|
|
229
|
+
producers,
|
|
230
|
+
consumers,
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
}),
|
|
234
|
+
getMessagesProducedOrConsumedByResource: tool({
|
|
235
|
+
description:
|
|
236
|
+
'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',
|
|
237
|
+
inputSchema: z.object({
|
|
238
|
+
resourceId: z.string().describe('The id of the resource to get the messages produced or consumed for'),
|
|
239
|
+
resourceVersion: z.string().describe('The version of the resource to get the messages produced or consumed for'),
|
|
240
|
+
resourceCollection: z
|
|
241
|
+
.enum(['services', 'events', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
|
|
242
|
+
.describe('The collection of the resource to get the messages produced or consumed for')
|
|
243
|
+
.default('services'),
|
|
244
|
+
}),
|
|
245
|
+
execute: async ({ resourceId, resourceVersion, resourceCollection }) => {
|
|
246
|
+
const resource = await getEntry(resourceCollection as any, `${resourceId}-${resourceVersion}`);
|
|
247
|
+
if (!resource) {
|
|
248
|
+
return {
|
|
249
|
+
error: `Resource not found with id ${resourceId} and version ${resourceVersion} and collection ${resourceCollection}`,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return resource;
|
|
253
|
+
},
|
|
254
|
+
}),
|
|
255
|
+
getProducerAndConsumerForMessage: tool({
|
|
256
|
+
description: 'Use this tool to get the producers and consumers for a message by its id and version',
|
|
257
|
+
inputSchema: z.object({
|
|
258
|
+
messageId: z.string().describe('The id of the message to get the producers and consumers for'),
|
|
259
|
+
messageVersion: z.string().describe('The version of the message to get the producers and consumers for'),
|
|
260
|
+
messageCollection: z
|
|
261
|
+
.enum(['events', 'commands', 'queries'])
|
|
262
|
+
.describe('The collection of the message to get the producers and consumers for')
|
|
263
|
+
.default('events'),
|
|
264
|
+
}),
|
|
265
|
+
execute: async ({ messageId, messageVersion, messageCollection }) => {
|
|
266
|
+
const services = await getCollection('services');
|
|
267
|
+
const message = await getEntry(messageCollection as any, `${messageId}-${messageVersion}`);
|
|
268
|
+
const consumers = await getProducersOfMessage(services, message as any);
|
|
269
|
+
return consumers;
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
getConsumersOfMessage: tool({
|
|
273
|
+
description: 'Use this tool to get the consumers for a message by its id and version',
|
|
274
|
+
inputSchema: z.object({
|
|
275
|
+
messageId: z.string().describe('The id of the message to get the consumers for'),
|
|
276
|
+
messageVersion: z.string().describe('The version of the message to get the consumers for'),
|
|
277
|
+
messageCollection: z
|
|
278
|
+
.enum(['events', 'commands', 'queries'])
|
|
279
|
+
.describe('The collection of the message to get the consumers for')
|
|
280
|
+
.default('events'),
|
|
281
|
+
}),
|
|
282
|
+
execute: async ({ messageId, messageVersion, messageCollection }) => {
|
|
283
|
+
const services = await getCollection('services');
|
|
284
|
+
const message = await getEntry(messageCollection as any, `${messageId}-${messageVersion}`);
|
|
285
|
+
const consumers = await getConsumersOfMessage(services, message as any);
|
|
286
|
+
return consumers;
|
|
287
|
+
},
|
|
288
|
+
}),
|
|
289
|
+
getSchemaForResource: tool({
|
|
290
|
+
description:
|
|
291
|
+
'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',
|
|
292
|
+
inputSchema: z.object({
|
|
293
|
+
resourceId: z.string().describe('The id of the resource to get the schema for'),
|
|
294
|
+
resourceVersion: z.string().describe('The version of the resource to get the schema for'),
|
|
295
|
+
resourceCollection: z
|
|
296
|
+
.enum(['services', 'events', 'commands', 'queries', 'flows', 'domains', 'channels', 'entities'])
|
|
297
|
+
.describe('The collection of the resource to get the schema for')
|
|
298
|
+
.default('services'),
|
|
299
|
+
}),
|
|
300
|
+
execute: async ({ resourceId, resourceVersion, resourceCollection }) => {
|
|
301
|
+
const resource = await getEntry(resourceCollection as any, `${resourceId}-${resourceVersion}`);
|
|
302
|
+
|
|
303
|
+
if (!resource) {
|
|
304
|
+
return {
|
|
305
|
+
error: `Resource not found with id ${resourceId} and version ${resourceVersion} and collection ${resourceCollection}`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const schema = await getSchemasFromResource(resource);
|
|
310
|
+
|
|
311
|
+
// If we have any schemas back then read them and return them
|
|
312
|
+
if (schema.length > 0) {
|
|
313
|
+
return schema.map((schemaItem) => ({
|
|
314
|
+
url: schemaItem.url,
|
|
315
|
+
format: schemaItem.format,
|
|
316
|
+
code: fs.readFileSync(schemaItem.url, 'utf-8'),
|
|
317
|
+
}));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return [];
|
|
321
|
+
},
|
|
322
|
+
}),
|
|
323
|
+
...extendedTools,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
return result.toUIMessageStreamResponse({
|
|
327
|
+
headers: {
|
|
328
|
+
'Content-Type': 'text/event-stream',
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
} catch (err: any) {
|
|
332
|
+
console.error('[Chat] Error during streaming:', err);
|
|
333
|
+
|
|
334
|
+
// Extract a user-friendly error message
|
|
335
|
+
let errorMessage = 'An unexpected error occurred while processing your request.';
|
|
336
|
+
|
|
337
|
+
if (err?.message) {
|
|
338
|
+
// Check for common error patterns and provide friendlier messages
|
|
339
|
+
if (err.message.includes('API key') || err.message.includes('authentication') || err.message.includes('401')) {
|
|
340
|
+
errorMessage = 'Authentication error: Please check your API key configuration.';
|
|
341
|
+
} else if (err.message.includes('rate limit') || err.message.includes('429')) {
|
|
342
|
+
errorMessage = 'Rate limit exceeded. Please wait a moment and try again.';
|
|
343
|
+
} else if (err.message.includes('timeout') || err.message.includes('ETIMEDOUT')) {
|
|
344
|
+
errorMessage = 'Request timed out. Please try again.';
|
|
345
|
+
} else if (err.message.includes('model') || err.message.includes('not found')) {
|
|
346
|
+
errorMessage = 'Model configuration error: ' + err.message;
|
|
347
|
+
} else {
|
|
348
|
+
// Use the original message if it's not too technical
|
|
349
|
+
errorMessage = err.message.length < 200 ? err.message : 'An error occurred while processing your request.';
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return new Response(JSON.stringify({ error: errorMessage }), {
|
|
354
|
+
status: 500,
|
|
355
|
+
headers: { 'Content-Type': 'application/json' },
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export const prerender = false;
|