@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.
Files changed (206) hide show
  1. package/README.md +25 -0
  2. package/app/(shell)/credentials/page.tsx +5 -0
  3. package/app/(shell)/dashboard/page.tsx +14 -0
  4. package/app/(shell)/layout.tsx +11 -0
  5. package/app/(shell)/page.tsx +5 -0
  6. package/app/(shell)/users/page.tsx +5 -0
  7. package/app/(shell)/workflows/[workflowId]/page.tsx +19 -0
  8. package/app/(shell)/workflows/page.tsx +5 -0
  9. package/app/api/[[...path]]/route.ts +40 -0
  10. package/app/api/auth/[...nextauth]/route.ts +3 -0
  11. package/app/globals.css +997 -0
  12. package/app/invite/[token]/page.tsx +10 -0
  13. package/app/layout.tsx +65 -0
  14. package/app/login/layout.tsx +25 -0
  15. package/app/login/page.tsx +22 -0
  16. package/components.json +21 -0
  17. package/docs/FORMS.md +46 -0
  18. package/docs/TAILWIND_SHADCN_MIGRATION.md +89 -0
  19. package/eslint.config.mjs +56 -0
  20. package/middleware.ts +29 -0
  21. package/next-env.d.ts +6 -0
  22. package/next.config.ts +34 -0
  23. package/package.json +76 -0
  24. package/postcss.config.mjs +7 -0
  25. package/public/canvas-icons/builtin/openai.svg +5 -0
  26. package/src/api/CodemationApiClient.ts +107 -0
  27. package/src/api/CodemationApiHttpError.ts +17 -0
  28. package/src/auth/CodemationNextAuthConfigResolver.ts +14 -0
  29. package/src/auth/CodemationNextAuthOAuthProviderDescriptorMapper.ts +30 -0
  30. package/src/auth/CodemationNextAuthOAuthProviderSnapshotResolver.ts +17 -0
  31. package/src/auth/CodemationNextAuthProviderCatalog.ts +107 -0
  32. package/src/auth/codemationEdgeAuth.ts +25 -0
  33. package/src/auth/codemationNextAuth.ts +32 -0
  34. package/src/components/Codemation.tsx +6 -0
  35. package/src/components/CodemationDataTable.tsx +37 -0
  36. package/src/components/CodemationDialog.tsx +137 -0
  37. package/src/components/CodemationFormattedDateTime.tsx +46 -0
  38. package/src/components/GoogleColorGIcon.tsx +39 -0
  39. package/src/components/OauthProviderIcon.tsx +33 -0
  40. package/src/components/PasswordStrengthMeter.tsx +59 -0
  41. package/src/components/forms/index.ts +28 -0
  42. package/src/components/json/JsonMonacoEditor.tsx +75 -0
  43. package/src/components/oauthProviderIconData.ts +17 -0
  44. package/src/components/ui/alert.tsx +56 -0
  45. package/src/components/ui/badge.tsx +40 -0
  46. package/src/components/ui/button.tsx +64 -0
  47. package/src/components/ui/card.tsx +70 -0
  48. package/src/components/ui/collapsible.tsx +26 -0
  49. package/src/components/ui/dialog.tsx +137 -0
  50. package/src/components/ui/dropdown-menu.tsx +238 -0
  51. package/src/components/ui/form.tsx +147 -0
  52. package/src/components/ui/input.tsx +19 -0
  53. package/src/components/ui/label.tsx +26 -0
  54. package/src/components/ui/scroll-area.tsx +47 -0
  55. package/src/components/ui/select.tsx +169 -0
  56. package/src/components/ui/separator.tsx +28 -0
  57. package/src/components/ui/switch.tsx +28 -0
  58. package/src/components/ui/table.tsx +72 -0
  59. package/src/components/ui/tabs.tsx +76 -0
  60. package/src/components/ui/textarea.tsx +18 -0
  61. package/src/components/ui/toggle.tsx +41 -0
  62. package/src/features/credentials/components/CredentialConfirmDialog.tsx +58 -0
  63. package/src/features/credentials/components/CredentialDialog.tsx +252 -0
  64. package/src/features/credentials/components/CredentialDialogFeedback.tsx +36 -0
  65. package/src/features/credentials/components/CredentialDialogFieldRows.tsx +257 -0
  66. package/src/features/credentials/components/CredentialDialogFormSections.tsx +230 -0
  67. package/src/features/credentials/components/CredentialEnvFieldStatusRow.tsx +64 -0
  68. package/src/features/credentials/components/CredentialFieldCopyButton.tsx +48 -0
  69. package/src/features/credentials/components/CredentialsScreenHealthBadge.tsx +21 -0
  70. package/src/features/credentials/components/CredentialsScreenInstancesTable.tsx +108 -0
  71. package/src/features/credentials/components/CredentialsScreenTestFailureAlert.tsx +33 -0
  72. package/src/features/credentials/hooks/useCredentialCreateDialog.ts +33 -0
  73. package/src/features/credentials/hooks/useCredentialDialogSession.ts +616 -0
  74. package/src/features/credentials/hooks/useCredentialsScreen.ts +213 -0
  75. package/src/features/credentials/lib/credentialFieldHelpers.ts +35 -0
  76. package/src/features/credentials/lib/credentialFormTypes.ts +1 -0
  77. package/src/features/credentials/lib/credentialInstanceTestPayloadParser.ts +10 -0
  78. package/src/features/credentials/screens/CredentialsScreen.tsx +187 -0
  79. package/src/features/invite/screens/InviteAcceptScreen.tsx +190 -0
  80. package/src/features/users/components/UsersInviteDialog.tsx +121 -0
  81. package/src/features/users/components/UsersRegenerateDialog.tsx +81 -0
  82. package/src/features/users/components/UsersScreenUserStatusBadge.tsx +19 -0
  83. package/src/features/users/schemas/usersInviteFormSchema.ts +7 -0
  84. package/src/features/users/screens/UsersScreen.tsx +240 -0
  85. package/src/features/workflows/components/WorkflowListFolderSection.tsx +91 -0
  86. package/src/features/workflows/components/WorkflowListItemCard.tsx +67 -0
  87. package/src/features/workflows/components/WorkflowListRoot.tsx +39 -0
  88. package/src/features/workflows/components/WorkflowsListTree.tsx +28 -0
  89. package/src/features/workflows/components/canvas/CanvasNodeChromeTooltip.tsx +96 -0
  90. package/src/features/workflows/components/canvas/CanvasNodeIconSlot.tsx +25 -0
  91. package/src/features/workflows/components/canvas/VisibleNodeStatusResolver.tsx +84 -0
  92. package/src/features/workflows/components/canvas/WorkflowCanvas.tsx +248 -0
  93. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNode.tsx +182 -0
  94. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAccents.tsx +73 -0
  95. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAgentBottomSourceHandles.tsx +43 -0
  96. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeAgentLabels.tsx +47 -0
  97. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeCard.tsx +202 -0
  98. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeHandles.tsx +77 -0
  99. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeLabelBelow.tsx +51 -0
  100. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeMainGlyph.tsx +64 -0
  101. package/src/features/workflows/components/canvas/WorkflowCanvasCodemationNodeToolbar.tsx +95 -0
  102. package/src/features/workflows/components/canvas/WorkflowCanvasLoadingPlaceholder.tsx +69 -0
  103. package/src/features/workflows/components/canvas/WorkflowCanvasNodeIcon.tsx +102 -0
  104. package/src/features/workflows/components/canvas/WorkflowCanvasSimpleIconGlyph.tsx +21 -0
  105. package/src/features/workflows/components/canvas/WorkflowCanvasStraightCountEdge.tsx +33 -0
  106. package/src/features/workflows/components/canvas/WorkflowCanvasStructureSignature.tsx +7 -0
  107. package/src/features/workflows/components/canvas/WorkflowCanvasSymmetricForkEdge.tsx +32 -0
  108. package/src/features/workflows/components/canvas/WorkflowCanvasToolbarIconButton.tsx +95 -0
  109. package/src/features/workflows/components/canvas/lib/WorkflowCanvasBuiltinIconRegistry.ts +26 -0
  110. package/src/features/workflows/components/canvas/lib/WorkflowCanvasEdgeCountResolver.ts +51 -0
  111. package/src/features/workflows/components/canvas/lib/WorkflowCanvasEdgeStyleResolver.ts +35 -0
  112. package/src/features/workflows/components/canvas/lib/WorkflowCanvasLabelLayoutEstimator.ts +42 -0
  113. package/src/features/workflows/components/canvas/lib/WorkflowCanvasOverlapResolver.ts +78 -0
  114. package/src/features/workflows/components/canvas/lib/WorkflowCanvasPortOrderResolver.ts +25 -0
  115. package/src/features/workflows/components/canvas/lib/WorkflowCanvasRoundedOrthogonalPathPlanner.ts +56 -0
  116. package/src/features/workflows/components/canvas/lib/WorkflowCanvasSiIconRegistry.ts +18 -0
  117. package/src/features/workflows/components/canvas/lib/WorkflowCanvasSymmetricForkPathPlanner.ts +43 -0
  118. package/src/features/workflows/components/canvas/lib/layoutWorkflow.ts +315 -0
  119. package/src/features/workflows/components/canvas/lib/workflowCanvasEdgeGeometry.ts +3 -0
  120. package/src/features/workflows/components/canvas/lib/workflowCanvasEmbeddedStyles.ts +62 -0
  121. package/src/features/workflows/components/canvas/lib/workflowCanvasFlowTypes.ts +10 -0
  122. package/src/features/workflows/components/canvas/lib/workflowCanvasNodeData.ts +41 -0
  123. package/src/features/workflows/components/canvas/lib/workflowCanvasNodeGeometry.ts +99 -0
  124. package/src/features/workflows/components/canvas/workflowCanvasNodeChrome.tsx +46 -0
  125. package/src/features/workflows/components/realtime/RealtimeContext.tsx +14 -0
  126. package/src/features/workflows/components/realtime/WorkflowRealtimeProvider.tsx +15 -0
  127. package/src/features/workflows/components/workflowDetail/NodeCredentialBindingRow.tsx +209 -0
  128. package/src/features/workflows/components/workflowDetail/NodeCredentialBindingsSection.tsx +227 -0
  129. package/src/features/workflows/components/workflowDetail/NodePropertiesConfigSection.tsx +51 -0
  130. package/src/features/workflows/components/workflowDetail/NodePropertiesPanelHeader.tsx +50 -0
  131. package/src/features/workflows/components/workflowDetail/NodePropertiesSlidePanel.tsx +134 -0
  132. package/src/features/workflows/components/workflowDetail/WorkflowActivationErrorDialog.tsx +71 -0
  133. package/src/features/workflows/components/workflowDetail/WorkflowActivationHeaderControl.tsx +64 -0
  134. package/src/features/workflows/components/workflowDetail/WorkflowDetailIcons.tsx +52 -0
  135. package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspector.tsx +110 -0
  136. package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorDetailBody.tsx +213 -0
  137. package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorPanes.tsx +239 -0
  138. package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorSidebarResizer.tsx +31 -0
  139. package/src/features/workflows/components/workflowDetail/WorkflowExecutionInspectorTreePanel.tsx +133 -0
  140. package/src/features/workflows/components/workflowDetail/WorkflowInspectorAttachmentGroupingPresenter.tsx +31 -0
  141. package/src/features/workflows/components/workflowDetail/WorkflowInspectorAttachmentList.tsx +118 -0
  142. package/src/features/workflows/components/workflowDetail/WorkflowInspectorBinaryView.tsx +15 -0
  143. package/src/features/workflows/components/workflowDetail/WorkflowInspectorErrorView.tsx +107 -0
  144. package/src/features/workflows/components/workflowDetail/WorkflowInspectorJsonView.tsx +114 -0
  145. package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyTreePresenter.tsx +132 -0
  146. package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyTreeViewRenderer.tsx +147 -0
  147. package/src/features/workflows/components/workflowDetail/WorkflowInspectorPrettyView.tsx +65 -0
  148. package/src/features/workflows/components/workflowDetail/WorkflowInspectorViews.tsx +5 -0
  149. package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorBinaryAttachmentRow.tsx +74 -0
  150. package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorBinaryUploadRow.tsx +69 -0
  151. package/src/features/workflows/components/workflowDetail/WorkflowJsonEditorDialog.tsx +254 -0
  152. package/src/features/workflows/components/workflowDetail/WorkflowRunsList.tsx +89 -0
  153. package/src/features/workflows/components/workflowDetail/WorkflowRunsSidebar.tsx +50 -0
  154. package/src/features/workflows/hooks/canvas/useWorkflowCanvasVisibleNodeStatuses.ts +14 -0
  155. package/src/features/workflows/hooks/realtime/realtime.tsx +271 -0
  156. package/src/features/workflows/hooks/realtime/runQueryPolling.ts +34 -0
  157. package/src/features/workflows/hooks/realtime/useWorkflowRealtimeInfrastructure.ts +541 -0
  158. package/src/features/workflows/hooks/realtime/useWorkflowRealtimeShowDisconnectedBadge.ts +9 -0
  159. package/src/features/workflows/hooks/workflowDetail/useWorkflowDetailController.tsx +1300 -0
  160. package/src/features/workflows/lib/realtime/realtimeApi.ts +78 -0
  161. package/src/features/workflows/lib/realtime/realtimeClientBridge.ts +52 -0
  162. package/src/features/workflows/lib/realtime/realtimeDomainTypes.ts +191 -0
  163. package/src/features/workflows/lib/realtime/realtimeQueryKeys.ts +15 -0
  164. package/src/features/workflows/lib/realtime/realtimeRunMutations.ts +167 -0
  165. package/src/features/workflows/lib/realtime/workflowTypes.ts +5 -0
  166. package/src/features/workflows/lib/workflowDetail/PersistedWorkflowSnapshotMapper.ts +205 -0
  167. package/src/features/workflows/lib/workflowDetail/WorkflowActivationHttpErrorFormat.ts +32 -0
  168. package/src/features/workflows/lib/workflowDetail/WorkflowDetailPresenter.ts +1017 -0
  169. package/src/features/workflows/lib/workflowDetail/WorkflowDetailUrlCodec.ts +70 -0
  170. package/src/features/workflows/lib/workflowDetail/workflowDetailTypes.ts +152 -0
  171. package/src/features/workflows/lib/workflowDetailTreeStyles.ts +65 -0
  172. package/src/features/workflows/screens/WorkflowDetailScreen.tsx +236 -0
  173. package/src/features/workflows/screens/WorkflowDetailScreenInspectorPanel.tsx +55 -0
  174. package/src/features/workflows/screens/WorkflowsList.tsx +35 -0
  175. package/src/features/workflows/screens/WorkflowsScreen.tsx +31 -0
  176. package/src/index.ts +1 -0
  177. package/src/lib/utils.ts +6 -0
  178. package/src/middleware/CodemationNextHostMiddlewarePathRules.ts +31 -0
  179. package/src/providers/CodemationSessionProvider.tsx +23 -0
  180. package/src/providers/Providers.tsx +36 -0
  181. package/src/providers/RealtimeBoundary.tsx +17 -0
  182. package/src/providers/WhitelabelProvider.tsx +22 -0
  183. package/src/server/CodemationAuthPrismaClient.ts +21 -0
  184. package/src/server/CodemationNextHost.ts +379 -0
  185. package/src/shell/AppLayout.tsx +141 -0
  186. package/src/shell/AppLayoutNavItems.tsx +129 -0
  187. package/src/shell/AppLayoutPageHeader.tsx +79 -0
  188. package/src/shell/AppLayoutSidebarBrand.tsx +33 -0
  189. package/src/shell/AppMainContent.tsx +17 -0
  190. package/src/shell/AppShellHeaderActions.tsx +12 -0
  191. package/src/shell/AppShellHeaderActionsAuthenticated.tsx +51 -0
  192. package/src/shell/CodemationNextClientShell.tsx +17 -0
  193. package/src/shell/CredentialsSignInRedirectResolver.ts +21 -0
  194. package/src/shell/LoginPageClient.tsx +231 -0
  195. package/src/shell/WorkflowDetailChromeContext.tsx +42 -0
  196. package/src/shell/WorkflowFolderTreeBuilder.ts +62 -0
  197. package/src/shell/WorkflowFolderUi.ts +42 -0
  198. package/src/shell/WorkflowSidebarNavFolder.tsx +112 -0
  199. package/src/shell/WorkflowSidebarNavTree.tsx +68 -0
  200. package/src/shell/appLayoutPageTitle.ts +16 -0
  201. package/src/shell/appLayoutSidebarIcons.tsx +108 -0
  202. package/src/whitelabel/CodemationWhitelabelSnapshot.ts +4 -0
  203. package/src/whitelabel/CodemationWhitelabelSnapshotFactory.ts +18 -0
  204. package/tsconfig.json +40 -0
  205. package/tsconfig.tsbuildinfo +1 -0
  206. 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
+ }