Skip to content

Commit 251b742

Browse files
committed
Move inputDefaults under core/primitives
1 parent 766a754 commit 251b742

12 files changed

Lines changed: 27 additions & 14 deletions

File tree

packages/agentflow/.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ module.exports = {
119119
{
120120
target: './src/atoms',
121121
from: './src/core',
122-
except: ['./types', './theme', './utils'],
123-
message: 'Atoms can only import from core/types, core/theme, and core/utils.'
122+
except: ['./types', './theme', './primitives'],
123+
message: 'Atoms can only import from core/types, core/theme, and core/primitives.'
124124
},
125125
// core/ cannot import from anything (leaf node)
126126
{

packages/agentflow/ARCHITECTURE.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ atoms/
4242
- No API calls
4343
- Stateless or minimal local state
4444
- Imported by features, never the reverse
45-
- **Forbidden**: Importing from `features/` or `infrastructure/` (except types from `core/types` for prop definitions, design tokens from `core/theme`, and utilities from `core/utils`)
45+
- **Forbidden**: Importing from `features/` or `infrastructure/` (except types from `core/types` for prop definitions, design tokens from `core/theme`, and primitives from `core/primitives`)
4646

4747
**Goal:** 100% visual consistency.
4848

@@ -110,6 +110,9 @@ features/
110110
core/
111111
├── types/ # Global interfaces (Node, Edge, Flow)
112112
│ └── index.ts
113+
├── primitives/ # Domain-free utilities (safe for atoms)
114+
│ ├── inputDefaults.ts # getDefaultValueForType
115+
│ └── index.ts
113116
├── node-config/ # Node configuration (icons, colors, default types)
114117
│ ├── nodeIcons.ts # AGENTFLOW_ICONS, DEFAULT_AGENTFLOW_NODES
115118
│ └── ...
@@ -124,7 +127,7 @@ core/
124127
│ ├── flowValidation.ts # validateFlow, validateNode
125128
│ ├── connectionValidation.ts # isValidConnectionAgentflowV2
126129
│ └── ...
127-
├── utils/ # Generic utilities
130+
├── utils/ # Domain-aware utilities (NOT importable by atoms)
128131
│ ├── nodeFactory.ts # initNode, getUniqueNodeId
129132
│ └── ...
130133
└── index.ts # Barrel export (use sparingly)
@@ -138,6 +141,15 @@ core/
138141
- Pure functions where possible
139142
- Can be tested in isolation
140143

144+
#### `core/primitives/` vs `core/utils/`
145+
146+
`core/` contains two utility directories with different import permissions:
147+
148+
- **`primitives/`** — Domain-free, general-purpose functions with no knowledge of nodes, flows, or any business concept. These are pure data transformations (e.g., computing a default value from a type string). **Safe to import from `atoms/`.**
149+
- **`utils/`** — Domain-aware utilities that understand node structures, flow data, or validation logic (e.g., `initNode`, `buildDynamicOutputAnchors`). **Only importable by `features/` and `infrastructure/`.**
150+
151+
When adding a new utility, ask: _"Does this function need to know what a Node or Flow is?"_ If no → `primitives/`. If yes → `utils/`.
152+
141153
**Goal:** To be the framework-agnostic source of truth.
142154

143155
---
@@ -210,7 +222,7 @@ infrastructure/
210222

211223
- `features``atoms`, `infrastructure`, `core`
212224
- `infrastructure``core`
213-
- `atoms``core/types` and `core/theme` only (for type definitions and design tokens)
225+
- `atoms``core/types`, `core/theme`, and `core/primitives` only
214226
- `core` → nothing (leaf node) ✅
215227
- **Atoms and Core are "leaf" nodes** - they cannot import from `features/` or `infrastructure/`
216228

packages/agentflow/src/atoms/ArrayInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Box, Button, Chip, IconButton } from '@mui/material'
44
import { useTheme } from '@mui/material/styles'
55
import { IconPlus, IconTrash } from '@tabler/icons-react'
66

7+
import { getDefaultValueForType } from '@/core/primitives'
78
import type { InputParam, NodeData } from '@/core/types'
8-
import { getDefaultValueForType } from '@/core/utils/inputDefaults'
99

1010
import { type AsyncInputProps, type ConfigInputComponentProps, NodeInputHandler } from './NodeInputHandler'
1111
import { useStableKeys } from './useStableKeys'

packages/agentflow/src/atoms/ConditionBuilder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Box, Button, Chip, IconButton, Typography } from '@mui/material'
44
import { useTheme } from '@mui/material/styles'
55
import { IconPlus, IconTrash } from '@tabler/icons-react'
66

7+
import { getDefaultValueForType } from '@/core/primitives'
78
import type { InputParam, NodeData } from '@/core/types'
8-
import { getDefaultValueForType } from '@/core/utils/inputDefaults'
99

1010
import { NodeInputHandler } from './NodeInputHandler'
1111
import { useStableKeys } from './useStableKeys'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Domain-free utility functions safe for use in any layer (including atoms)
2+
export { getDefaultValueForType } from './inputDefaults'

packages/agentflow/src/core/utils/inputDefaults.test.ts renamed to packages/agentflow/src/core/primitives/inputDefaults.test.ts

File renamed without changes.
File renamed without changes.

packages/agentflow/src/core/utils/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ export { evaluateFieldVisibility, evaluateParamVisibility, stripHiddenFieldValue
99

1010
// Dynamic output anchor utilities
1111
export { buildDynamicOutputAnchors, parseOutputHandleIndex } from './dynamicOutputAnchors'
12-
13-
// Input default value utilities
14-
export { getDefaultValueForType } from './inputDefaults'

packages/agentflow/src/core/utils/nodeFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { getDefaultValueForType } from '../primitives'
12
import type { FlowNode, NodeData, OutputAnchor } from '../types'
23

34
import { buildDynamicOutputAnchors } from './dynamicOutputAnchors'
4-
import { getDefaultValueForType } from './inputDefaults'
55

66
/**
77
* Map from NodeData.type to the ReactFlow node type key.

packages/agentflow/src/features/node-editor/ConfigInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { alpha, useTheme } from '@mui/material/styles'
66
import { IconSettings } from '@tabler/icons-react'
77

88
import { type AsyncInputProps, NodeInputHandler } from '@/atoms'
9+
import { getDefaultValueForType } from '@/core/primitives'
910
import type { InputParam, NodeData } from '@/core/types'
10-
import { evaluateFieldVisibility, getDefaultValueForType, initNode } from '@/core/utils'
11+
import { evaluateFieldVisibility, initNode } from '@/core/utils'
1112
import { useApiContext } from '@/infrastructure/store'
1213

1314
// ─── Props ────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)