@codemation/next-host 0.0.1
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 +25 -0
- package/app/(shell)/credentials/page.tsx +5 -0
- package/app/(shell)/dashboard/page.tsx +14 -0
- package/app/(shell)/layout.tsx +11 -0
- package/app/(shell)/page.tsx +5 -0
- package/app/(shell)/users/page.tsx +5 -0
- package/app/(shell)/workflows/[workflowId]/page.tsx +19 -0
- package/app/(shell)/workflows/page.tsx +5 -0
- package/app/api/[[...path]]/route.ts +40 -0
- package/app/api/auth/[...nextauth]/route.ts +3 -0
- package/app/globals.css +997 -0
- package/app/invite/[token]/page.tsx +10 -0
- package/app/layout.tsx +65 -0
- package/app/login/layout.tsx +25 -0
- package/app/login/page.tsx +22 -0
- package/components.json +21 -0
- package/docs/FORMS.md +46 -0
- package/docs/TAILWIND_SHADCN_MIGRATION.md +89 -0
- package/eslint.config.mjs +56 -0
- package/middleware.ts +29 -0
- package/next-env.d.ts +6 -0
- package/next.config.ts +34 -0
- package/package.json +76 -0
- package/postcss.config.mjs +7 -0
- package/public/canvas-icons/builtin/openai.svg +5 -0
- package/src/api/CodemationApiClient.ts +107 -0
- package/src/api/CodemationApiHttpError.ts +17 -0
- package/src/auth/CodemationNextAuthConfigResolver.ts +14 -0
- package/src/auth/CodemationNextAuthOAuthProviderDescriptorMapper.ts +30 -0
- package/src/auth/CodemationNextAuthOAuthProviderSnapshotResolver.ts +17 -0
- package/src/auth/CodemationNextAuthProviderCatalog.ts +107 -0
- package/src/auth/codemationEdgeAuth.ts +25 -0
- package/src/auth/codemationNextAuth.ts +32 -0
- package/src/components/Codemation.tsx +6 -0
- package/src/components/CodemationDataTable.tsx +37 -0
- package/src/components/CodemationDialog.tsx +137 -0
- package/src/components/CodemationFormattedDateTime.tsx +46 -0
- package/src/components/GoogleColorGIcon.tsx +39 -0
- package/src/components/OauthProviderIcon.tsx +33 -0
- package/src/components/PasswordStrengthMeter.tsx +59 -0
- package/src/components/forms/index.ts +28 -0
- package/src/components/json/JsonMonacoEditor.tsx +75 -0
- package/src/components/oauthProviderIconData.ts +17 -0
- package/src/components/ui/alert.tsx +56 -0
- package/src/components/ui/badge.tsx +40 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +70 -0
- package/src/components/ui/collapsible.tsx +26 -0
- package/src/components/ui/dialog.tsx +137 -0
- package/src/components/ui/dropdown-menu.tsx +238 -0
- package/src/components/ui/form.tsx +147 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/scroll-area.tsx +47 -0
- package/src/components/ui/select.tsx +169 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/switch.tsx +28 -0
- package/src/components/ui/table.tsx +72 -0
- package/src/components/ui/tabs.tsx +76 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/toggle.tsx +41 -0
- package/src/features/credentials/components/CredentialConfirmDialog.tsx +58 -0
- package/src/features/credentials/components/CredentialDialog.tsx +252 -0
- package/src/features/credentials/components/CredentialDialogFeedback.tsx +36 -0
- package/src/features/credentials/components/CredentialDialogFieldRows.tsx +257 -0
- package/src/features/credentials/components/CredentialDialogFormSections.tsx +230 -0
- package/src/features/credentials/components/CredentialEnvFieldStatusRow.tsx +64 -0
- package/src/features/credentials/components/CredentialFieldCopyButton.tsx +48 -0
- package/src/features/credentials/components/CredentialsScreenHealthBadge.tsx +21 -0
- package/src/features/credentials/components/CredentialsScreenInstancesTable.tsx +108 -0
- package/src/features/credentials/components/CredentialsScreenTestFailureAlert.tsx +33 -0
- package/src/features/credentials/hooks/useCredentialCreateDialog.ts +33 -0
- package/src/features/credentials/hooks/useCredentialDialogSession.ts +616 -0
- package/src/features/credentials/hooks/useCredentialsScreen.ts +213 -0
- package/src/features/credentials/lib/credentialFieldHelpers.ts +35 -0
- package/src/features/credentials/lib/credentialFormTypes.ts +1 -0
- package/src/features/credentials/lib/credentialInstanceTestPayloadParser.ts +10 -0
- package/src/features/credentials/screens/CredentialsScreen.tsx +187 -0
- package/src/features/invite/screens/InviteAcceptScreen.tsx +190 -0
- package/src/features/users/components/UsersInviteDialog.tsx +121 -0
- package/src/features/users/components/UsersRegenerateDialog.tsx +81 -0
- package/src/features/users/components/UsersScreenUserStatusBadge.tsx +19 -0
- package/src/features/users/schemas/usersInviteFormSchema.ts +7 -0
- package/src/features/users/screens/UsersScreen.tsx +240 -0
- package/src/features/workflows/components/WorkflowListFolderSection.tsx +91 -0
- package/src/features/workflows/components/WorkflowListItemCard.tsx +67 -0
- package/src/features/workflows/components/WorkflowListRoot.tsx +39 -0
- package/src/features/workflows/components/WorkflowsListTree.tsx +28 -0
- package/src/features/workflows/components/canvas/CanvasNodeChromeTooltip.tsx +96 -0
- package/src/features/workflows/components/canvas/CanvasNodeIconSlot.tsx +25 -0
- package/src/features/workflows/components/canvas/VisibleNodeStatusResolver.tsx +84 -0
- package/src/features/workflows/components/canvas/WorkflowCanvas.tsx +248 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNode.tsx +182 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAccents.tsx +73 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAgentBottomSourceHandles.tsx +43 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAgentLabels.tsx +47 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeCard.tsx +202 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeHandles.tsx +77 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeLabelBelow.tsx +51 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeMainGlyph.tsx +64 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeToolbar.tsx +95 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasLoadingPlaceholder.tsx +69 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasNodeIcon.tsx +102 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasSimpleIconGlyph.tsx +21 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasStraightCountEdge.tsx +33 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasStructureSignature.tsx +7 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasSymmetricForkEdge.tsx +32 -0
- package/src/features/workflows/components/canvas/WorkflowCanvasToolbarIconButton.tsx +95 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasBuiltinIconRegistry.ts +26 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasEdgeCountResolver.ts +51 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasEdgeStyleResolver.ts +35 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasLabelLayoutEstimator.ts +42 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasOverlapResolver.ts +78 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasPortOrderResolver.ts +25 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasRoundedOrthogonalPathPlanner.ts +56 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasSiIconRegistry.ts +18 -0
- package/src/features/workflows/components/canvas/lib/WorkflowCanvasSymmetricForkPathPlanner.ts +43 -0
- package/src/features/workflows/components/canvas/lib/layoutWorkflow.ts +315 -0
- package/src/features/workflows/components/canvas/lib/workflowCanvasEdgeGeometry.ts +3 -0
- package/src/features/workflows/components/canvas/lib/workflowCanvasEmbeddedStyles.ts +62 -0
- package/src/features/workflows/components/canvas/lib/workflowCanvasFlowTypes.ts +10 -0
- package/src/features/workflows/components/canvas/lib/workflowCanvasNodeData.ts +41 -0
- package/src/features/workflows/components/canvas/lib/workflowCanvasNodeGeometry.ts +99 -0
- package/src/features/workflows/components/canvas/workflowCanvasNodeChrome.tsx +46 -0
- package/src/features/workflows/components/realtime/RealtimeContext.tsx +14 -0
- package/src/features/workflows/components/realtime/WorkflowRealtimeProvider.tsx +15 -0
- package/src/features/workflows/components/workflowDetail/NodeCredentialBindingRow.tsx +209 -0
- package/src/features/workflows/components/workflowDetail/NodeCredentialBindingsSection.tsx +227 -0
- package/src/features/workflows/components/workflowDetail/NodePropertiesConfigSection.tsx +51 -0
- package/src/features/workflows/components/workflowDetail/NodePropertiesPanelHeader.tsx +50 -0
- package/src/features/workflows/components/workflowDetail/NodePropertiesSlidePanel.tsx +134 -0
- package/src/features/workflows/components/workflowDetail/WorkflowActivationErrorDialog.tsx +71 -0
- package/src/features/workflows/components/workflowDetail/WorkflowActivationHeaderControl.tsx +64 -0
- package/src/features/workflows/components/workflowDetail/WorkflowDetailIcons.tsx +52 -0
- package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspector.tsx +110 -0
- package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorDetailBody.tsx +213 -0
- package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorPanes.tsx +239 -0
- package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorSidebarResizer.tsx +31 -0
- package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorTreePanel.tsx +133 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorAttachmentGroupingPresenter.tsx +31 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorAttachmentList.tsx +118 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorBinaryView.tsx +15 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorErrorView.tsx +107 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorJsonView.tsx +114 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyTreePresenter.tsx +132 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyTreeViewRenderer.tsx +147 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyView.tsx +65 -0
- package/src/features/workflows/components/workflowDetail/WorkflowInspectorViews.tsx +5 -0
- package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorBinaryAttachmentRow.tsx +74 -0
- package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorBinaryUploadRow.tsx +69 -0
- package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorDialog.tsx +254 -0
- package/src/features/workflows/components/workflowDetail/WorkflowRunsList.tsx +89 -0
- package/src/features/workflows/components/workflowDetail/WorkflowRunsSidebar.tsx +50 -0
- package/src/features/workflows/hooks/canvas/useWorkflowCanvasVisibleNodeStatuses.ts +14 -0
- package/src/features/workflows/hooks/realtime/realtime.tsx +271 -0
- package/src/features/workflows/hooks/realtime/runQueryPolling.ts +34 -0
- package/src/features/workflows/hooks/realtime/useWorkflowRealtimeInfrastructure.ts +541 -0
- package/src/features/workflows/hooks/realtime/useWorkflowRealtimeShowDisconnectedBadge.ts +9 -0
- package/src/features/workflows/hooks/workflowDetail/useWorkflowDetailController.tsx +1300 -0
- package/src/features/workflows/lib/realtime/realtimeApi.ts +78 -0
- package/src/features/workflows/lib/realtime/realtimeClientBridge.ts +52 -0
- package/src/features/workflows/lib/realtime/realtimeDomainTypes.ts +191 -0
- package/src/features/workflows/lib/realtime/realtimeQueryKeys.ts +15 -0
- package/src/features/workflows/lib/realtime/realtimeRunMutations.ts +167 -0
- package/src/features/workflows/lib/realtime/workflowTypes.ts +5 -0
- package/src/features/workflows/lib/workflowDetail/PersistedWorkflowSnapshotMapper.ts +205 -0
- package/src/features/workflows/lib/workflowDetail/WorkflowActivationHttpErrorFormat.ts +32 -0
- package/src/features/workflows/lib/workflowDetail/WorkflowDetailPresenter.ts +1017 -0
- package/src/features/workflows/lib/workflowDetail/WorkflowDetailUrlCodec.ts +70 -0
- package/src/features/workflows/lib/workflowDetail/workflowDetailTypes.ts +152 -0
- package/src/features/workflows/lib/workflowDetailTreeStyles.ts +65 -0
- package/src/features/workflows/screens/WorkflowDetailScreen.tsx +236 -0
- package/src/features/workflows/screens/WorkflowDetailScreenInspectorPanel.tsx +55 -0
- package/src/features/workflows/screens/WorkflowsList.tsx +35 -0
- package/src/features/workflows/screens/WorkflowsScreen.tsx +31 -0
- package/src/index.ts +1 -0
- package/src/lib/utils.ts +6 -0
- package/src/middleware/CodemationNextHostMiddlewarePathRules.ts +31 -0
- package/src/providers/CodemationSessionProvider.tsx +23 -0
- package/src/providers/Providers.tsx +36 -0
- package/src/providers/RealtimeBoundary.tsx +17 -0
- package/src/providers/WhitelabelProvider.tsx +22 -0
- package/src/server/CodemationAuthPrismaClient.ts +21 -0
- package/src/server/CodemationNextHost.ts +379 -0
- package/src/shell/AppLayout.tsx +141 -0
- package/src/shell/AppLayoutNavItems.tsx +129 -0
- package/src/shell/AppLayoutPageHeader.tsx +79 -0
- package/src/shell/AppLayoutSidebarBrand.tsx +33 -0
- package/src/shell/AppMainContent.tsx +17 -0
- package/src/shell/AppShellHeaderActions.tsx +12 -0
- package/src/shell/AppShellHeaderActionsAuthenticated.tsx +51 -0
- package/src/shell/CodemationNextClientShell.tsx +17 -0
- package/src/shell/CredentialsSignInRedirectResolver.ts +21 -0
- package/src/shell/LoginPageClient.tsx +231 -0
- package/src/shell/WorkflowDetailChromeContext.tsx +42 -0
- package/src/shell/WorkflowFolderTreeBuilder.ts +62 -0
- package/src/shell/WorkflowFolderUi.ts +42 -0
- package/src/shell/WorkflowSidebarNavFolder.tsx +112 -0
- package/src/shell/WorkflowSidebarNavTree.tsx +68 -0
- package/src/shell/appLayoutPageTitle.ts +16 -0
- package/src/shell/appLayoutSidebarIcons.tsx +108 -0
- package/src/whitelabel/CodemationWhitelabelSnapshot.ts +4 -0
- package/src/whitelabel/CodemationWhitelabelSnapshotFactory.ts +18 -0
- package/tsconfig.json +40 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { ConnectionNodeIdFactory } from "@codemation/core/browser";
|
|
2
|
+
import { WorkflowPolicyUiPresentationFactory } from "@codemation/host-src/application/mapping/WorkflowPolicyUiPresentationFactory";
|
|
3
|
+
import type { PersistedWorkflowSnapshot, WorkflowDto } from "../../hooks/realtime/realtime";
|
|
4
|
+
import type { WorkflowNodeDto } from "../realtime/workflowTypes";
|
|
5
|
+
|
|
6
|
+
export class PersistedWorkflowSnapshotMapper {
|
|
7
|
+
constructor(private readonly policyUi = new WorkflowPolicyUiPresentationFactory()) {}
|
|
8
|
+
|
|
9
|
+
map(snapshot: PersistedWorkflowSnapshot): WorkflowDto {
|
|
10
|
+
const nodesById = new Map(snapshot.nodes.map((node) => [node.id, node]));
|
|
11
|
+
const connectionChildMeta = this.buildConnectionChildMeta(snapshot);
|
|
12
|
+
const nodes: WorkflowNodeDto[] = [];
|
|
13
|
+
for (const node of snapshot.nodes) {
|
|
14
|
+
if (connectionChildMeta.has(node.id)) {
|
|
15
|
+
nodes.push(this.toConnectionChildDto(node, connectionChildMeta.get(node.id)!));
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
nodes.push(...this.toTopLevelNodes(node, snapshot, nodesById));
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
id: snapshot.id,
|
|
22
|
+
name: snapshot.name,
|
|
23
|
+
active: false,
|
|
24
|
+
hasWorkflowErrorHandler: snapshot.workflowErrorHandlerConfigured,
|
|
25
|
+
nodes,
|
|
26
|
+
edges: [...snapshot.edges, ...this.toAttachmentEdges(nodes)],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private buildConnectionChildMeta(
|
|
31
|
+
snapshot: PersistedWorkflowSnapshot,
|
|
32
|
+
): ReadonlyMap<string, Readonly<{ parentNodeId: string; connectionName: string }>> {
|
|
33
|
+
const map = new Map<string, Readonly<{ parentNodeId: string; connectionName: string }>>();
|
|
34
|
+
for (const c of snapshot.connections ?? []) {
|
|
35
|
+
for (const childId of c.childNodeIds) {
|
|
36
|
+
map.set(childId, { parentNodeId: c.parentNodeId, connectionName: c.connectionName });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private agentHasConnectionChildren(snapshot: PersistedWorkflowSnapshot, agentNodeId: string): boolean {
|
|
43
|
+
return (snapshot.connections ?? []).some((c) => c.parentNodeId === agentNodeId && c.childNodeIds.length > 0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private allConnectionChildrenMaterialized(
|
|
47
|
+
snapshot: PersistedWorkflowSnapshot,
|
|
48
|
+
agentNodeId: string,
|
|
49
|
+
nodesById: ReadonlyMap<string, PersistedWorkflowSnapshot["nodes"][number]>,
|
|
50
|
+
): boolean {
|
|
51
|
+
const groups = (snapshot.connections ?? []).filter((c) => c.parentNodeId === agentNodeId);
|
|
52
|
+
if (groups.length === 0) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
for (const c of groups) {
|
|
56
|
+
for (const childId of c.childNodeIds) {
|
|
57
|
+
if (!nodesById.has(childId)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private toTopLevelNodes(
|
|
66
|
+
node: PersistedWorkflowSnapshot["nodes"][number],
|
|
67
|
+
snapshot: PersistedWorkflowSnapshot,
|
|
68
|
+
nodesById: ReadonlyMap<string, PersistedWorkflowSnapshot["nodes"][number]>,
|
|
69
|
+
): ReadonlyArray<WorkflowNodeDto> {
|
|
70
|
+
const workflowNode: WorkflowNodeDto = {
|
|
71
|
+
id: node.id,
|
|
72
|
+
kind: node.kind,
|
|
73
|
+
name: node.name,
|
|
74
|
+
type: node.configTokenName ?? node.tokenName ?? node.configTokenId,
|
|
75
|
+
role: this.isAgentConfig(node.config) ? "agent" : "workflowNode",
|
|
76
|
+
icon: this.readNodeIcon(node.config),
|
|
77
|
+
retryPolicySummary: this.policyUi.snapshotNodeRetrySummary(node.config),
|
|
78
|
+
hasNodeErrorHandler: this.policyUi.snapshotNodeHasErrorHandler(node.config),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (!this.isAgentConfig(node.config)) {
|
|
82
|
+
return [workflowNode];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.allConnectionChildrenMaterialized(snapshot, node.id, nodesById)) {
|
|
86
|
+
return [workflowNode];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.agentHasConnectionChildren(snapshot, node.id)) {
|
|
90
|
+
return [workflowNode, ...this.toAttachmentNodes(node)];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [workflowNode, ...this.toAttachmentNodes(node)];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private toConnectionChildDto(
|
|
97
|
+
node: PersistedWorkflowSnapshot["nodes"][number],
|
|
98
|
+
meta: Readonly<{ parentNodeId: string; connectionName: string }>,
|
|
99
|
+
): WorkflowNodeDto {
|
|
100
|
+
const role = meta.connectionName === "llm" ? "languageModel" : "tool";
|
|
101
|
+
return {
|
|
102
|
+
id: node.id,
|
|
103
|
+
kind: node.kind,
|
|
104
|
+
name: node.name,
|
|
105
|
+
type: node.configTokenName ?? node.tokenName ?? node.configTokenId,
|
|
106
|
+
role,
|
|
107
|
+
icon: this.readNodeIcon(node.config),
|
|
108
|
+
retryPolicySummary: this.policyUi.snapshotNodeRetrySummary(node.config),
|
|
109
|
+
hasNodeErrorHandler: this.policyUi.snapshotNodeHasErrorHandler(node.config),
|
|
110
|
+
parentNodeId: meta.parentNodeId,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private toAttachmentNodes(node: PersistedWorkflowSnapshot["nodes"][number]): ReadonlyArray<WorkflowNodeDto> {
|
|
115
|
+
const config = this.asRecord(node.config);
|
|
116
|
+
const chatModel = this.asRecord(config.chatModel);
|
|
117
|
+
const languageModelNode = chatModel.name
|
|
118
|
+
? [
|
|
119
|
+
{
|
|
120
|
+
id: ConnectionNodeIdFactory.languageModelConnectionNodeId(node.id),
|
|
121
|
+
kind: "node",
|
|
122
|
+
name: this.readAttachmentLabel(chatModel.presentation, chatModel.name),
|
|
123
|
+
type: chatModel.name,
|
|
124
|
+
role: "languageModel",
|
|
125
|
+
icon: this.readAttachmentIcon(chatModel.presentation),
|
|
126
|
+
parentNodeId: node.id,
|
|
127
|
+
} satisfies WorkflowNodeDto,
|
|
128
|
+
]
|
|
129
|
+
: [];
|
|
130
|
+
const tools = Array.isArray(config.tools) ? config.tools : [];
|
|
131
|
+
const toolNodes = tools.flatMap((tool) => {
|
|
132
|
+
const toolConfig = this.asRecord(tool);
|
|
133
|
+
return toolConfig.name
|
|
134
|
+
? [
|
|
135
|
+
{
|
|
136
|
+
id: ConnectionNodeIdFactory.toolConnectionNodeId(node.id, String(toolConfig.name)),
|
|
137
|
+
kind: "node",
|
|
138
|
+
name: this.readAttachmentLabel(toolConfig.presentation, toolConfig.name),
|
|
139
|
+
type: toolConfig.name,
|
|
140
|
+
role: "tool",
|
|
141
|
+
icon: this.readAttachmentIcon(toolConfig.presentation),
|
|
142
|
+
parentNodeId: node.id,
|
|
143
|
+
} satisfies WorkflowNodeDto,
|
|
144
|
+
]
|
|
145
|
+
: [];
|
|
146
|
+
});
|
|
147
|
+
return [...languageModelNode, ...toolNodes];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private toAttachmentEdges(nodes: ReadonlyArray<WorkflowNodeDto>): WorkflowDto["edges"] {
|
|
151
|
+
return nodes.flatMap((node) => {
|
|
152
|
+
if (!node.parentNodeId) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
return [
|
|
156
|
+
{
|
|
157
|
+
from: { nodeId: node.parentNodeId, output: "main" },
|
|
158
|
+
to: { nodeId: node.id, input: "in" },
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private isAgentConfig(value: unknown): boolean {
|
|
165
|
+
const record = this.asRecord(value);
|
|
166
|
+
return typeof record.systemMessage === "string" && record.chatModel !== undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private readAttachmentLabel(presentation: unknown, fallback: string): string {
|
|
170
|
+
const presentationRecord = this.asRecord(presentation);
|
|
171
|
+
return presentationRecord.label ?? fallback;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private readAttachmentIcon(presentation: unknown): string | undefined {
|
|
175
|
+
return this.asRecord(presentation).icon;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private readNodeIcon(config: unknown): string | undefined {
|
|
179
|
+
const c = this.asRecord(config);
|
|
180
|
+
return typeof c.icon === "string" ? c.icon : undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private asRecord(value: unknown): Readonly<{
|
|
184
|
+
name?: string;
|
|
185
|
+
label?: string;
|
|
186
|
+
icon?: string;
|
|
187
|
+
systemMessage?: string;
|
|
188
|
+
chatModel?: unknown;
|
|
189
|
+
tools?: ReadonlyArray<unknown>;
|
|
190
|
+
presentation?: unknown;
|
|
191
|
+
}> {
|
|
192
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
195
|
+
return value as Readonly<{
|
|
196
|
+
name?: string;
|
|
197
|
+
label?: string;
|
|
198
|
+
icon?: string;
|
|
199
|
+
systemMessage?: string;
|
|
200
|
+
chatModel?: unknown;
|
|
201
|
+
tools?: ReadonlyArray<unknown>;
|
|
202
|
+
presentation?: unknown;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CodemationApiHttpError } from "../../../../api/CodemationApiHttpError";
|
|
2
|
+
|
|
3
|
+
export class WorkflowActivationHttpErrorFormat {
|
|
4
|
+
extractMessages(error: unknown): ReadonlyArray<string> {
|
|
5
|
+
if (error instanceof CodemationApiHttpError) {
|
|
6
|
+
const parsed = this.tryParseJson(error.bodyText);
|
|
7
|
+
if (parsed?.errors && parsed.errors.length > 0) {
|
|
8
|
+
return parsed.errors;
|
|
9
|
+
}
|
|
10
|
+
if (parsed?.error && typeof parsed.error === "string") {
|
|
11
|
+
return [parsed.error];
|
|
12
|
+
}
|
|
13
|
+
return [error.message];
|
|
14
|
+
}
|
|
15
|
+
return [error instanceof Error ? error.message : String(error)];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private tryParseJson(bodyText: string): Readonly<{ error?: string; errors?: ReadonlyArray<string> }> | null {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(bodyText) as { error?: unknown; errors?: unknown };
|
|
21
|
+
if (Array.isArray(parsed.errors) && parsed.errors.every((x) => typeof x === "string")) {
|
|
22
|
+
return { error: typeof parsed.error === "string" ? parsed.error : undefined, errors: parsed.errors };
|
|
23
|
+
}
|
|
24
|
+
if (typeof parsed.error === "string") {
|
|
25
|
+
return { error: parsed.error };
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|