Compare commits
7 Commits
aiprocessb
...
copilot-wo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97fc235636 | ||
|
|
c7282ee2a0 | ||
|
|
ce65817670 | ||
|
|
fe51355d29 | ||
|
|
4f466d7992 | ||
|
|
c822017ef1 | ||
|
|
8b192ba7f5 |
@@ -1,324 +0,0 @@
|
|||||||
# AI Process Builder + Chat Orchestrator
|
|
||||||
|
|
||||||
A complete implementation of tenant-scoped AI process automation where admins design LangGraph-compiled workflows via React Flow UI, and end-users execute them through a Deep Agent chat orchestrator with deterministic, audited execution.
|
|
||||||
|
|
||||||
## Architecture Overview
|
|
||||||
|
|
||||||
### Backend Components
|
|
||||||
|
|
||||||
#### 1. **Deep Agent Orchestrator** ([deep-agent.orchestrator.ts](backend/src/ai-processes/deep-agent.orchestrator.ts))
|
|
||||||
- Uses LangChain/OpenAI to intelligently select processes
|
|
||||||
- Extracts structured inputs from natural language
|
|
||||||
- Generates friendly confirmation messages
|
|
||||||
- Three-step workflow: discover → select → extract → execute
|
|
||||||
|
|
||||||
#### 2. **Graph Compiler** ([ai-processes.compiler.ts](backend/src/ai-processes/ai-processes.compiler.ts))
|
|
||||||
- Validates ReactFlow JSON graphs (Start/End nodes, reachability, cycles)
|
|
||||||
- Compiles to LangGraph-compatible state machines
|
|
||||||
- Validates tool allowlist and JSON schemas (Ajv)
|
|
||||||
- Persists compiled artifact for versioned execution
|
|
||||||
|
|
||||||
#### 3. **Runtime Executor** ([ai-processes.runner.ts](backend/src/ai-processes/ai-processes.runner.ts))
|
|
||||||
- Executes compiled graphs deterministically
|
|
||||||
- Implements 4 node types: LLMDecisionNode, ToolNode, HumanInputNode, End
|
|
||||||
- Handles conditional edges via jsonlogic
|
|
||||||
- Emits real-time events for streaming updates
|
|
||||||
|
|
||||||
#### 4. **Tool Registry** ([tools/tool-registry.ts](backend/src/ai-processes/tools/tool-registry.ts))
|
|
||||||
- Tenant-scoped tool allowlist (database-backed via AiToolConfig)
|
|
||||||
- Demo tools wrapping ObjectService (findAccount, createAccount, etc.)
|
|
||||||
- Context injection (tenantId, userId, knex) for secure execution
|
|
||||||
|
|
||||||
#### 5. **Orchestrator Service** ([ai-processes.orchestrator.service.ts](backend/src/ai-processes/ai-processes.orchestrator.service.ts))
|
|
||||||
- Integrates Deep Agent for process selection
|
|
||||||
- Falls back to standard AI assistant when no processes configured
|
|
||||||
- Manages chat sessions and message history
|
|
||||||
- Streams execution events via SSE
|
|
||||||
|
|
||||||
### Frontend Components
|
|
||||||
|
|
||||||
#### 1. **AIChatBar** ([components/AIChatBar.vue](frontend/components/AIChatBar.vue))
|
|
||||||
- Updated to call `/ai-processes/chat/messages` endpoint
|
|
||||||
- SSE event stream consumer for real-time updates
|
|
||||||
- Displays process selection, node execution, tool calls
|
|
||||||
- Handles NEED_INPUT events for human-in-the-loop
|
|
||||||
|
|
||||||
#### 2. **Process Management UI** ([pages/ai-processes/](frontend/pages/ai-processes/))
|
|
||||||
- List view: displays all processes with versions
|
|
||||||
- Editor view: React Flow integration via iframe + postMessage
|
|
||||||
- Test runner for quick validation
|
|
||||||
|
|
||||||
#### 3. **React Flow Editor** ([ai-processes-editor/src/App.tsx](frontend/ai-processes-editor/src/App.tsx))
|
|
||||||
- Node palette: Start, LLMDecisionNode, ToolNode, HumanInputNode, End
|
|
||||||
- Visual graph designer with drag-drop
|
|
||||||
- Auto-saves to parent window via postMessage
|
|
||||||
- Loads existing graphs for editing
|
|
||||||
|
|
||||||
### Data Models (Objection.js)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
AiProcess
|
|
||||||
├── id, tenantId, name, description, latestVersion
|
|
||||||
└── relations: versions[], runs[]
|
|
||||||
|
|
||||||
AiProcessVersion
|
|
||||||
├── id, tenantId, processId, version
|
|
||||||
├── graphJson (ReactFlow definition)
|
|
||||||
└── compiledJson (LangGraph artifact)
|
|
||||||
|
|
||||||
AiProcessRun
|
|
||||||
├── id, tenantId, processId, version, status
|
|
||||||
├── inputJson, outputJson, errorJson, stateJson
|
|
||||||
└── currentNodeId (for resume)
|
|
||||||
|
|
||||||
AiChatSession
|
|
||||||
├── id, tenantId, userId
|
|
||||||
└── relations: messages[]
|
|
||||||
|
|
||||||
AiChatMessage
|
|
||||||
├── id, sessionId, role, content
|
|
||||||
└── timestamps
|
|
||||||
|
|
||||||
AiAuditEvent
|
|
||||||
├── id, tenantId, runId, eventType
|
|
||||||
└── payloadJson (full event data)
|
|
||||||
|
|
||||||
AiToolConfig
|
|
||||||
├── id, tenantId, toolName, enabled
|
|
||||||
└── configJson (tool-specific settings)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Demo Process: Register New Pet
|
|
||||||
|
|
||||||
A complete workflow demonstrating conditional logic and tool orchestration:
|
|
||||||
|
|
||||||
1. **Extract Info** (LLMDecisionNode)
|
|
||||||
- Parses user message for pet + owner details
|
|
||||||
- Outputs structured JSON with validation
|
|
||||||
|
|
||||||
2. **Find/Create Account** (Conditional)
|
|
||||||
- Searches for existing account by name/email
|
|
||||||
- Creates new account if not found
|
|
||||||
- Merges results into state
|
|
||||||
|
|
||||||
3. **Find/Create Contact** (Conditional)
|
|
||||||
- Searches for existing contact under account
|
|
||||||
- Creates new contact if not found
|
|
||||||
|
|
||||||
4. **Create Pet** (ToolNode)
|
|
||||||
- Inserts pet record linked to contact
|
|
||||||
- Returns pet ID
|
|
||||||
|
|
||||||
### Seed the Demo Process
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
npm run migrate:tenant -- <tenant-slug>
|
|
||||||
npm run seed:demo-process -- <tenant-slug>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Test the Demo Process
|
|
||||||
|
|
||||||
1. Navigate to `/ai-processes` in your tenant subdomain
|
|
||||||
2. Open "Register New Pet" process
|
|
||||||
3. Click "Test Run" or use the chat bar:
|
|
||||||
|
|
||||||
```
|
|
||||||
User: "Register a dog named Max, breed Golden Retriever, age 3,
|
|
||||||
owned by John Smith, email john@example.com"
|
|
||||||
|
|
||||||
Agent: 🔄 Selected process: Register New Pet
|
|
||||||
I'll register Max (Golden Retriever, 3 years old) for John Smith.
|
|
||||||
|
|
||||||
⚙️ Executing step: Extract Info
|
|
||||||
✓ Extracted pet details
|
|
||||||
|
|
||||||
🔧 Using tool: findAccount
|
|
||||||
ℹ️ Account not found, creating new account
|
|
||||||
|
|
||||||
🔧 Using tool: createAccount
|
|
||||||
✓ Created account for John Smith
|
|
||||||
|
|
||||||
🔧 Using tool: findContact
|
|
||||||
ℹ️ Contact not found, creating new contact
|
|
||||||
|
|
||||||
🔧 Using tool: createContact
|
|
||||||
✓ Created contact: John Smith
|
|
||||||
|
|
||||||
🔧 Using tool: createPet
|
|
||||||
✓ Created pet: Max (ID: pet_1234567890)
|
|
||||||
|
|
||||||
✅ Process completed successfully!
|
|
||||||
```
|
|
||||||
|
|
||||||
## API Endpoints
|
|
||||||
|
|
||||||
### Process Management (Admin)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
GET /tenants/:tenantId/ai-processes
|
|
||||||
POST /tenants/:tenantId/ai-processes
|
|
||||||
GET /tenants/:tenantId/ai-processes/:id
|
|
||||||
POST /tenants/:tenantId/ai-processes/:id/versions
|
|
||||||
GET /tenants/:tenantId/ai-processes/:id/versions
|
|
||||||
|
|
||||||
POST /tenants/:tenantId/ai-processes/:id/runs
|
|
||||||
POST /tenants/:tenantId/ai-processes/runs/:runId/resume
|
|
||||||
```
|
|
||||||
|
|
||||||
### Chat Orchestrator (End User)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
POST /tenants/:tenantId/ai-processes/chat/messages
|
|
||||||
SSE /tenants/:tenantId/ai-processes/stream?sessionId=xxx
|
|
||||||
```
|
|
||||||
|
|
||||||
## Event Stream Types
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
type StreamEvent =
|
|
||||||
| { type: 'agent_started' }
|
|
||||||
| { type: 'processes_listed', data: { count: number } }
|
|
||||||
| { type: 'process_selected', processId: string, version: number }
|
|
||||||
| { type: 'agent_message', data: { message: string } }
|
|
||||||
| { type: 'node_started', nodeId: string }
|
|
||||||
| { type: 'node_completed', nodeId: string }
|
|
||||||
| { type: 'tool_called', toolName: string, nodeId: string }
|
|
||||||
| { type: 'llm_decision', nodeId: string, data: any }
|
|
||||||
| { type: 'need_input', data: { prompt: string, schema: JSONSchema } }
|
|
||||||
| { type: 'final', data: { output: any } }
|
|
||||||
| { type: 'error', data: { error: string } }
|
|
||||||
```
|
|
||||||
|
|
||||||
## Security & Guardrails
|
|
||||||
|
|
||||||
### 1. **Tenancy Isolation**
|
|
||||||
- All queries filtered by `tenantId` (enforced in Objection models)
|
|
||||||
- Tool context includes tenant scope
|
|
||||||
- Database-per-tenant architecture (inherited from platform)
|
|
||||||
|
|
||||||
### 2. **Tool Allowlist**
|
|
||||||
- Two-level validation:
|
|
||||||
- Tenant-level: `AiToolConfig` table (enabled tools per tenant)
|
|
||||||
- Compile-time: validates toolName exists in registry
|
|
||||||
- Runtime check before tool execution
|
|
||||||
|
|
||||||
### 3. **Schema Validation**
|
|
||||||
- LLMDecisionNode output validated against JSON Schema (Ajv)
|
|
||||||
- HumanInputNode input validated before resume
|
|
||||||
- Graph structure validated at compile time
|
|
||||||
|
|
||||||
### 4. **Audit Trail**
|
|
||||||
- Every node execution logged to `ai_audit_events`
|
|
||||||
- Includes: tool calls, LLM decisions, state mutations, errors
|
|
||||||
- Queryable for compliance dashboards
|
|
||||||
|
|
||||||
### 5. **Versioning**
|
|
||||||
- Immutable process versions (create-only)
|
|
||||||
- Runs reference specific version number
|
|
||||||
- Graph definition + compiled artifact stored together
|
|
||||||
|
|
||||||
## Running the System
|
|
||||||
|
|
||||||
### 1. **Run Migrations**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
npm run migrate:tenant -- tenant1
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. **Seed Demo Data**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run seed:demo-process -- tenant1
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. **Start Backend**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run start:dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. **Build Editor (if needed)**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd frontend/ai-processes-editor
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. **Start Frontend**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd frontend
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. **Access UI**
|
|
||||||
|
|
||||||
- Admin UI: `http://tenant1.localhost:3001/ai-processes`
|
|
||||||
- Chat UI: Available in bottom drawer on any page (⌘K to toggle)
|
|
||||||
|
|
||||||
## Extension Points
|
|
||||||
|
|
||||||
### Adding New Node Types
|
|
||||||
|
|
||||||
1. Define type in [ai-processes.types.ts](backend/src/ai-processes/ai-processes.types.ts)
|
|
||||||
2. Add schema validation in [ai-processes.schemas.ts](backend/src/ai-processes/ai-processes.schemas.ts)
|
|
||||||
3. Implement executor in [ai-processes.runner.ts](backend/src/ai-processes/ai-processes.runner.ts)
|
|
||||||
4. Add UI component in React Flow editor
|
|
||||||
|
|
||||||
### Adding New Tools
|
|
||||||
|
|
||||||
1. Implement handler in [tools/demo-tools.ts](backend/src/ai-processes/tools/demo-tools.ts)
|
|
||||||
2. Register in `demoTools` export
|
|
||||||
3. Add to tenant allowlist via UI or seed script
|
|
||||||
4. Document input/output schema
|
|
||||||
|
|
||||||
### Custom LLM Decision Logic
|
|
||||||
|
|
||||||
Override `llmDecision` callback in [ai-processes.service.ts](backend/src/ai-processes/ai-processes.service.ts):
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
llmDecision: async (node, state) => {
|
|
||||||
const prompt = renderTemplate(node.data.promptTemplate, state);
|
|
||||||
const response = await callOpenAI(prompt, node.data.model);
|
|
||||||
return validateAgainstSchema(response, node.data.outputSchema);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Process not appearing in chat
|
|
||||||
|
|
||||||
- Check: `npm run seed:demo-process` completed successfully
|
|
||||||
- Verify: Process exists in database (`select * from ai_processes`)
|
|
||||||
- Check: Tools enabled (`select * from ai_tool_configs`)
|
|
||||||
|
|
||||||
### Graph validation errors
|
|
||||||
|
|
||||||
- Ensure exactly one Start node
|
|
||||||
- Ensure at least one End node
|
|
||||||
- Check all edges reference valid node IDs
|
|
||||||
- Verify tool names match registered tools
|
|
||||||
|
|
||||||
### SSE stream not working
|
|
||||||
|
|
||||||
- Check CORS settings for subdomain routing
|
|
||||||
- Verify `sessionId` returned from initial message
|
|
||||||
- Check browser console for connection errors
|
|
||||||
- Fallback: use polling endpoint (TODO: implement)
|
|
||||||
|
|
||||||
## Next Steps
|
|
||||||
|
|
||||||
1. **Enhanced Input Extraction**: Use Deep Agent to extract required fields per process
|
|
||||||
2. **Visual Schema Builder**: UI for JSON Schema creation (drag-drop fields)
|
|
||||||
3. **Conditional Edge Builder**: Visual jsonlogic editor
|
|
||||||
4. **Process Analytics**: Dashboard showing run success rates, avg duration
|
|
||||||
5. **Human-in-Loop UI**: Dynamic form renderer for HumanInputNode
|
|
||||||
6. **Process Marketplace**: Share processes across tenants (with permissions)
|
|
||||||
7. **Python Microservice**: Optional Python runtime for native LangGraph support
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
-- Insert demo AI process directly
|
|
||||||
SET @process_id = '2d883482-4df0-44d7-b6cf-8541b482afe4';
|
|
||||||
SET @version_id = '437b1e72-405e-4862-a8bc-f368e554b482';
|
|
||||||
SET @user_id = 'system';
|
|
||||||
|
|
||||||
-- Insert process
|
|
||||||
INSERT INTO ai_processes (id, name, created_by)
|
|
||||||
VALUES (@process_id, 'Register New Pet', @user_id);
|
|
||||||
|
|
||||||
-- Insert process version with compiled graph
|
|
||||||
INSERT INTO ai_process_versions (id, process_id, version, graph_json, compiled_json, created_by)
|
|
||||||
VALUES (
|
|
||||||
@version_id,
|
|
||||||
@process_id,
|
|
||||||
1,
|
|
||||||
'{}',
|
|
||||||
JSON_OBJECT(
|
|
||||||
'id', 'register_new_pet',
|
|
||||||
'name', 'Register New Pet',
|
|
||||||
'description', 'Complete pet registration workflow',
|
|
||||||
'allowCycles', false,
|
|
||||||
'startNodeId', 'start',
|
|
||||||
'endNodeIds', JSON_ARRAY('end'),
|
|
||||||
'maxIterations', 50,
|
|
||||||
'nodes', JSON_ARRAY(
|
|
||||||
JSON_OBJECT('id', 'start', 'type', 'Start', 'data', JSON_OBJECT('label', 'Start')),
|
|
||||||
JSON_OBJECT('id', 'extract_info', 'type', 'LLMDecisionNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Extract Info',
|
|
||||||
'promptTemplate', 'Extract: petName, species, ownerFirstName, ownerLastName, ownerEmail, accountName from: {{state.message}}',
|
|
||||||
'inputKeys', JSON_ARRAY('message'),
|
|
||||||
'outputSchema', JSON_OBJECT(
|
|
||||||
'type', 'object',
|
|
||||||
'properties', JSON_OBJECT(
|
|
||||||
'petName', JSON_OBJECT('type', 'string'),
|
|
||||||
'species', JSON_OBJECT('type', 'string'),
|
|
||||||
'ownerFirstName', JSON_OBJECT('type', 'string'),
|
|
||||||
'ownerLastName', JSON_OBJECT('type', 'string'),
|
|
||||||
'ownerEmail', JSON_OBJECT('type', 'string'),
|
|
||||||
'accountName', JSON_OBJECT('type', 'string')
|
|
||||||
),
|
|
||||||
'required', JSON_ARRAY('petName', 'species', 'ownerFirstName', 'ownerLastName')
|
|
||||||
)
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'find_account', 'type', 'ToolNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Find Account',
|
|
||||||
'toolName', 'findAccount',
|
|
||||||
'argsTemplate', JSON_OBJECT('name', '{{state.accountName}}', 'email', '{{state.ownerEmail}}'),
|
|
||||||
'outputMapping', JSON_OBJECT('found', 'accountFound', 'accountId', 'accountId')
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'create_account', 'type', 'ToolNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Create Account',
|
|
||||||
'toolName', 'createAccount',
|
|
||||||
'argsTemplate', JSON_OBJECT('name', '{{state.accountName}}', 'email', '{{state.ownerEmail}}'),
|
|
||||||
'outputMapping', JSON_OBJECT('accountId', 'accountId')
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'find_contact', 'type', 'ToolNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Find Contact',
|
|
||||||
'toolName', 'findContact',
|
|
||||||
'argsTemplate', JSON_OBJECT(
|
|
||||||
'firstName', '{{state.ownerFirstName}}',
|
|
||||||
'lastName', '{{state.ownerLastName}}',
|
|
||||||
'email', '{{state.ownerEmail}}',
|
|
||||||
'accountId', '{{state.accountId}}'
|
|
||||||
),
|
|
||||||
'outputMapping', JSON_OBJECT('found', 'contactFound', 'contactId', 'contactId')
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'create_contact', 'type', 'ToolNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Create Contact',
|
|
||||||
'toolName', 'createContact',
|
|
||||||
'argsTemplate', JSON_OBJECT(
|
|
||||||
'firstName', '{{state.ownerFirstName}}',
|
|
||||||
'lastName', '{{state.ownerLastName}}',
|
|
||||||
'email', '{{state.ownerEmail}}',
|
|
||||||
'accountId', '{{state.accountId}}'
|
|
||||||
),
|
|
||||||
'outputMapping', JSON_OBJECT('contactId', 'contactId')
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'create_pet', 'type', 'ToolNode', 'data', JSON_OBJECT(
|
|
||||||
'label', 'Create Pet',
|
|
||||||
'toolName', 'createPet',
|
|
||||||
'argsTemplate', JSON_OBJECT(
|
|
||||||
'name', '{{state.petName}}',
|
|
||||||
'species', '{{state.species}}',
|
|
||||||
'ownerId', '{{state.contactId}}'
|
|
||||||
),
|
|
||||||
'outputMapping', JSON_OBJECT('petId', 'petId')
|
|
||||||
)),
|
|
||||||
JSON_OBJECT('id', 'end', 'type', 'End', 'data', JSON_OBJECT('label', 'End'))
|
|
||||||
),
|
|
||||||
'edges', JSON_ARRAY(
|
|
||||||
JSON_OBJECT('id', 'e1', 'source', 'start', 'target', 'extract_info'),
|
|
||||||
JSON_OBJECT('id', 'e2', 'source', 'extract_info', 'target', 'find_account'),
|
|
||||||
JSON_OBJECT('id', 'e3', 'source', 'find_account', 'target', 'find_contact', 'condition', JSON_OBJECT('==', JSON_ARRAY(JSON_OBJECT('var', 'accountFound'), true))),
|
|
||||||
JSON_OBJECT('id', 'e4', 'source', 'find_account', 'target', 'create_account', 'condition', JSON_OBJECT('==', JSON_ARRAY(JSON_OBJECT('var', 'accountFound'), false))),
|
|
||||||
JSON_OBJECT('id', 'e5', 'source', 'create_account', 'target', 'find_contact'),
|
|
||||||
JSON_OBJECT('id', 'e6', 'source', 'find_contact', 'target', 'create_pet', 'condition', JSON_OBJECT('==', JSON_ARRAY(JSON_OBJECT('var', 'contactFound'), true))),
|
|
||||||
JSON_OBJECT('id', 'e7', 'source', 'find_contact', 'target', 'create_contact', 'condition', JSON_OBJECT('==', JSON_ARRAY(JSON_OBJECT('var', 'contactFound'), false))),
|
|
||||||
JSON_OBJECT('id', 'e8', 'source', 'create_contact', 'target', 'create_pet'),
|
|
||||||
JSON_OBJECT('id', 'e9', 'source', 'create_pet', 'target', 'end')
|
|
||||||
)
|
|
||||||
),
|
|
||||||
@user_id
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Insert tool allowlist
|
|
||||||
INSERT INTO ai_tool_configs (id, tool_name, enabled)
|
|
||||||
VALUES
|
|
||||||
(UUID(), 'findAccount', true),
|
|
||||||
(UUID(), 'createAccount', true),
|
|
||||||
(UUID(), 'findContact', true),
|
|
||||||
(UUID(), 'createContact', true),
|
|
||||||
(UUID(), 'createPet', true)
|
|
||||||
ON DUPLICATE KEY UPDATE enabled = true;
|
|
||||||
|
|
||||||
SELECT 'Demo process inserted successfully!' as result;
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.up = function(knex) {
|
||||||
|
return knex.schema.alterTable('page_layouts', (table) => {
|
||||||
|
// Add layout_type column to distinguish between detail/edit layouts and list view layouts
|
||||||
|
// Default to 'detail' for existing layouts
|
||||||
|
table.enum('layout_type', ['detail', 'list']).notNullable().defaultTo('detail').after('name');
|
||||||
|
|
||||||
|
// Update the unique index to include layout_type so we can have both a default detail and default list layout
|
||||||
|
table.dropIndex(['object_id', 'is_default']);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.down = function(knex) {
|
||||||
|
return knex.schema.alterTable('page_layouts', (table) => {
|
||||||
|
table.dropColumn('layout_type');
|
||||||
|
table.index(['object_id', 'is_default']);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
exports.up = async function (knex) {
|
|
||||||
await knex.schema.createTable('ai_processes', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.string('name').notNullable();
|
|
||||||
table.text('description');
|
|
||||||
table.integer('latest_version').notNullable().defaultTo(1);
|
|
||||||
table.string('created_by').notNullable();
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.timestamp('updated_at').defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.createTable('ai_process_versions', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.uuid('process_id').notNullable();
|
|
||||||
table.integer('version').notNullable();
|
|
||||||
table.json('graph_json').notNullable();
|
|
||||||
table.json('compiled_json').notNullable();
|
|
||||||
table.string('created_by').notNullable();
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.unique(['process_id', 'version']);
|
|
||||||
table.index(['process_id']);
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.createTable('ai_process_runs', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.uuid('process_id').notNullable();
|
|
||||||
table.integer('version').notNullable();
|
|
||||||
table.string('status').notNullable();
|
|
||||||
table.json('input_json').notNullable();
|
|
||||||
table.json('output_json');
|
|
||||||
table.json('error_json');
|
|
||||||
table.json('state_json');
|
|
||||||
table.string('current_node_id');
|
|
||||||
table.timestamp('started_at').defaultTo(knex.fn.now());
|
|
||||||
table.timestamp('ended_at');
|
|
||||||
table.index(['process_id']);
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.createTable('ai_chat_sessions', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.string('user_id').notNullable();
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.index(['user_id']);
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.createTable('ai_chat_messages', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.uuid('session_id').notNullable();
|
|
||||||
table.string('role').notNullable();
|
|
||||||
table.text('content').notNullable();
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.index(['session_id']);
|
|
||||||
});
|
|
||||||
|
|
||||||
await knex.schema.createTable('ai_audit_events', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.uuid('run_id').notNullable();
|
|
||||||
table.string('event_type').notNullable();
|
|
||||||
table.json('payload_json').notNullable();
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.index(['run_id']);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = async function (knex) {
|
|
||||||
await knex.schema.dropTableIfExists('ai_audit_events');
|
|
||||||
await knex.schema.dropTableIfExists('ai_chat_messages');
|
|
||||||
await knex.schema.dropTableIfExists('ai_chat_sessions');
|
|
||||||
await knex.schema.dropTableIfExists('ai_process_runs');
|
|
||||||
await knex.schema.dropTableIfExists('ai_process_versions');
|
|
||||||
await knex.schema.dropTableIfExists('ai_processes');
|
|
||||||
};
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
exports.up = async function (knex) {
|
|
||||||
await knex.schema.createTable('ai_tool_configs', (table) => {
|
|
||||||
table.uuid('id').primary();
|
|
||||||
table.string('tool_name').notNullable().unique();
|
|
||||||
table.boolean('enabled').notNullable().defaultTo(true);
|
|
||||||
table.json('config_json');
|
|
||||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
||||||
table.timestamp('updated_at').defaultTo(knex.fn.now());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = async function (knex) {
|
|
||||||
await knex.schema.dropTableIfExists('ai_tool_configs');
|
|
||||||
};
|
|
||||||
333
backend/package-lock.json
generated
333
backend/package-lock.json
generated
@@ -11,7 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@casl/ability": "^6.7.5",
|
"@casl/ability": "^6.7.5",
|
||||||
"@fastify/websocket": "^10.0.1",
|
"@fastify/websocket": "^10.0.1",
|
||||||
"@langchain/core": "^1.1.12",
|
"@langchain/core": "^1.1.15",
|
||||||
"@langchain/langgraph": "^1.0.15",
|
"@langchain/langgraph": "^1.0.15",
|
||||||
"@langchain/openai": "^1.2.1",
|
"@langchain/openai": "^1.2.1",
|
||||||
"@nestjs/bullmq": "^10.1.0",
|
"@nestjs/bullmq": "^10.1.0",
|
||||||
@@ -25,17 +25,14 @@
|
|||||||
"@nestjs/serve-static": "^4.0.2",
|
"@nestjs/serve-static": "^4.0.2",
|
||||||
"@nestjs/websockets": "^10.4.20",
|
"@nestjs/websockets": "^10.4.20",
|
||||||
"@prisma/client": "^5.8.0",
|
"@prisma/client": "^5.8.0",
|
||||||
"@types/json-logic-js": "^2.0.8",
|
|
||||||
"ajv": "^8.17.1",
|
|
||||||
"ajv-formats": "^3.0.1",
|
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"bullmq": "^5.1.0",
|
"bullmq": "^5.1.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.1",
|
"class-validator": "^0.14.1",
|
||||||
|
"deepagents": "^1.5.0",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"json-logic-js": "^2.0.5",
|
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
"langchain": "^1.2.7",
|
"langchain": "^1.2.10",
|
||||||
"mysql2": "^3.15.3",
|
"mysql2": "^3.15.3",
|
||||||
"objection": "^3.1.5",
|
"objection": "^3.1.5",
|
||||||
"openai": "^6.15.0",
|
"openai": "^6.15.0",
|
||||||
@@ -100,41 +97,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@angular-devkit/core/node_modules/ajv": {
|
|
||||||
"version": "8.12.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
|
|
||||||
"integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"fast-deep-equal": "^3.1.1",
|
|
||||||
"json-schema-traverse": "^1.0.0",
|
|
||||||
"require-from-string": "^2.0.2",
|
|
||||||
"uri-js": "^4.2.2"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/epoberezkin"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@angular-devkit/core/node_modules/ajv-formats": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"ajv": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@angular-devkit/core/node_modules/rxjs": {
|
"node_modules/@angular-devkit/core/node_modules/rxjs": {
|
||||||
"version": "7.8.1",
|
"version": "7.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz",
|
||||||
@@ -267,6 +229,26 @@
|
|||||||
"tslib": "^2.1.0"
|
"tslib": "^2.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@anthropic-ai/sdk": {
|
||||||
|
"version": "0.71.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.71.2.tgz",
|
||||||
|
"integrity": "sha512-TGNDEUuEstk/DKu0/TflXAEt+p+p/WhTlFzEnoosvbaDU2LTjm42igSdlL0VijrKpWejtOKxX0b8A7uc+XiSAQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"json-schema-to-ts": "^3.1.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"anthropic-ai-sdk": "bin/cli"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"zod": "^3.25.0 || ^4.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"zod": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
"version": "7.27.1",
|
"version": "7.27.1",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
|
||||||
@@ -728,6 +710,15 @@
|
|||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@babel/runtime": {
|
||||||
|
"version": "7.28.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.6.tgz",
|
||||||
|
"integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@babel/template": {
|
"node_modules/@babel/template": {
|
||||||
"version": "7.27.2",
|
"version": "7.27.2",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz",
|
||||||
@@ -968,23 +959,6 @@
|
|||||||
"fast-uri": "^2.0.0"
|
"fast-uri": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@fastify/ajv-compiler/node_modules/ajv-formats": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"ajv": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@fastify/cors": {
|
"node_modules/@fastify/cors": {
|
||||||
"version": "9.0.1",
|
"version": "9.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-9.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-9.0.1.tgz",
|
||||||
@@ -1745,10 +1719,26 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@langchain/anthropic": {
|
||||||
|
"version": "1.3.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@langchain/anthropic/-/anthropic-1.3.10.tgz",
|
||||||
|
"integrity": "sha512-VXq5fsEJ4FB5XGrnoG+bfm0I7OlmYLI4jZ6cX9RasyqhGo9wcDyKw1+uEQ1H7Og7jWrTa1bfXCun76wttewJnw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@anthropic-ai/sdk": "^0.71.0",
|
||||||
|
"zod": "^3.25.76 || ^4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@langchain/core": "1.1.15"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@langchain/core": {
|
"node_modules/@langchain/core": {
|
||||||
"version": "1.1.12",
|
"version": "1.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/@langchain/core/-/core-1.1.12.tgz",
|
"resolved": "https://registry.npmjs.org/@langchain/core/-/core-1.1.15.tgz",
|
||||||
"integrity": "sha512-sHWLvhyLi3fntlg3MEPB89kCjxEX7/+imlIYJcp6uFGCAZfGxVWklqp22HwjT1szorUBYrkO8u0YA554ReKxGQ==",
|
"integrity": "sha512-b8RN5DkWAmDAlMu/UpTZEluYwCLpm63PPWniRKlE8ie3KkkE7IuMQ38pf4kV1iaiI+d99BEQa2vafQHfCujsRA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cfworker/json-schema": "^4.0.2",
|
"@cfworker/json-schema": "^4.0.2",
|
||||||
@@ -2543,7 +2533,6 @@
|
|||||||
"version": "2.1.5",
|
"version": "2.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||||
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
|
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodelib/fs.stat": "2.0.5",
|
"@nodelib/fs.stat": "2.0.5",
|
||||||
@@ -2557,7 +2546,6 @@
|
|||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz",
|
||||||
"integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==",
|
"integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
@@ -2567,7 +2555,6 @@
|
|||||||
"version": "1.2.8",
|
"version": "1.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz",
|
||||||
"integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==",
|
"integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodelib/fs.scandir": "2.1.5",
|
"@nodelib/fs.scandir": "2.1.5",
|
||||||
@@ -2973,12 +2960,6 @@
|
|||||||
"pretty-format": "^29.0.0"
|
"pretty-format": "^29.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/json-logic-js": {
|
|
||||||
"version": "2.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/json-logic-js/-/json-logic-js-2.0.8.tgz",
|
|
||||||
"integrity": "sha512-WgNsDPuTPKYXl0Jh0IfoCoJoAGGYZt5qzpmjuLSEg7r0cKp/kWtWp0HAsVepyPSPyXiHo6uXp/B/kW/2J1fa2Q==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/@types/json-schema": {
|
"node_modules/@types/json-schema": {
|
||||||
"version": "7.0.15",
|
"version": "7.0.15",
|
||||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||||
@@ -3636,15 +3617,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ajv": {
|
"node_modules/ajv": {
|
||||||
"version": "8.17.1",
|
"version": "8.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz",
|
||||||
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
"integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.1",
|
||||||
"fast-uri": "^3.0.1",
|
|
||||||
"json-schema-traverse": "^1.0.0",
|
"json-schema-traverse": "^1.0.0",
|
||||||
"require-from-string": "^2.0.2"
|
"require-from-string": "^2.0.2",
|
||||||
|
"uri-js": "^4.2.2"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -3652,9 +3633,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ajv-formats": {
|
"node_modules/ajv-formats": {
|
||||||
"version": "3.0.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
||||||
"integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",
|
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^8.0.0"
|
"ajv": "^8.0.0"
|
||||||
@@ -3681,22 +3662,6 @@
|
|||||||
"ajv": "^8.8.2"
|
"ajv": "^8.8.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ajv/node_modules/fast-uri": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz",
|
|
||||||
"integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==",
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/fastify"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/fastify"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "BSD-3-Clause"
|
|
||||||
},
|
|
||||||
"node_modules/ansi-colors": {
|
"node_modules/ansi-colors": {
|
||||||
"version": "4.1.3",
|
"version": "4.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
|
||||||
@@ -4107,7 +4072,6 @@
|
|||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fill-range": "^7.1.1"
|
"fill-range": "^7.1.1"
|
||||||
@@ -4832,6 +4796,22 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/deepagents": {
|
||||||
|
"version": "1.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/deepagents/-/deepagents-1.5.0.tgz",
|
||||||
|
"integrity": "sha512-tjZLOISPMpqfk+k/iE1uIZavXW9j4NrhopUmH5ARqzmk95EEtGDyN++tgnY+tdVOOZTjE2LHjOVV7or58dtx8A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@langchain/anthropic": "^1.3.7",
|
||||||
|
"@langchain/core": "^1.1.12",
|
||||||
|
"@langchain/langgraph": "^1.0.14",
|
||||||
|
"fast-glob": "^3.3.3",
|
||||||
|
"langchain": "^1.2.7",
|
||||||
|
"micromatch": "^4.0.8",
|
||||||
|
"yaml": "^2.8.2",
|
||||||
|
"zod": "^4.3.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/deepmerge": {
|
"node_modules/deepmerge": {
|
||||||
"version": "4.3.1",
|
"version": "4.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
|
||||||
@@ -5592,7 +5572,6 @@
|
|||||||
"version": "3.3.3",
|
"version": "3.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz",
|
||||||
"integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==",
|
"integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodelib/fs.stat": "^2.0.2",
|
"@nodelib/fs.stat": "^2.0.2",
|
||||||
@@ -5627,6 +5606,23 @@
|
|||||||
"rfdc": "^1.2.0"
|
"rfdc": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fast-json-stringify/node_modules/ajv-formats": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"ajv": "^8.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"ajv": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fast-levenshtein": {
|
"node_modules/fast-levenshtein": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
|
||||||
@@ -5801,7 +5797,6 @@
|
|||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
@@ -6206,7 +6201,6 @@
|
|||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||||
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
||||||
"dev": true,
|
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-glob": "^4.0.1"
|
"is-glob": "^4.0.1"
|
||||||
@@ -6655,7 +6649,6 @@
|
|||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||||
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
@@ -6684,7 +6677,6 @@
|
|||||||
"version": "4.0.3",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||||
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-extglob": "^2.1.1"
|
"is-extglob": "^2.1.1"
|
||||||
@@ -6719,7 +6711,6 @@
|
|||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
@@ -7654,12 +7645,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/json-logic-js": {
|
|
||||||
"version": "2.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/json-logic-js/-/json-logic-js-2.0.5.tgz",
|
|
||||||
"integrity": "sha512-rTT2+lqcuUmj4DgWfmzupZqQDA64AdmYqizzMPWj3DxGdfFNsxPpcNVSaTj4l8W2tG/+hg7/mQhxjU3aPacO6g==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/json-parse-even-better-errors": {
|
"node_modules/json-parse-even-better-errors": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
|
||||||
@@ -7676,6 +7661,19 @@
|
|||||||
"fast-deep-equal": "^3.1.3"
|
"fast-deep-equal": "^3.1.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/json-schema-to-ts": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-+DWg8jCJG2TEnpy7kOm/7/AxaYoaRbjVB4LFZLySZlWn8exGs3A4OLJR966cVvU26N7X9TWxl+Jsw7dzAqKT6g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.18.3",
|
||||||
|
"ts-algebra": "^2.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/json-schema-traverse": {
|
"node_modules/json-schema-traverse": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
||||||
@@ -7878,9 +7876,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/langchain": {
|
"node_modules/langchain": {
|
||||||
"version": "1.2.7",
|
"version": "1.2.10",
|
||||||
"resolved": "https://registry.npmjs.org/langchain/-/langchain-1.2.7.tgz",
|
"resolved": "https://registry.npmjs.org/langchain/-/langchain-1.2.10.tgz",
|
||||||
"integrity": "sha512-G+3Ftz/08CurJaE7LukQGBf3mCSz7XM8LZeAaFPg391Ru4lT8eLYfG6Fv4ZI0u6EBsPVcOQfaS9ig8nCRmJeqA==",
|
"integrity": "sha512-9uVxOJE/RTECvNutQfOLwH7f6R9mcq0G/IMHwA2eptDA86R/Yz2zWMz4vARVFPxPrdSJ9nJFDPAqRQlRFwdHBw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@langchain/langgraph": "^1.0.0",
|
"@langchain/langgraph": "^1.0.0",
|
||||||
@@ -7893,7 +7891,7 @@
|
|||||||
"node": ">=20"
|
"node": ">=20"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@langchain/core": "1.1.12"
|
"@langchain/core": "1.1.15"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/langchain/node_modules/uuid": {
|
"node_modules/langchain/node_modules/uuid": {
|
||||||
@@ -8268,7 +8266,6 @@
|
|||||||
"version": "1.4.1",
|
"version": "1.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
|
||||||
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
|
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
@@ -8278,7 +8275,6 @@
|
|||||||
"version": "4.0.8",
|
"version": "4.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||||
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"braces": "^3.0.3",
|
"braces": "^3.0.3",
|
||||||
@@ -8292,7 +8288,6 @@
|
|||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.6"
|
"node": ">=8.6"
|
||||||
@@ -8722,23 +8717,38 @@
|
|||||||
"knex": ">=1.0.1"
|
"knex": ">=1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/objection/node_modules/ajv-formats": {
|
"node_modules/objection/node_modules/ajv": {
|
||||||
"version": "2.1.1",
|
"version": "8.17.1",
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
|
||||||
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^8.0.0"
|
"fast-deep-equal": "^3.1.3",
|
||||||
|
"fast-uri": "^3.0.1",
|
||||||
|
"json-schema-traverse": "^1.0.0",
|
||||||
|
"require-from-string": "^2.0.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"funding": {
|
||||||
"ajv": "^8.0.0"
|
"type": "github",
|
||||||
},
|
"url": "https://github.com/sponsors/epoberezkin"
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"ajv": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/objection/node_modules/fast-uri": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/fastify"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/fastify"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "BSD-3-Clause"
|
||||||
|
},
|
||||||
"node_modules/obliterator": {
|
"node_modules/obliterator": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.5.tgz",
|
||||||
@@ -9399,7 +9409,6 @@
|
|||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||||
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
@@ -9441,7 +9450,6 @@
|
|||||||
"version": "1.2.3",
|
"version": "1.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||||
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
||||||
"dev": true,
|
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -9780,7 +9788,6 @@
|
|||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
|
||||||
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
|
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
|
||||||
"dev": true,
|
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -10535,24 +10542,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/terser-webpack-plugin/node_modules/ajv-formats": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"ajv": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/terser-webpack-plugin/node_modules/jest-worker": {
|
"node_modules/terser-webpack-plugin/node_modules/jest-worker": {
|
||||||
"version": "27.5.1",
|
"version": "27.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz",
|
||||||
@@ -10728,7 +10717,6 @@
|
|||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-number": "^7.0.0"
|
"is-number": "^7.0.0"
|
||||||
@@ -10780,6 +10768,12 @@
|
|||||||
"tree-kill": "cli.js"
|
"tree-kill": "cli.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ts-algebra": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ts-algebra/-/ts-algebra-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-FPAhNPFMrkwz76P7cdjdmiShwMynZYN6SgOujD1urY4oNm80Ou9oMdmbR45LotcKOXoy7wSmHkRFE6Mxbrhefw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/ts-api-utils": {
|
"node_modules/ts-api-utils": {
|
||||||
"version": "1.4.3",
|
"version": "1.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz",
|
||||||
@@ -11128,7 +11122,6 @@
|
|||||||
"version": "4.4.1",
|
"version": "4.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
||||||
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
|
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
|
||||||
"dev": true,
|
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"punycode": "^2.1.0"
|
"punycode": "^2.1.0"
|
||||||
@@ -11312,25 +11305,6 @@
|
|||||||
"node": ">=10.13.0"
|
"node": ">=10.13.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/webpack/node_modules/ajv-formats": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"ajv": "^8.0.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"ajv": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/webpack/node_modules/es-module-lexer": {
|
"node_modules/webpack/node_modules/es-module-lexer": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz",
|
||||||
@@ -11546,6 +11520,21 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/yaml": {
|
||||||
|
"version": "2.8.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz",
|
||||||
|
"integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==",
|
||||||
|
"license": "ISC",
|
||||||
|
"bin": {
|
||||||
|
"yaml": "bin.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/eemeli"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yargs": {
|
"node_modules/yargs": {
|
||||||
"version": "17.7.2",
|
"version": "17.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||||
@@ -11599,9 +11588,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/zod": {
|
"node_modules/zod": {
|
||||||
"version": "3.25.76",
|
"version": "4.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.5.tgz",
|
||||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
"integrity": "sha512-k7Nwx6vuWx1IJ9Bjuf4Zt1PEllcwe7cls3VNzm4CQ1/hgtFUK2bRNG3rvnpPUhFjmqJKAKtjV576KnUkHocg/g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
|
|||||||
@@ -23,13 +23,12 @@
|
|||||||
"migrate:rollback": "knex migrate:rollback --knexfile=knexfile.js",
|
"migrate:rollback": "knex migrate:rollback --knexfile=knexfile.js",
|
||||||
"migrate:status": "ts-node -r tsconfig-paths/register scripts/check-migration-status.ts",
|
"migrate:status": "ts-node -r tsconfig-paths/register scripts/check-migration-status.ts",
|
||||||
"migrate:tenant": "ts-node -r tsconfig-paths/register scripts/migrate-tenant.ts",
|
"migrate:tenant": "ts-node -r tsconfig-paths/register scripts/migrate-tenant.ts",
|
||||||
"migrate:all-tenants": "ts-node -r tsconfig-paths/register scripts/migrate-all-tenants.ts",
|
"migrate:all-tenants": "ts-node -r tsconfig-paths/register scripts/migrate-all-tenants.ts"
|
||||||
"seed:demo-process": "ts-node -r tsconfig-paths/register scripts/seed-demo-process.ts"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@casl/ability": "^6.7.5",
|
"@casl/ability": "^6.7.5",
|
||||||
"@fastify/websocket": "^10.0.1",
|
"@fastify/websocket": "^10.0.1",
|
||||||
"@langchain/core": "^1.1.12",
|
"@langchain/core": "^1.1.15",
|
||||||
"@langchain/langgraph": "^1.0.15",
|
"@langchain/langgraph": "^1.0.15",
|
||||||
"@langchain/openai": "^1.2.1",
|
"@langchain/openai": "^1.2.1",
|
||||||
"@nestjs/bullmq": "^10.1.0",
|
"@nestjs/bullmq": "^10.1.0",
|
||||||
@@ -43,17 +42,14 @@
|
|||||||
"@nestjs/serve-static": "^4.0.2",
|
"@nestjs/serve-static": "^4.0.2",
|
||||||
"@nestjs/websockets": "^10.4.20",
|
"@nestjs/websockets": "^10.4.20",
|
||||||
"@prisma/client": "^5.8.0",
|
"@prisma/client": "^5.8.0",
|
||||||
"@types/json-logic-js": "^2.0.8",
|
|
||||||
"ajv": "^8.17.1",
|
|
||||||
"ajv-formats": "^3.0.1",
|
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"bullmq": "^5.1.0",
|
"bullmq": "^5.1.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.1",
|
"class-validator": "^0.14.1",
|
||||||
|
"deepagents": "^1.5.0",
|
||||||
"ioredis": "^5.3.2",
|
"ioredis": "^5.3.2",
|
||||||
"json-logic-js": "^2.0.5",
|
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
"langchain": "^1.2.7",
|
"langchain": "^1.2.10",
|
||||||
"mysql2": "^3.15.3",
|
"mysql2": "^3.15.3",
|
||||||
"objection": "^3.1.5",
|
"objection": "^3.1.5",
|
||||||
"openai": "^6.15.0",
|
"openai": "^6.15.0",
|
||||||
|
|||||||
@@ -181,101 +181,6 @@ model ContactDetail {
|
|||||||
@@map("contact_details")
|
@@map("contact_details")
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI Process Builder + Chat Orchestrator
|
|
||||||
model AiProcess {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
tenantId String @map("tenant_id")
|
|
||||||
name String
|
|
||||||
description String? @db.Text
|
|
||||||
latestVersion Int @default(1) @map("latest_version")
|
|
||||||
createdBy String @map("created_by")
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
|
||||||
|
|
||||||
versions AiProcessVersion[]
|
|
||||||
runs AiProcessRun[]
|
|
||||||
|
|
||||||
@@index([tenantId])
|
|
||||||
@@map("ai_processes")
|
|
||||||
}
|
|
||||||
|
|
||||||
model AiProcessVersion {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
tenantId String @map("tenant_id")
|
|
||||||
processId String @map("process_id")
|
|
||||||
version Int
|
|
||||||
graphJson Json @map("graph_json")
|
|
||||||
compiledJson Json @map("compiled_json")
|
|
||||||
createdBy String @map("created_by")
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
|
||||||
|
|
||||||
process AiProcess @relation(fields: [processId], references: [id], onDelete: Cascade)
|
|
||||||
|
|
||||||
@@unique([processId, version])
|
|
||||||
@@index([tenantId])
|
|
||||||
@@map("ai_process_versions")
|
|
||||||
}
|
|
||||||
|
|
||||||
model AiProcessRun {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
tenantId String @map("tenant_id")
|
|
||||||
processId String @map("process_id")
|
|
||||||
version Int
|
|
||||||
status String
|
|
||||||
inputJson Json @map("input_json")
|
|
||||||
outputJson Json? @map("output_json")
|
|
||||||
errorJson Json? @map("error_json")
|
|
||||||
stateJson Json? @map("state_json")
|
|
||||||
currentNodeId String? @map("current_node_id")
|
|
||||||
startedAt DateTime @default(now()) @map("started_at")
|
|
||||||
endedAt DateTime? @map("ended_at")
|
|
||||||
|
|
||||||
process AiProcess @relation(fields: [processId], references: [id], onDelete: Cascade)
|
|
||||||
|
|
||||||
@@index([tenantId])
|
|
||||||
@@index([processId])
|
|
||||||
@@map("ai_process_runs")
|
|
||||||
}
|
|
||||||
|
|
||||||
model AiChatSession {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
tenantId String @map("tenant_id")
|
|
||||||
userId String @map("user_id")
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
|
||||||
|
|
||||||
messages AiChatMessage[]
|
|
||||||
|
|
||||||
@@index([tenantId])
|
|
||||||
@@index([userId])
|
|
||||||
@@map("ai_chat_sessions")
|
|
||||||
}
|
|
||||||
|
|
||||||
model AiChatMessage {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
sessionId String @map("session_id")
|
|
||||||
role String
|
|
||||||
content String @db.Text
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
|
||||||
|
|
||||||
session AiChatSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
|
|
||||||
|
|
||||||
@@index([sessionId])
|
|
||||||
@@map("ai_chat_messages")
|
|
||||||
}
|
|
||||||
|
|
||||||
model AiAuditEvent {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
tenantId String @map("tenant_id")
|
|
||||||
runId String @map("run_id")
|
|
||||||
eventType String @map("event_type")
|
|
||||||
payloadJson Json @map("payload_json")
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
|
||||||
|
|
||||||
@@index([tenantId])
|
|
||||||
@@index([runId])
|
|
||||||
@@map("ai_audit_events")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Application Builder
|
// Application Builder
|
||||||
model App {
|
model App {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
|
|||||||
@@ -1,332 +0,0 @@
|
|||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { AiProcess, AiProcessVersion, AiToolConfig } from '../src/models/ai-process.model';
|
|
||||||
|
|
||||||
// Bootstrap NestJS to get proper services
|
|
||||||
async function getTenantContext(tenantSlugOrId: string) {
|
|
||||||
const { NestFactory } = await import('@nestjs/core');
|
|
||||||
const { AppModule } = await import('../src/app.module');
|
|
||||||
const { TenantDatabaseService } = await import('../src/tenant/tenant-database.service');
|
|
||||||
|
|
||||||
// Create app context (without listening)
|
|
||||||
const app = await NestFactory.createApplicationContext(AppModule, {
|
|
||||||
logger: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const tenantDbService = app.get(TenantDatabaseService);
|
|
||||||
|
|
||||||
// Resolve tenant ID
|
|
||||||
const tenantId = await tenantDbService.resolveTenantId(tenantSlugOrId);
|
|
||||||
|
|
||||||
// Get proper Knex connection
|
|
||||||
const knex = await tenantDbService.getTenantKnexById(tenantId);
|
|
||||||
|
|
||||||
return { tenantId, knex, app };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seed script for demo AI Process: Register New Pet
|
|
||||||
*
|
|
||||||
* This process demonstrates:
|
|
||||||
* - Conditional logic (find or create account/contact)
|
|
||||||
* - Tool usage (findAccount, createAccount, findContact, createContact, createPet)
|
|
||||||
* - Sequential execution
|
|
||||||
* - LLM decision nodes with structured JSON output
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* npm run seed:demo-process -- <tenant-slug-or-id>
|
|
||||||
*/
|
|
||||||
|
|
||||||
const demoProcessGraph = {
|
|
||||||
id: 'register_new_pet',
|
|
||||||
name: 'Register New Pet',
|
|
||||||
description: 'Complete pet registration workflow with account and contact resolution',
|
|
||||||
allowCycles: false,
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: 'start',
|
|
||||||
type: 'Start',
|
|
||||||
position: { x: 250, y: 50 },
|
|
||||||
data: { label: 'Start' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'extract_info',
|
|
||||||
type: 'LLMDecisionNode',
|
|
||||||
position: { x: 250, y: 150 },
|
|
||||||
data: {
|
|
||||||
label: 'Extract Pet Info',
|
|
||||||
promptTemplate: `Extract pet registration information from the user message.
|
|
||||||
|
|
||||||
User message: {{state.message}}
|
|
||||||
|
|
||||||
Extract:
|
|
||||||
- Pet name (required)
|
|
||||||
- Pet species (required, e.g., "dog", "cat", "bird")
|
|
||||||
- Pet breed (optional)
|
|
||||||
- Pet age (optional, as number)
|
|
||||||
- Owner first name (required)
|
|
||||||
- Owner last name (required)
|
|
||||||
- Owner email (optional)
|
|
||||||
- Owner phone (optional)
|
|
||||||
- Account/Company name (optional, defaults to owner's full name)
|
|
||||||
|
|
||||||
Return JSON with these exact fields.`,
|
|
||||||
inputKeys: ['message'],
|
|
||||||
outputSchema: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
petName: { type: 'string' },
|
|
||||||
species: { type: 'string' },
|
|
||||||
breed: { type: 'string' },
|
|
||||||
age: { type: 'number' },
|
|
||||||
ownerFirstName: { type: 'string' },
|
|
||||||
ownerLastName: { type: 'string' },
|
|
||||||
ownerEmail: { type: 'string' },
|
|
||||||
ownerPhone: { type: 'string' },
|
|
||||||
accountName: { type: 'string' },
|
|
||||||
},
|
|
||||||
required: ['petName', 'species', 'ownerFirstName', 'ownerLastName'],
|
|
||||||
},
|
|
||||||
model: { name: 'gpt-4o', temperature: 0 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'find_account',
|
|
||||||
type: 'ToolNode',
|
|
||||||
position: { x: 250, y: 280 },
|
|
||||||
data: {
|
|
||||||
label: 'Find Account',
|
|
||||||
toolName: 'findAccount',
|
|
||||||
argsTemplate: {
|
|
||||||
name: '{{state.accountName}}',
|
|
||||||
email: '{{state.ownerEmail}}',
|
|
||||||
},
|
|
||||||
outputMapping: {
|
|
||||||
found: 'accountFound',
|
|
||||||
accountId: 'accountId',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_account',
|
|
||||||
type: 'ToolNode',
|
|
||||||
position: { x: 450, y: 380 },
|
|
||||||
data: {
|
|
||||||
label: 'Create Account',
|
|
||||||
toolName: 'createAccount',
|
|
||||||
argsTemplate: {
|
|
||||||
name: '{{state.accountName}}',
|
|
||||||
email: '{{state.ownerEmail}}',
|
|
||||||
phone: '{{state.ownerPhone}}',
|
|
||||||
},
|
|
||||||
outputMapping: {
|
|
||||||
accountId: 'accountId',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'find_contact',
|
|
||||||
type: 'ToolNode',
|
|
||||||
position: { x: 250, y: 480 },
|
|
||||||
data: {
|
|
||||||
label: 'Find Contact',
|
|
||||||
toolName: 'findContact',
|
|
||||||
argsTemplate: {
|
|
||||||
firstName: '{{state.ownerFirstName}}',
|
|
||||||
lastName: '{{state.ownerLastName}}',
|
|
||||||
email: '{{state.ownerEmail}}',
|
|
||||||
accountId: '{{state.accountId}}',
|
|
||||||
},
|
|
||||||
outputMapping: {
|
|
||||||
found: 'contactFound',
|
|
||||||
contactId: 'contactId',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_contact',
|
|
||||||
type: 'ToolNode',
|
|
||||||
position: { x: 450, y: 580 },
|
|
||||||
data: {
|
|
||||||
label: 'Create Contact',
|
|
||||||
toolName: 'createContact',
|
|
||||||
argsTemplate: {
|
|
||||||
firstName: '{{state.ownerFirstName}}',
|
|
||||||
lastName: '{{state.ownerLastName}}',
|
|
||||||
email: '{{state.ownerEmail}}',
|
|
||||||
phone: '{{state.ownerPhone}}',
|
|
||||||
accountId: '{{state.accountId}}',
|
|
||||||
},
|
|
||||||
outputMapping: {
|
|
||||||
contactId: 'contactId',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_pet',
|
|
||||||
type: 'ToolNode',
|
|
||||||
position: { x: 250, y: 680 },
|
|
||||||
data: {
|
|
||||||
label: 'Create Pet Record',
|
|
||||||
toolName: 'createPet',
|
|
||||||
argsTemplate: {
|
|
||||||
name: '{{state.petName}}',
|
|
||||||
species: '{{state.species}}',
|
|
||||||
breed: '{{state.breed}}',
|
|
||||||
age: '{{state.age}}',
|
|
||||||
ownerId: '{{state.contactId}}',
|
|
||||||
},
|
|
||||||
outputMapping: {
|
|
||||||
petId: 'petId',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'end',
|
|
||||||
type: 'End',
|
|
||||||
position: { x: 250, y: 780 },
|
|
||||||
data: { label: 'End' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
edges: [
|
|
||||||
{ id: 'e1', source: 'start', target: 'extract_info' },
|
|
||||||
{ id: 'e2', source: 'extract_info', target: 'find_account' },
|
|
||||||
{
|
|
||||||
id: 'e3',
|
|
||||||
source: 'find_account',
|
|
||||||
target: 'find_contact',
|
|
||||||
condition: { '==': [{ var: 'accountFound' }, true] },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'e4',
|
|
||||||
source: 'find_account',
|
|
||||||
target: 'create_account',
|
|
||||||
condition: { '==': [{ var: 'accountFound' }, false] },
|
|
||||||
},
|
|
||||||
{ id: 'e5', source: 'create_account', target: 'find_contact' },
|
|
||||||
{
|
|
||||||
id: 'e6',
|
|
||||||
source: 'find_contact',
|
|
||||||
target: 'create_pet',
|
|
||||||
condition: { '==': [{ var: 'contactFound' }, true] },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'e7',
|
|
||||||
source: 'find_contact',
|
|
||||||
target: 'create_contact',
|
|
||||||
condition: { '==': [{ var: 'contactFound' }, false] },
|
|
||||||
},
|
|
||||||
{ id: 'e8', source: 'create_contact', target: 'create_pet' },
|
|
||||||
{ id: 'e9', source: 'create_pet', target: 'end' },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const demoTools = [
|
|
||||||
'findAccount',
|
|
||||||
'createAccount',
|
|
||||||
'findContact',
|
|
||||||
'createContact',
|
|
||||||
'createPet',
|
|
||||||
];
|
|
||||||
|
|
||||||
async function seedDemoProcess(tenantSlugOrId: string) {
|
|
||||||
let app;
|
|
||||||
try {
|
|
||||||
console.log(`\n🌱 Seeding demo AI process for tenant: ${tenantSlugOrId}\n`);
|
|
||||||
|
|
||||||
const context = await getTenantContext(tenantSlugOrId);
|
|
||||||
const { tenantId, knex, app: nestApp } = context;
|
|
||||||
app = nestApp;
|
|
||||||
|
|
||||||
console.log(`✓ Resolved tenant ID: ${tenantId}`);
|
|
||||||
console.log(`✓ Connected to tenant database`);
|
|
||||||
|
|
||||||
// Check if process already exists
|
|
||||||
const existing = await AiProcess.query(knex)
|
|
||||||
.where('name', demoProcessGraph.name)
|
|
||||||
.first();
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
console.log(`⚠ Process "${demoProcessGraph.name}" already exists (ID: ${existing.id})`);
|
|
||||||
console.log(` To create a new version, update via the UI.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create process in transaction
|
|
||||||
await knex.transaction(async (trx) => {
|
|
||||||
const processId = randomUUID();
|
|
||||||
const userId = 'system'; // System user for seed data
|
|
||||||
|
|
||||||
// Create process
|
|
||||||
await AiProcess.query(trx).insert({
|
|
||||||
id: processId,
|
|
||||||
name: demoProcessGraph.name,
|
|
||||||
description: demoProcessGraph.description,
|
|
||||||
latestVersion: 1,
|
|
||||||
createdBy: userId,
|
|
||||||
});
|
|
||||||
console.log(`✓ Created process: ${demoProcessGraph.name} (${processId})`);
|
|
||||||
|
|
||||||
// Create initial version
|
|
||||||
// Note: In production, this would call the compiler service
|
|
||||||
// For seed, we're storing a simplified version
|
|
||||||
await AiProcessVersion.query(trx).insert({
|
|
||||||
id: randomUUID(),
|
|
||||||
processId,
|
|
||||||
version: 1,
|
|
||||||
graphJson: demoProcessGraph,
|
|
||||||
compiledJson: {
|
|
||||||
graphId: demoProcessGraph.id,
|
|
||||||
version: 1,
|
|
||||||
nodes: demoProcessGraph.nodes,
|
|
||||||
edges: demoProcessGraph.edges,
|
|
||||||
startNodeId: 'start',
|
|
||||||
endNodeIds: ['end'],
|
|
||||||
adjacency: {},
|
|
||||||
},
|
|
||||||
createdBy: userId,
|
|
||||||
});
|
|
||||||
console.log(`✓ Created process version 1`);
|
|
||||||
|
|
||||||
// Enable demo tools for tenant
|
|
||||||
for (const toolName of demoTools) {
|
|
||||||
const existingTool = await AiToolConfig.query(trx)
|
|
||||||
.where('tool_name', toolName)
|
|
||||||
.first();
|
|
||||||
|
|
||||||
if (!existingTool) {
|
|
||||||
await AiToolConfig.query(trx).insert({
|
|
||||||
id: randomUUID(),
|
|
||||||
toolName,
|
|
||||||
enabled: true,
|
|
||||||
});
|
|
||||||
console.log(`✓ Enabled tool: ${toolName}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`\n✅ Demo process seeded successfully!\n`);
|
|
||||||
console.log(`Next steps:`);
|
|
||||||
console.log(` 1. Navigate to /ai-processes in your frontend`);
|
|
||||||
console.log(` 2. Open the "${demoProcessGraph.name}" process`);
|
|
||||||
console.log(` 3. Test it by sending a message like:`);
|
|
||||||
console.log(` "Register a dog named Max, owned by John Smith (john@email.com)"`);
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
if (app) await app.close();
|
|
||||||
process.exit(0);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Seed failed:', error);
|
|
||||||
if (app) await app.close();
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get tenant from command line args
|
|
||||||
const tenantSlugOrId = process.argv[2];
|
|
||||||
|
|
||||||
if (!tenantSlugOrId) {
|
|
||||||
console.error('Usage: npm run seed:demo-process -- <tenant-slug-or-id>');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
seedDemoProcess(tenantSlugOrId);
|
|
||||||
@@ -10,6 +10,5 @@ import { MeilisearchModule } from '../search/meilisearch.module';
|
|||||||
imports: [ObjectModule, PageLayoutModule, TenantModule, MeilisearchModule],
|
imports: [ObjectModule, PageLayoutModule, TenantModule, MeilisearchModule],
|
||||||
controllers: [AiAssistantController],
|
controllers: [AiAssistantController],
|
||||||
providers: [AiAssistantService],
|
providers: [AiAssistantService],
|
||||||
exports: [AiAssistantService],
|
|
||||||
})
|
})
|
||||||
export class AiAssistantModule {}
|
export class AiAssistantModule {}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,15 +12,94 @@ export interface AiChatContext {
|
|||||||
|
|
||||||
export interface AiAssistantReply {
|
export interface AiAssistantReply {
|
||||||
reply: string;
|
reply: string;
|
||||||
action?: 'create_record' | 'collect_fields' | 'clarify';
|
action?: 'create_record' | 'collect_fields' | 'clarify' | 'plan_complete' | 'plan_pending';
|
||||||
missingFields?: string[];
|
missingFields?: string[];
|
||||||
record?: any;
|
record?: any;
|
||||||
|
records?: any[]; // Multiple records when plan execution completes
|
||||||
|
plan?: RecordCreationPlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Entity Discovery Types
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
export interface EntityFieldInfo {
|
||||||
|
apiName: string;
|
||||||
|
label: string;
|
||||||
|
type: string;
|
||||||
|
isRequired: boolean;
|
||||||
|
isSystem: boolean;
|
||||||
|
referenceObject?: string; // For LOOKUP fields, the target entity
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityRelationship {
|
||||||
|
fieldApiName: string;
|
||||||
|
fieldLabel: string;
|
||||||
|
targetEntity: string;
|
||||||
|
relationshipType: 'lookup' | 'master-detail' | 'polymorphic';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityInfo {
|
||||||
|
apiName: string;
|
||||||
|
label: string;
|
||||||
|
pluralLabel?: string;
|
||||||
|
description?: string;
|
||||||
|
fields: EntityFieldInfo[];
|
||||||
|
requiredFields: string[]; // Field apiNames that are required
|
||||||
|
relationships: EntityRelationship[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SystemEntities {
|
||||||
|
entities: EntityInfo[];
|
||||||
|
entityByApiName: Record<string, EntityInfo>; // Changed from Map for state serialization
|
||||||
|
loadedAt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Planning Types
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
export interface PlannedRecord {
|
||||||
|
id: string; // Temporary ID for planning (e.g., "temp_account_1")
|
||||||
|
entityApiName: string;
|
||||||
|
entityLabel: string;
|
||||||
|
fields: Record<string, any>;
|
||||||
|
resolvedFields?: Record<string, any>; // Fields after dependency resolution
|
||||||
|
missingRequiredFields: string[];
|
||||||
|
dependsOn: string[]; // IDs of other planned records this depends on
|
||||||
|
status: 'pending' | 'ready' | 'created' | 'failed';
|
||||||
|
createdRecordId?: string; // Actual ID after creation
|
||||||
|
wasExisting?: boolean; // True if record already existed in database
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RecordCreationPlan {
|
||||||
|
id: string;
|
||||||
|
records: PlannedRecord[];
|
||||||
|
executionOrder: string[]; // Ordered list of planned record IDs
|
||||||
|
status: 'building' | 'incomplete' | 'ready' | 'executing' | 'completed' | 'failed';
|
||||||
|
createdRecords: any[];
|
||||||
|
errors: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// State Types
|
||||||
|
// ============================================
|
||||||
|
|
||||||
export interface AiAssistantState {
|
export interface AiAssistantState {
|
||||||
message: string;
|
message: string;
|
||||||
|
messages?: any[]; // BaseMessage[] from langchain - used when invoked by Deep Agent
|
||||||
history?: AiChatMessage[];
|
history?: AiChatMessage[];
|
||||||
context: AiChatContext;
|
context: AiChatContext;
|
||||||
|
|
||||||
|
// Entity discovery
|
||||||
|
systemEntities?: SystemEntities;
|
||||||
|
|
||||||
|
// Planning
|
||||||
|
plan?: RecordCreationPlan;
|
||||||
|
|
||||||
|
// Legacy fields (kept for compatibility during transition)
|
||||||
objectDefinition?: any;
|
objectDefinition?: any;
|
||||||
pageLayout?: any;
|
pageLayout?: any;
|
||||||
extractedFields?: Record<string, any>;
|
extractedFields?: Record<string, any>;
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import { compileProcessGraph, GraphValidationError } from '../ai-processes.compiler';
|
|
||||||
import { demoRegisterNewPetProcess } from '../demo-process';
|
|
||||||
|
|
||||||
describe('ai-processes compiler', () => {
|
|
||||||
it('throws when missing start node', () => {
|
|
||||||
const badGraph = {
|
|
||||||
...demoRegisterNewPetProcess,
|
|
||||||
nodes: demoRegisterNewPetProcess.nodes.filter((n) => n.type !== 'Start'),
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(() =>
|
|
||||||
compileProcessGraph(badGraph, { tenantId: 'default', version: 1 }),
|
|
||||||
).toThrow(GraphValidationError);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('compiles the demo process graph', () => {
|
|
||||||
const compiled = compileProcessGraph(demoRegisterNewPetProcess, {
|
|
||||||
tenantId: 'default',
|
|
||||||
version: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(compiled.startNodeId).toBe('start');
|
|
||||||
expect(compiled.endNodeIds).toContain('end');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { compileProcessGraph } from '../ai-processes.compiler';
|
|
||||||
import { demoRegisterNewPetProcess } from '../demo-process';
|
|
||||||
import { runCompiledGraph } from '../ai-processes.runner';
|
|
||||||
import { ToolRegistry } from '../tools/tool-registry';
|
|
||||||
|
|
||||||
describe('ai-processes runner', () => {
|
|
||||||
it('runs the demo process until human input is required', async () => {
|
|
||||||
const compiled = compileProcessGraph(demoRegisterNewPetProcess, {
|
|
||||||
tenantId: 'default',
|
|
||||||
version: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await runCompiledGraph({
|
|
||||||
compiledGraph: compiled,
|
|
||||||
input: {
|
|
||||||
accountName: 'Acme Inc',
|
|
||||||
firstName: 'Jamie',
|
|
||||||
lastName: 'Doe',
|
|
||||||
},
|
|
||||||
toolRegistry: new ToolRegistry(),
|
|
||||||
toolContext: { tenantId: 'default', userId: 'user-1' },
|
|
||||||
llmDecision: async (node, state) => {
|
|
||||||
if (node.id === 'decide_account') {
|
|
||||||
return { accountAction: 'find', accountName: state.accountName };
|
|
||||||
}
|
|
||||||
if (node.id === 'decide_contact') {
|
|
||||||
return {
|
|
||||||
contactAction: 'find',
|
|
||||||
firstName: state.firstName,
|
|
||||||
lastName: state.lastName,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.status).toBe('waiting');
|
|
||||||
expect(result.currentNodeId).toBe('need_pet');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
import { apply as applyJsonLogic } from 'json-logic-js';
|
|
||||||
import { createAjv } from './ai-processes.schemas';
|
|
||||||
import {
|
|
||||||
CompiledGraph,
|
|
||||||
ProcessGraphDefinition,
|
|
||||||
ProcessGraphEdge,
|
|
||||||
ProcessGraphNode,
|
|
||||||
} from './ai-processes.types';
|
|
||||||
import { ToolRegistry } from './tools/tool-registry';
|
|
||||||
|
|
||||||
export class GraphValidationError extends Error {
|
|
||||||
constructor(message: string) {
|
|
||||||
super(message);
|
|
||||||
this.name = 'GraphValidationError';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CompileOptions {
|
|
||||||
tenantId: string;
|
|
||||||
version: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const validateGraphDefinition = (
|
|
||||||
graph: ProcessGraphDefinition,
|
|
||||||
tenantId: string,
|
|
||||||
) => {
|
|
||||||
const ajv = createAjv();
|
|
||||||
const validate = ajv.getSchema<ProcessGraphDefinition>('processGraph');
|
|
||||||
if (!validate) {
|
|
||||||
throw new GraphValidationError('Graph schema is not registered.');
|
|
||||||
}
|
|
||||||
const valid = validate(graph);
|
|
||||||
if (!valid) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`Graph schema validation failed: ${ajv.errorsText(validate.errors)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const startNodes = graph.nodes.filter((node) => node.type === 'Start');
|
|
||||||
const endNodes = graph.nodes.filter((node) => node.type === 'End');
|
|
||||||
|
|
||||||
if (startNodes.length !== 1) {
|
|
||||||
throw new GraphValidationError('Graph must contain exactly one Start node.');
|
|
||||||
}
|
|
||||||
if (endNodes.length < 1) {
|
|
||||||
throw new GraphValidationError('Graph must contain at least one End node.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeIds = new Set(graph.nodes.map((node) => node.id));
|
|
||||||
graph.edges.forEach((edge) => {
|
|
||||||
if (!nodeIds.has(edge.source) || !nodeIds.has(edge.target)) {
|
|
||||||
throw new GraphValidationError(`Edge ${edge.id} references unknown nodes.`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const adjacency = buildAdjacency(graph.edges);
|
|
||||||
const reachable = new Set<string>();
|
|
||||||
const queue = [startNodes[0].id];
|
|
||||||
|
|
||||||
while (queue.length) {
|
|
||||||
const current = queue.shift();
|
|
||||||
if (!current || reachable.has(current)) continue;
|
|
||||||
reachable.add(current);
|
|
||||||
(adjacency[current] || []).forEach((neighbor) => queue.push(neighbor));
|
|
||||||
}
|
|
||||||
|
|
||||||
graph.nodes.forEach((node) => {
|
|
||||||
if (!reachable.has(node.id)) {
|
|
||||||
throw new GraphValidationError(`Node ${node.id} is not reachable.`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!graph.allowCycles && hasCycle(graph.nodes, graph.edges)) {
|
|
||||||
throw new GraphValidationError('Graph contains cycles but allowCycles=false.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const toolRegistry = new ToolRegistry();
|
|
||||||
const allToolNames = toolRegistry.getAllToolNames();
|
|
||||||
|
|
||||||
graph.nodes.forEach((node) => {
|
|
||||||
if (node.type === 'ToolNode') {
|
|
||||||
const toolName = (node.data as { toolName?: string }).toolName;
|
|
||||||
if (!toolName) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`ToolNode ${node.id} missing toolName configuration.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Validate tool exists in registry (allowlist check happens at runtime)
|
|
||||||
if (!allToolNames.includes(toolName)) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`Tool ${toolName} is not registered in the tool registry.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node.type === 'LLMDecisionNode') {
|
|
||||||
const data = node.data as {
|
|
||||||
promptTemplate?: string;
|
|
||||||
inputKeys?: string[];
|
|
||||||
outputSchema?: Record<string, unknown>;
|
|
||||||
model?: { name?: string; temperature?: number };
|
|
||||||
};
|
|
||||||
if (!data.promptTemplate || !data.outputSchema || !data.model?.name) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`LLMDecisionNode ${node.id} missing required configuration.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node.type === 'HumanInputNode') {
|
|
||||||
const data = node.data as {
|
|
||||||
requiredFieldsSchema?: Record<string, unknown>;
|
|
||||||
promptToUser?: string;
|
|
||||||
};
|
|
||||||
if (!data.requiredFieldsSchema || !data.promptToUser) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`HumanInputNode ${node.id} missing required configuration.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
graph.edges.forEach((edge) => {
|
|
||||||
if (edge.condition) {
|
|
||||||
try {
|
|
||||||
applyJsonLogic(edge.condition, {});
|
|
||||||
} catch (error) {
|
|
||||||
throw new GraphValidationError(
|
|
||||||
`Edge ${edge.id} has invalid json-logic condition.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const compileProcessGraph = (
|
|
||||||
graph: ProcessGraphDefinition,
|
|
||||||
options: CompileOptions,
|
|
||||||
): CompiledGraph => {
|
|
||||||
validateGraphDefinition(graph, options.tenantId);
|
|
||||||
|
|
||||||
const startNodeId = graph.nodes.find((node) => node.type === 'Start')?.id;
|
|
||||||
if (!startNodeId) {
|
|
||||||
throw new GraphValidationError('Start node missing after validation.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const endNodeIds = graph.nodes
|
|
||||||
.filter((node) => node.type === 'End')
|
|
||||||
.map((node) => node.id);
|
|
||||||
|
|
||||||
return {
|
|
||||||
graphId: graph.id,
|
|
||||||
version: options.version,
|
|
||||||
nodes: graph.nodes,
|
|
||||||
edges: graph.edges,
|
|
||||||
startNodeId,
|
|
||||||
endNodeIds,
|
|
||||||
adjacency: buildAdjacency(graph.edges),
|
|
||||||
allowCycles: graph.allowCycles,
|
|
||||||
maxIterations: graph.maxIterations,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildAdjacency = (edges: ProcessGraphEdge[]) => {
|
|
||||||
return edges.reduce<Record<string, string[]>>((acc, edge) => {
|
|
||||||
if (!acc[edge.source]) {
|
|
||||||
acc[edge.source] = [];
|
|
||||||
}
|
|
||||||
acc[edge.source].push(edge.target);
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasCycle = (nodes: ProcessGraphNode[], edges: ProcessGraphEdge[]) => {
|
|
||||||
const adjacency = buildAdjacency(edges);
|
|
||||||
const visited = new Set<string>();
|
|
||||||
const stack = new Set<string>();
|
|
||||||
|
|
||||||
const visit = (nodeId: string): boolean => {
|
|
||||||
if (stack.has(nodeId)) return true;
|
|
||||||
if (visited.has(nodeId)) return false;
|
|
||||||
visited.add(nodeId);
|
|
||||||
stack.add(nodeId);
|
|
||||||
const neighbors = adjacency[nodeId] || [];
|
|
||||||
for (const neighbor of neighbors) {
|
|
||||||
if (visit(neighbor)) return true;
|
|
||||||
}
|
|
||||||
stack.delete(nodeId);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
return nodes.some((node) => visit(node.id));
|
|
||||||
};
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
import {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Query,
|
|
||||||
Sse,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
||||||
import { CurrentUser } from '../auth/current-user.decorator';
|
|
||||||
import { TenantId } from '../tenant/tenant.decorator';
|
|
||||||
import { AiProcessesService } from './ai-processes.service';
|
|
||||||
import { AiProcessesStreamService } from './ai-processes.stream.service';
|
|
||||||
import { AiProcessesOrchestratorService } from './ai-processes.orchestrator.service';
|
|
||||||
import { CreateAiProcessDto, UpdateAiProcessDto } from './dto/ai-process.dto';
|
|
||||||
import { CreateAiRunDto, ResumeAiRunDto } from './dto/ai-run.dto';
|
|
||||||
import { CreateChatSessionDto, SendChatMessageDto } from './dto/ai-chat.dto';
|
|
||||||
|
|
||||||
@Controller('tenants/:tenantId')
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
export class AiProcessesController {
|
|
||||||
constructor(
|
|
||||||
private readonly processesService: AiProcessesService,
|
|
||||||
private readonly streamService: AiProcessesStreamService,
|
|
||||||
private readonly orchestratorService: AiProcessesOrchestratorService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Get('ai-processes')
|
|
||||||
async listProcesses(@TenantId() tenantId: string) {
|
|
||||||
return this.processesService.listProcesses(tenantId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('ai-processes')
|
|
||||||
async createProcess(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Body() payload: CreateAiProcessDto,
|
|
||||||
) {
|
|
||||||
return this.processesService.createProcess(
|
|
||||||
tenantId,
|
|
||||||
user.userId,
|
|
||||||
payload.name,
|
|
||||||
payload.description,
|
|
||||||
payload.graph,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put('ai-processes/:processId')
|
|
||||||
async updateProcess(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Param('processId') processId: string,
|
|
||||||
@Body() payload: UpdateAiProcessDto,
|
|
||||||
) {
|
|
||||||
return this.processesService.createProcessVersion(
|
|
||||||
tenantId,
|
|
||||||
user.userId,
|
|
||||||
processId,
|
|
||||||
payload.graph,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('ai-processes/:processId/versions')
|
|
||||||
async listVersions(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@Param('processId') processId: string,
|
|
||||||
) {
|
|
||||||
return this.processesService.listProcessVersions(tenantId, processId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('ai-processes/:processId/runs')
|
|
||||||
async createRun(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Param('processId') processId: string,
|
|
||||||
@Body() payload: CreateAiRunDto,
|
|
||||||
) {
|
|
||||||
return this.processesService.createRun(
|
|
||||||
tenantId,
|
|
||||||
user.userId,
|
|
||||||
processId,
|
|
||||||
payload.input,
|
|
||||||
payload.sessionId,
|
|
||||||
payload.sessionId
|
|
||||||
? (event) => this.streamService.emit(payload.sessionId as string, event)
|
|
||||||
: undefined,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('ai-runs/:runId/resume')
|
|
||||||
async resumeRun(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Param('runId') runId: string,
|
|
||||||
@Body() payload: ResumeAiRunDto,
|
|
||||||
) {
|
|
||||||
return this.processesService.resumeRun(
|
|
||||||
tenantId,
|
|
||||||
user.userId,
|
|
||||||
runId,
|
|
||||||
payload.input,
|
|
||||||
payload.sessionId,
|
|
||||||
payload.sessionId
|
|
||||||
? (event) => this.streamService.emit(payload.sessionId as string, event)
|
|
||||||
: undefined,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('ai-chat/sessions')
|
|
||||||
async createSession(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Body() _payload: CreateChatSessionDto,
|
|
||||||
) {
|
|
||||||
return this.orchestratorService.createSession(tenantId, user.userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('ai-chat/messages')
|
|
||||||
@Post('ai-processes/chat/messages')
|
|
||||||
async sendChatMessage(
|
|
||||||
@TenantId() tenantId: string,
|
|
||||||
@CurrentUser() user: any,
|
|
||||||
@Body() payload: SendChatMessageDto,
|
|
||||||
) {
|
|
||||||
return this.orchestratorService.sendMessage(
|
|
||||||
tenantId,
|
|
||||||
user.userId,
|
|
||||||
payload.message,
|
|
||||||
payload.sessionId,
|
|
||||||
payload.processId,
|
|
||||||
payload.history,
|
|
||||||
payload.context,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Sse('ai-chat/stream')
|
|
||||||
@Sse('ai-processes/stream')
|
|
||||||
streamChat(@Query('sessionId') sessionId: string) {
|
|
||||||
return this.streamService.getStream(sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { TenantModule } from '../tenant/tenant.module';
|
|
||||||
import { AiAssistantModule } from '../ai-assistant/ai-assistant.module';
|
|
||||||
import { AiProcessesController } from './ai-processes.controller';
|
|
||||||
import { AiProcessesService } from './ai-processes.service';
|
|
||||||
import { AiProcessesStreamService } from './ai-processes.stream.service';
|
|
||||||
import { AiProcessesOrchestratorService } from './ai-processes.orchestrator.service';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [TenantModule, AiAssistantModule],
|
|
||||||
controllers: [AiProcessesController],
|
|
||||||
providers: [
|
|
||||||
AiProcessesService,
|
|
||||||
AiProcessesStreamService,
|
|
||||||
AiProcessesOrchestratorService,
|
|
||||||
],
|
|
||||||
exports: [AiProcessesService],
|
|
||||||
})
|
|
||||||
export class AiProcessesModule {}
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import { AiProcessesService } from './ai-processes.service';
|
|
||||||
import { AiProcessesStreamService } from './ai-processes.stream.service';
|
|
||||||
import { AiAssistantService } from '../ai-assistant/ai-assistant.service';
|
|
||||||
import { TenantDatabaseService } from '../tenant/tenant-database.service';
|
|
||||||
import { AiChatMessage, AiChatSession } from '../models/ai-chat.model';
|
|
||||||
import { DeepAgentOrchestrator } from './deep-agent.orchestrator';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AiProcessesOrchestratorService {
|
|
||||||
constructor(
|
|
||||||
private readonly processesService: AiProcessesService,
|
|
||||||
private readonly streamService: AiProcessesStreamService,
|
|
||||||
private readonly tenantDbService: TenantDatabaseService,
|
|
||||||
private readonly aiAssistantService: AiAssistantService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private async getTenantContext(tenantId: string) {
|
|
||||||
const resolvedTenantId = await this.tenantDbService.resolveTenantId(tenantId);
|
|
||||||
const knex = await this.tenantDbService.getTenantKnexById(resolvedTenantId);
|
|
||||||
return { knex, tenantId: resolvedTenantId };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createSessionWithContext(
|
|
||||||
knex: Knex,
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
) {
|
|
||||||
return AiChatSession.query(knex).insert({
|
|
||||||
userId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async createSession(tenantId: string, userId: string) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
return this.createSessionWithContext(knex, resolvedTenantId, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async sendMessage(
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
message: string,
|
|
||||||
sessionId?: string,
|
|
||||||
processId?: string,
|
|
||||||
history?: { role: string; text: string }[],
|
|
||||||
context?: Record<string, unknown>,
|
|
||||||
) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
|
|
||||||
const session = sessionId
|
|
||||||
? await AiChatSession.query(knex).findById(sessionId)
|
|
||||||
: await this.createSessionWithContext(knex, resolvedTenantId, userId);
|
|
||||||
|
|
||||||
if (!session) {
|
|
||||||
throw new Error('Chat session not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
await AiChatMessage.query(knex).insert({
|
|
||||||
sessionId: session.id,
|
|
||||||
role: 'user',
|
|
||||||
content: message,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.streamService.emit(session.id, { type: 'agent_started' });
|
|
||||||
|
|
||||||
const processes = await this.processesService.listProcesses(resolvedTenantId);
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'processes_listed',
|
|
||||||
data: { count: processes.length },
|
|
||||||
});
|
|
||||||
|
|
||||||
// If no processes configured, fallback to standard AI assistant
|
|
||||||
if (!processes.length) {
|
|
||||||
const response = await this.aiAssistantService.handleChat(
|
|
||||||
resolvedTenantId,
|
|
||||||
userId,
|
|
||||||
message,
|
|
||||||
(history ?? []) as any,
|
|
||||||
context ?? {},
|
|
||||||
);
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'final',
|
|
||||||
data: { reply: response.reply, action: response.action },
|
|
||||||
});
|
|
||||||
|
|
||||||
await AiChatMessage.query(knex).insert({
|
|
||||||
sessionId: session.id,
|
|
||||||
role: 'assistant',
|
|
||||||
content: response.reply,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
sessionId: session.id,
|
|
||||||
reply: response.reply,
|
|
||||||
action: response.action,
|
|
||||||
record: response.record,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get OpenAI credentials from tenant integrations
|
|
||||||
const credentials = await this.aiAssistantService.getOpenAiConfig(resolvedTenantId);
|
|
||||||
if (!credentials?.apiKey) {
|
|
||||||
throw new Error('OpenAI credentials not configured for this tenant');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Deep Agent with tenant's credentials
|
|
||||||
const deepAgent = new DeepAgentOrchestrator(credentials.apiKey, credentials.model);
|
|
||||||
|
|
||||||
// Use Deep Agent to select the best process
|
|
||||||
const processInfos = processes.map((p) => ({
|
|
||||||
id: p.id,
|
|
||||||
name: p.name,
|
|
||||||
description: p.description || undefined,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const selection = await deepAgent.selectProcess(
|
|
||||||
message,
|
|
||||||
processInfos,
|
|
||||||
history as any,
|
|
||||||
);
|
|
||||||
|
|
||||||
// If we need more information or no match, respond with question
|
|
||||||
if (selection.action === 'need_more_info' || selection.action === 'no_match') {
|
|
||||||
const reply = selection.question || selection.reasoning ||
|
|
||||||
'I\'m not sure which process to use. Could you provide more details?';
|
|
||||||
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'final',
|
|
||||||
data: { reply, needsMoreInfo: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
await AiChatMessage.query(knex).insert({
|
|
||||||
sessionId: session.id,
|
|
||||||
role: 'assistant',
|
|
||||||
content: reply,
|
|
||||||
});
|
|
||||||
|
|
||||||
return { sessionId: session.id, reply, needsMoreInfo: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process selected - find it and execute
|
|
||||||
const selectedProcess = processes.find((p) => p.id === selection.processId);
|
|
||||||
if (!selectedProcess) {
|
|
||||||
throw new Error('Selected process not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'process_selected',
|
|
||||||
processId: selectedProcess.id,
|
|
||||||
version: selectedProcess.latestVersion,
|
|
||||||
data: { processName: selectedProcess.name, reasoning: selection.reasoning },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Extract inputs from the message
|
|
||||||
// For now, we'll use a simple approach - just pass the message as input
|
|
||||||
// In a more sophisticated implementation, we'd use the deep agent to extract structured inputs
|
|
||||||
const startMessage = await deepAgent.generateStartMessage(
|
|
||||||
selectedProcess.name,
|
|
||||||
{ message },
|
|
||||||
);
|
|
||||||
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'agent_message',
|
|
||||||
data: { message: startMessage },
|
|
||||||
});
|
|
||||||
|
|
||||||
await AiChatMessage.query(knex).insert({
|
|
||||||
sessionId: session.id,
|
|
||||||
role: 'assistant',
|
|
||||||
content: startMessage,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { run, result } = await this.processesService.createRun(
|
|
||||||
resolvedTenantId,
|
|
||||||
userId,
|
|
||||||
selectedProcess.id,
|
|
||||||
{ message, context: context || {} },
|
|
||||||
session.id,
|
|
||||||
(payload) => this.streamService.emit(session.id, payload),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Emit final event
|
|
||||||
this.streamService.emit(session.id, {
|
|
||||||
type: 'final',
|
|
||||||
data: {
|
|
||||||
runId: run.id,
|
|
||||||
status: result.status,
|
|
||||||
output: result.output,
|
|
||||||
message: result.status === 'completed'
|
|
||||||
? '✅ Workflow completed successfully!'
|
|
||||||
: result.status === 'error'
|
|
||||||
? `❌ Workflow failed: ${result.error?.message || 'Unknown error'}`
|
|
||||||
: '⏸️ Workflow paused',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await AiChatMessage.query(knex).insert({
|
|
||||||
sessionId: session.id,
|
|
||||||
role: 'assistant',
|
|
||||||
content: result.status === 'completed'
|
|
||||||
? '✅ Workflow completed successfully!'
|
|
||||||
: result.status === 'error'
|
|
||||||
? `❌ Workflow failed: ${result.error?.message || 'Unknown error'}`
|
|
||||||
: '⏸️ Workflow paused',
|
|
||||||
});
|
|
||||||
|
|
||||||
return { sessionId: session.id, runId: run.id, status: result.status };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
import { apply as applyJsonLogic } from 'json-logic-js';
|
|
||||||
import Ajv from 'ajv';
|
|
||||||
import { ToolRegistry, ToolContext } from './tools/tool-registry';
|
|
||||||
import {
|
|
||||||
AiProcessEventPayload,
|
|
||||||
CompiledGraph,
|
|
||||||
ProcessGraphNode,
|
|
||||||
} from './ai-processes.types';
|
|
||||||
|
|
||||||
export interface RunOptions {
|
|
||||||
compiledGraph: CompiledGraph;
|
|
||||||
input: Record<string, unknown>;
|
|
||||||
toolRegistry: ToolRegistry;
|
|
||||||
toolContext: ToolContext;
|
|
||||||
onEvent?: (event: AiProcessEventPayload) => void;
|
|
||||||
llmDecision: (
|
|
||||||
node: ProcessGraphNode,
|
|
||||||
state: Record<string, unknown>,
|
|
||||||
) => Promise<Record<string, unknown>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RunResult {
|
|
||||||
status: 'running' | 'waiting' | 'completed' | 'error';
|
|
||||||
state: Record<string, unknown>;
|
|
||||||
currentNodeId?: string;
|
|
||||||
output?: Record<string, unknown>;
|
|
||||||
error?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const runCompiledGraph = async (
|
|
||||||
options: RunOptions,
|
|
||||||
startNodeId?: string,
|
|
||||||
): Promise<RunResult> => {
|
|
||||||
const {
|
|
||||||
compiledGraph,
|
|
||||||
input,
|
|
||||||
toolRegistry,
|
|
||||||
toolContext,
|
|
||||||
onEvent,
|
|
||||||
llmDecision,
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
const state: Record<string, unknown> = { ...input };
|
|
||||||
let currentNodeId = startNodeId ?? compiledGraph.startNodeId;
|
|
||||||
let iterations = 0;
|
|
||||||
const maxIterations = compiledGraph.maxIterations ?? 50;
|
|
||||||
|
|
||||||
const emit = (payload: AiProcessEventPayload) => {
|
|
||||||
if (onEvent) {
|
|
||||||
onEvent(payload);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
while (currentNodeId) {
|
|
||||||
if (
|
|
||||||
compiledGraph.nodes.length > 0 &&
|
|
||||||
compiledGraph.endNodeIds.includes(currentNodeId)
|
|
||||||
) {
|
|
||||||
emit({ type: 'node_started', nodeId: currentNodeId });
|
|
||||||
emit({ type: 'node_completed', nodeId: currentNodeId });
|
|
||||||
emit({ type: 'final', data: { output: state } });
|
|
||||||
return { status: 'completed', state, output: state };
|
|
||||||
}
|
|
||||||
|
|
||||||
const node = compiledGraph.nodes.find((item) => item.id === currentNodeId);
|
|
||||||
if (!node) {
|
|
||||||
return {
|
|
||||||
status: 'error',
|
|
||||||
state,
|
|
||||||
error: { message: `Node ${currentNodeId} not found.` },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
emit({ type: 'node_started', nodeId: node.id });
|
|
||||||
|
|
||||||
if (node.type === 'LLMDecisionNode') {
|
|
||||||
const output = await llmDecision(node, state);
|
|
||||||
validateNodeOutput(node, output);
|
|
||||||
Object.assign(state, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'ToolNode') {
|
|
||||||
const toolName = (node.data as { toolName: string }).toolName;
|
|
||||||
emit({ type: 'tool_called', nodeId: node.id, toolName });
|
|
||||||
const tool = toolRegistry.getTool(toolName);
|
|
||||||
const argsTemplate = (node.data as { argsTemplate: Record<string, unknown> })
|
|
||||||
.argsTemplate;
|
|
||||||
const resolvedArgs = resolveTemplate(argsTemplate, state);
|
|
||||||
|
|
||||||
// Debug logging
|
|
||||||
console.log(`[ToolNode ${node.id}] Tool: ${toolName}`);
|
|
||||||
console.log(`[ToolNode ${node.id}] State keys:`, Object.keys(state));
|
|
||||||
console.log(`[ToolNode ${node.id}] ArgsTemplate:`, JSON.stringify(argsTemplate));
|
|
||||||
console.log(`[ToolNode ${node.id}] ResolvedArgs:`, JSON.stringify(resolvedArgs));
|
|
||||||
|
|
||||||
const toolResult = await tool(toolContext, {
|
|
||||||
...resolvedArgs,
|
|
||||||
state,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`[ToolNode ${node.id}] ToolResult:`, JSON.stringify(toolResult));
|
|
||||||
|
|
||||||
const outputMapping = (node.data as { outputMapping: Record<string, string> })
|
|
||||||
.outputMapping;
|
|
||||||
Object.entries(outputMapping).forEach(([key, path]) => {
|
|
||||||
console.log(`[ToolNode ${node.id}] Mapping: toolResult['${key}'] = ${toolResult[key]} -> state['${path}']`);
|
|
||||||
state[path] = toolResult[key];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.type === 'HumanInputNode') {
|
|
||||||
const data = node.data as {
|
|
||||||
requiredFieldsSchema: Record<string, unknown>;
|
|
||||||
promptToUser: string;
|
|
||||||
};
|
|
||||||
emit({
|
|
||||||
type: 'need_input',
|
|
||||||
nodeId: node.id,
|
|
||||||
data: {
|
|
||||||
requiredFieldsSchema: data.requiredFieldsSchema,
|
|
||||||
promptToUser: data.promptToUser,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return { status: 'waiting', state, currentNodeId: node.id };
|
|
||||||
}
|
|
||||||
|
|
||||||
emit({ type: 'node_completed', nodeId: node.id });
|
|
||||||
|
|
||||||
const nextTargets = compiledGraph.edges.filter(
|
|
||||||
(edge) => edge.source === node.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nextTargets.length === 0) {
|
|
||||||
return {
|
|
||||||
status: 'error',
|
|
||||||
state,
|
|
||||||
error: { message: `No outgoing edges for node ${node.id}.` },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectedEdge = selectEdge(nextTargets, state);
|
|
||||||
if (!selectedEdge) {
|
|
||||||
return {
|
|
||||||
status: 'error',
|
|
||||||
state,
|
|
||||||
error: { message: `No edge conditions matched for node ${node.id}.` },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
currentNodeId = selectedEdge.target;
|
|
||||||
iterations += 1;
|
|
||||||
|
|
||||||
if (!compiledGraph.allowCycles && iterations > compiledGraph.nodes.length) {
|
|
||||||
return {
|
|
||||||
status: 'error',
|
|
||||||
state,
|
|
||||||
error: { message: 'Cycle detected during execution.' },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compiledGraph.allowCycles && iterations > maxIterations) {
|
|
||||||
return {
|
|
||||||
status: 'error',
|
|
||||||
state,
|
|
||||||
error: { message: 'Max iterations exceeded.' },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { status: 'completed', state, output: state };
|
|
||||||
};
|
|
||||||
|
|
||||||
const resolveTemplate = (
|
|
||||||
template: Record<string, unknown>,
|
|
||||||
state: Record<string, unknown>,
|
|
||||||
) => {
|
|
||||||
return Object.entries(template).reduce<Record<string, unknown>>(
|
|
||||||
(acc, [key, value]) => {
|
|
||||||
if (typeof value === 'string' && value.startsWith('{{state.')) {
|
|
||||||
const path = value.replace('{{state.', '').replace('}}', '');
|
|
||||||
acc[key] = state[path];
|
|
||||||
} else {
|
|
||||||
acc[key] = value;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const selectEdge = (
|
|
||||||
edges: { condition?: Record<string, unknown>; target: string }[],
|
|
||||||
state: Record<string, unknown>,
|
|
||||||
) => {
|
|
||||||
if (edges.length === 1) return edges[0];
|
|
||||||
|
|
||||||
return edges.find((edge) => {
|
|
||||||
if (!edge.condition) return true;
|
|
||||||
try {
|
|
||||||
return Boolean(applyJsonLogic(edge.condition, state));
|
|
||||||
} catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateNodeOutput = (
|
|
||||||
node: ProcessGraphNode,
|
|
||||||
output: Record<string, unknown>,
|
|
||||||
) => {
|
|
||||||
const schema = (node.data as { outputSchema?: Record<string, unknown> })
|
|
||||||
.outputSchema;
|
|
||||||
if (!schema) return;
|
|
||||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
||||||
const validate = ajv.compile(schema);
|
|
||||||
if (!validate(output)) {
|
|
||||||
const errors = validate.errors?.map(e => `${e.instancePath} ${e.message}`).join(', ');
|
|
||||||
throw new Error(
|
|
||||||
`LLM output invalid for node ${node.id}. Errors: ${errors}. Output: ${JSON.stringify(output)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import Ajv, { JSONSchemaType } from 'ajv';
|
|
||||||
import addFormats from 'ajv-formats';
|
|
||||||
import {
|
|
||||||
AiNodeType,
|
|
||||||
ProcessGraphDefinition,
|
|
||||||
ProcessGraphEdge,
|
|
||||||
ProcessGraphNode,
|
|
||||||
} from './ai-processes.types';
|
|
||||||
|
|
||||||
const nodeTypes: AiNodeType[] = [
|
|
||||||
'Start',
|
|
||||||
'LLMDecisionNode',
|
|
||||||
'ToolNode',
|
|
||||||
'HumanInputNode',
|
|
||||||
'End',
|
|
||||||
];
|
|
||||||
|
|
||||||
export const graphSchema: any = {
|
|
||||||
type: 'object',
|
|
||||||
required: ['id', 'name', 'nodes', 'edges'],
|
|
||||||
additionalProperties: false,
|
|
||||||
properties: {
|
|
||||||
id: { type: 'string' },
|
|
||||||
name: { type: 'string' },
|
|
||||||
description: { type: 'string', nullable: true },
|
|
||||||
allowCycles: { type: 'boolean', nullable: true },
|
|
||||||
maxIterations: { type: 'number', nullable: true },
|
|
||||||
nodes: {
|
|
||||||
type: 'array',
|
|
||||||
items: { $ref: '#/definitions/processGraphNode' },
|
|
||||||
minItems: 1,
|
|
||||||
},
|
|
||||||
edges: {
|
|
||||||
type: 'array',
|
|
||||||
items: { $ref: '#/definitions/processGraphEdge' },
|
|
||||||
minItems: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
definitions: {
|
|
||||||
processGraphEdge: {
|
|
||||||
type: 'object',
|
|
||||||
required: ['id', 'source', 'target'],
|
|
||||||
additionalProperties: false,
|
|
||||||
properties: {
|
|
||||||
id: { type: 'string' },
|
|
||||||
source: { type: 'string' },
|
|
||||||
target: { type: 'string' },
|
|
||||||
condition: { type: 'object', nullable: true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
processGraphNode: {
|
|
||||||
type: 'object',
|
|
||||||
required: ['id', 'type', 'data'],
|
|
||||||
additionalProperties: false,
|
|
||||||
properties: {
|
|
||||||
id: { type: 'string' },
|
|
||||||
type: { type: 'string', enum: nodeTypes },
|
|
||||||
position: {
|
|
||||||
type: 'object',
|
|
||||||
nullable: true,
|
|
||||||
required: ['x', 'y'],
|
|
||||||
additionalProperties: false,
|
|
||||||
properties: {
|
|
||||||
x: { type: 'number' },
|
|
||||||
y: { type: 'number' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: { type: 'object' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createAjv = () => {
|
|
||||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
||||||
addFormats(ajv);
|
|
||||||
ajv.addSchema(graphSchema, 'processGraph');
|
|
||||||
return ajv;
|
|
||||||
};
|
|
||||||
@@ -1,319 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import { TenantDatabaseService } from '../tenant/tenant-database.service';
|
|
||||||
import {
|
|
||||||
AiAuditEvent,
|
|
||||||
AiProcess,
|
|
||||||
AiProcessRun,
|
|
||||||
AiProcessVersion,
|
|
||||||
} from '../models/ai-process.model';
|
|
||||||
import { compileProcessGraph } from './ai-processes.compiler';
|
|
||||||
import { runCompiledGraph } from './ai-processes.runner';
|
|
||||||
import {
|
|
||||||
AiProcessEventPayload,
|
|
||||||
CompiledGraph,
|
|
||||||
ProcessGraphDefinition,
|
|
||||||
} from './ai-processes.types';
|
|
||||||
import { ToolRegistry } from './tools/tool-registry';
|
|
||||||
import { demoTools } from './tools/demo-tools';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AiProcessesService {
|
|
||||||
constructor(private readonly tenantDbService: TenantDatabaseService) {}
|
|
||||||
|
|
||||||
private async getTenantContext(tenantId: string) {
|
|
||||||
const resolvedTenantId = await this.tenantDbService.resolveTenantId(tenantId);
|
|
||||||
const knex = await this.tenantDbService.getTenantKnexById(resolvedTenantId);
|
|
||||||
return { knex, tenantId: resolvedTenantId };
|
|
||||||
}
|
|
||||||
|
|
||||||
async listProcesses(tenantId: string) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
return AiProcess.query(knex)
|
|
||||||
.withGraphFetched('versions')
|
|
||||||
.orderBy('created_at', 'desc');
|
|
||||||
}
|
|
||||||
|
|
||||||
async getProcess(tenantId: string, processId: string) {
|
|
||||||
const { knex } = await this.getTenantContext(tenantId);
|
|
||||||
return AiProcess.query(knex)
|
|
||||||
.findById(processId)
|
|
||||||
.withGraphFetched('versions');
|
|
||||||
}
|
|
||||||
|
|
||||||
async createProcess(
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
name: string,
|
|
||||||
description: string | undefined,
|
|
||||||
graph: ProcessGraphDefinition,
|
|
||||||
) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
const compiled = compileProcessGraph(graph, {
|
|
||||||
tenantId: resolvedTenantId,
|
|
||||||
version: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
return knex.transaction(async (trx) => {
|
|
||||||
const processId = randomUUID();
|
|
||||||
|
|
||||||
await AiProcess.query(trx).insert({
|
|
||||||
id: processId,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
latestVersion: 1,
|
|
||||||
createdBy: userId,
|
|
||||||
});
|
|
||||||
|
|
||||||
await trx('ai_process_versions').insert({
|
|
||||||
id: randomUUID(),
|
|
||||||
process_id: processId,
|
|
||||||
version: 1,
|
|
||||||
graph_json: JSON.stringify(graph),
|
|
||||||
compiled_json: JSON.stringify(compiled),
|
|
||||||
created_by: userId,
|
|
||||||
created_at: new Date(),
|
|
||||||
});
|
|
||||||
|
|
||||||
return AiProcess.query(trx)
|
|
||||||
.findById(processId)
|
|
||||||
.withGraphFetched('versions');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async createProcessVersion(
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
processId: string,
|
|
||||||
graph: ProcessGraphDefinition,
|
|
||||||
) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
|
|
||||||
const process = await AiProcess.query(knex).findById(processId);
|
|
||||||
if (!process) {
|
|
||||||
throw new Error('Process not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextVersion = process.latestVersion + 1;
|
|
||||||
const compiled = compileProcessGraph(graph, {
|
|
||||||
tenantId: resolvedTenantId,
|
|
||||||
version: nextVersion,
|
|
||||||
});
|
|
||||||
|
|
||||||
return knex.transaction(async (trx) => {
|
|
||||||
await AiProcess.query(trx)
|
|
||||||
.findById(processId)
|
|
||||||
.patch({ latestVersion: nextVersion });
|
|
||||||
|
|
||||||
const versionId = randomUUID();
|
|
||||||
await trx('ai_process_versions').insert({
|
|
||||||
id: versionId,
|
|
||||||
process_id: processId,
|
|
||||||
version: nextVersion,
|
|
||||||
graph_json: JSON.stringify(graph),
|
|
||||||
compiled_json: JSON.stringify(compiled),
|
|
||||||
created_by: userId,
|
|
||||||
created_at: new Date(),
|
|
||||||
});
|
|
||||||
|
|
||||||
return AiProcessVersion.query(trx).findById(versionId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async listProcessVersions(tenantId: string, processId: string) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
return AiProcessVersion.query(knex)
|
|
||||||
.where({ process_id: processId })
|
|
||||||
.orderBy('version', 'desc');
|
|
||||||
}
|
|
||||||
|
|
||||||
async createRun(
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
processId: string,
|
|
||||||
input: Record<string, unknown>,
|
|
||||||
sessionId: string | undefined,
|
|
||||||
emitEvent?: (payload: AiProcessEventPayload) => void,
|
|
||||||
) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
const process = await AiProcess.query(knex).findById(processId);
|
|
||||||
if (!process) {
|
|
||||||
throw new Error('Process not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionRecord = await AiProcessVersion.query(knex).findOne({
|
|
||||||
process_id: processId,
|
|
||||||
version: process.latestVersion,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!versionRecord) {
|
|
||||||
throw new Error('Process version not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const runId = randomUUID();
|
|
||||||
await AiProcessRun.query(knex).insert({
|
|
||||||
id: runId,
|
|
||||||
processId,
|
|
||||||
version: versionRecord.version,
|
|
||||||
status: 'running',
|
|
||||||
inputJson: input,
|
|
||||||
stateJson: input,
|
|
||||||
currentNodeId: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const run = await AiProcessRun.query(knex).findById(runId);
|
|
||||||
if (!run) {
|
|
||||||
throw new Error('Run not created.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const compiled = versionRecord.compiledJson as unknown as CompiledGraph;
|
|
||||||
const toolRegistry = new ToolRegistry(demoTools);
|
|
||||||
await toolRegistry.loadTenantAllowlist(resolvedTenantId, knex);
|
|
||||||
|
|
||||||
const emitAndAudit = (event: AiProcessEventPayload) => {
|
|
||||||
emitEvent?.(event);
|
|
||||||
void AiAuditEvent.query(knex).insert({
|
|
||||||
id: randomUUID(),
|
|
||||||
runId,
|
|
||||||
eventType: event.type,
|
|
||||||
payloadJson: event as any,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const result = await runCompiledGraph(
|
|
||||||
{
|
|
||||||
compiledGraph: compiled,
|
|
||||||
input,
|
|
||||||
toolRegistry,
|
|
||||||
toolContext: { tenantId: resolvedTenantId, userId, knex },
|
|
||||||
onEvent: (event) => emitAndAudit({ ...event, runId, sessionId }),
|
|
||||||
llmDecision: async (node, state) =>
|
|
||||||
this.mockDecision(node.id, state),
|
|
||||||
},
|
|
||||||
run.currentNodeId ?? undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedRun = await this.persistRunResult(runId, result, knex);
|
|
||||||
|
|
||||||
return { run: updatedRun, result };
|
|
||||||
}
|
|
||||||
|
|
||||||
async resumeRun(
|
|
||||||
tenantId: string,
|
|
||||||
userId: string,
|
|
||||||
runId: string,
|
|
||||||
input: Record<string, unknown>,
|
|
||||||
sessionId: string | undefined,
|
|
||||||
emitEvent?: (payload: AiProcessEventPayload) => void,
|
|
||||||
) {
|
|
||||||
const { knex, tenantId: resolvedTenantId } =
|
|
||||||
await this.getTenantContext(tenantId);
|
|
||||||
const run = await AiProcessRun.query(knex).findById(runId);
|
|
||||||
if (!run) {
|
|
||||||
throw new Error('Run not found.');
|
|
||||||
}
|
|
||||||
const versionRecord = await AiProcessVersion.query(knex).findOne({
|
|
||||||
process_id: run.processId,
|
|
||||||
version: run.version,
|
|
||||||
});
|
|
||||||
if (!versionRecord) {
|
|
||||||
throw new Error('Process version not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const compiled = versionRecord.compiledJson as unknown as CompiledGraph;
|
|
||||||
const toolRegistry = new ToolRegistry(demoTools);
|
|
||||||
await toolRegistry.loadTenantAllowlist(resolvedTenantId, knex);
|
|
||||||
|
|
||||||
const mergedState = { ...(run.stateJson || {}), ...input };
|
|
||||||
const emitAndAudit = (event: AiProcessEventPayload) => {
|
|
||||||
emitEvent?.(event);
|
|
||||||
void AiAuditEvent.query(knex).insert({
|
|
||||||
id: randomUUID(),
|
|
||||||
runId: run.id,
|
|
||||||
eventType: event.type,
|
|
||||||
payloadJson: event as any,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await runCompiledGraph(
|
|
||||||
{
|
|
||||||
compiledGraph: compiled,
|
|
||||||
input: mergedState,
|
|
||||||
toolRegistry,
|
|
||||||
toolContext: { tenantId: resolvedTenantId, userId, knex },
|
|
||||||
onEvent: (event) =>
|
|
||||||
emitAndAudit({ ...event, runId: run.id, sessionId }),
|
|
||||||
llmDecision: async (node, state) =>
|
|
||||||
this.mockDecision(node.id, state),
|
|
||||||
},
|
|
||||||
run.currentNodeId ?? undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const updatedRun = await this.persistRunResult(run.id, result, knex);
|
|
||||||
|
|
||||||
return { run: updatedRun, result };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async persistRunResult(runId: string, result: any, knex: Knex) {
|
|
||||||
const endedAt =
|
|
||||||
result.status === 'completed' || result.status === 'error'
|
|
||||||
? new Date()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return AiProcessRun.query(knex).patchAndFetchById(runId, {
|
|
||||||
status: result.status,
|
|
||||||
outputJson: result.output,
|
|
||||||
errorJson: result.error,
|
|
||||||
stateJson: result.state,
|
|
||||||
currentNodeId: result.currentNodeId ?? null,
|
|
||||||
endedAt,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async mockDecision(
|
|
||||||
nodeId: string,
|
|
||||||
state: Record<string, unknown>,
|
|
||||||
) {
|
|
||||||
if (nodeId === 'extract_info') {
|
|
||||||
// Extract pet registration info from the message
|
|
||||||
const message = (state.message as string) || '';
|
|
||||||
|
|
||||||
// Simple extraction (in production, this would use an LLM)
|
|
||||||
const petNameMatch = message.match(/(?:dog|cat|pet)\s+named\s+(\w+)/i);
|
|
||||||
const petTypeMatch = message.match(/(dog|cat)/i);
|
|
||||||
const ownerNameMatch = message.match(/owned\s+by\s+([\w\s]+?)(?:\s*\(|$)/i);
|
|
||||||
const emailMatch = message.match(/\(?([\w\.-]+@[\w\.-]+\.\w+)\)?/i);
|
|
||||||
|
|
||||||
const ownerName = ownerNameMatch?.[1]?.trim() || 'Unknown Owner';
|
|
||||||
const nameParts = ownerName.split(/\s+/);
|
|
||||||
const firstName = nameParts[0] || 'Unknown';
|
|
||||||
const lastName = nameParts.slice(1).join(' ') || 'Owner';
|
|
||||||
|
|
||||||
return {
|
|
||||||
petName: petNameMatch?.[1] || 'Unknown Pet',
|
|
||||||
species: petTypeMatch?.[1]?.toLowerCase() || 'dog',
|
|
||||||
ownerFirstName: firstName,
|
|
||||||
ownerLastName: lastName,
|
|
||||||
ownerEmail: emailMatch?.[1] || null,
|
|
||||||
accountName: `${firstName} ${lastName}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (nodeId === 'decide_account') {
|
|
||||||
const accountName = (state.accountName as string) ?? 'New Account';
|
|
||||||
const accountAction = state.accountId ? 'find' : 'create';
|
|
||||||
return { accountAction, accountName };
|
|
||||||
}
|
|
||||||
if (nodeId === 'decide_contact') {
|
|
||||||
const firstName = (state.firstName as string) ?? 'Jane';
|
|
||||||
const lastName = (state.lastName as string) ?? 'Doe';
|
|
||||||
const contactAction = state.contactId ? 'find' : 'create';
|
|
||||||
return { contactAction, firstName, lastName };
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { MessageEvent } from '@nestjs/common';
|
|
||||||
import { Observable, Subject } from 'rxjs';
|
|
||||||
import { AiProcessEventPayload } from './ai-processes.types';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AiProcessesStreamService {
|
|
||||||
private readonly streams = new Map<string, Subject<MessageEvent>>();
|
|
||||||
|
|
||||||
getStream(sessionId: string): Observable<MessageEvent> {
|
|
||||||
return this.getSubject(sessionId).asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit(sessionId: string, payload: AiProcessEventPayload) {
|
|
||||||
const subject = this.getSubject(sessionId);
|
|
||||||
subject.next({ type: payload.type, data: payload });
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sessionId: string) {
|
|
||||||
const subject = this.streams.get(sessionId);
|
|
||||||
if (subject) {
|
|
||||||
subject.complete();
|
|
||||||
this.streams.delete(sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSubject(sessionId: string) {
|
|
||||||
if (!this.streams.has(sessionId)) {
|
|
||||||
this.streams.set(sessionId, new Subject<MessageEvent>());
|
|
||||||
}
|
|
||||||
return this.streams.get(sessionId) as Subject<MessageEvent>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
import { JSONSchema7 } from 'json-schema';
|
|
||||||
|
|
||||||
export type AiNodeType =
|
|
||||||
| 'Start'
|
|
||||||
| 'LLMDecisionNode'
|
|
||||||
| 'ToolNode'
|
|
||||||
| 'HumanInputNode'
|
|
||||||
| 'End';
|
|
||||||
|
|
||||||
export interface ProcessGraphDefinition {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
allowCycles?: boolean;
|
|
||||||
maxIterations?: number;
|
|
||||||
nodes: ProcessGraphNode[];
|
|
||||||
edges: ProcessGraphEdge[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProcessGraphNode {
|
|
||||||
id: string;
|
|
||||||
type: AiNodeType;
|
|
||||||
position?: { x: number; y: number };
|
|
||||||
data:
|
|
||||||
| StartNodeData
|
|
||||||
| LLMDecisionNodeData
|
|
||||||
| ToolNodeData
|
|
||||||
| HumanInputNodeData
|
|
||||||
| EndNodeData;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProcessGraphEdge {
|
|
||||||
id: string;
|
|
||||||
source: string;
|
|
||||||
target: string;
|
|
||||||
condition?: JsonLogicExpression;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type JsonLogicExpression = Record<string, unknown>;
|
|
||||||
|
|
||||||
export interface StartNodeData {
|
|
||||||
label?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EndNodeData {
|
|
||||||
label?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LLMDecisionNodeData {
|
|
||||||
label?: string;
|
|
||||||
promptTemplate: string;
|
|
||||||
inputKeys: string[];
|
|
||||||
outputSchema: JSONSchema7;
|
|
||||||
model: {
|
|
||||||
name: string;
|
|
||||||
temperature: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ToolNodeData {
|
|
||||||
label?: string;
|
|
||||||
toolName: string;
|
|
||||||
argsTemplate: Record<string, unknown>;
|
|
||||||
outputMapping: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface HumanInputNodeData {
|
|
||||||
label?: string;
|
|
||||||
requiredFieldsSchema: JSONSchema7;
|
|
||||||
promptToUser: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CompiledGraph {
|
|
||||||
graphId: string;
|
|
||||||
version: number;
|
|
||||||
nodes: ProcessGraphNode[];
|
|
||||||
edges: ProcessGraphEdge[];
|
|
||||||
startNodeId: string;
|
|
||||||
endNodeIds: string[];
|
|
||||||
adjacency: Record<string, string[]>;
|
|
||||||
allowCycles?: boolean;
|
|
||||||
maxIterations?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AiProcessStatus = 'running' | 'waiting' | 'completed' | 'error';
|
|
||||||
|
|
||||||
export interface AiProcessRunContext {
|
|
||||||
state: Record<string, unknown>;
|
|
||||||
currentNodeId?: string;
|
|
||||||
iterationCount?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AiProcessEventType =
|
|
||||||
| 'agent_started'
|
|
||||||
| 'processes_listed'
|
|
||||||
| 'process_selected'
|
|
||||||
| 'agent_message'
|
|
||||||
| 'node_started'
|
|
||||||
| 'tool_called'
|
|
||||||
| 'node_completed'
|
|
||||||
| 'need_input'
|
|
||||||
| 'final'
|
|
||||||
| 'error';
|
|
||||||
|
|
||||||
export interface AiProcessEventPayload {
|
|
||||||
type: AiProcessEventType;
|
|
||||||
runId?: string;
|
|
||||||
sessionId?: string;
|
|
||||||
nodeId?: string;
|
|
||||||
toolName?: string;
|
|
||||||
processId?: string;
|
|
||||||
version?: number;
|
|
||||||
data?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NeedInputPayload {
|
|
||||||
runId: string;
|
|
||||||
requiredFieldsSchema: JSONSchema7;
|
|
||||||
promptToUser: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProcessSelection {
|
|
||||||
processId: string;
|
|
||||||
version: number;
|
|
||||||
}
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
import { ChatOpenAI } from '@langchain/openai';
|
|
||||||
import { JsonOutputParser } from '@langchain/core/output_parsers';
|
|
||||||
import { SystemMessage, HumanMessage } from '@langchain/core/messages';
|
|
||||||
|
|
||||||
export interface ProcessInfo {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProcessSelectionResult {
|
|
||||||
action: 'select_process' | 'need_more_info' | 'no_match';
|
|
||||||
processId?: string;
|
|
||||||
question?: string;
|
|
||||||
reasoning?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface InputExtractionResult {
|
|
||||||
hasAllInputs: boolean;
|
|
||||||
extractedInputs: Record<string, unknown>;
|
|
||||||
missingFields?: string[];
|
|
||||||
question?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DeepAgentOrchestrator {
|
|
||||||
private model: ChatOpenAI;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
apiKey: string,
|
|
||||||
modelName: string = 'gpt-4o',
|
|
||||||
temperature: number = 0,
|
|
||||||
) {
|
|
||||||
this.model = new ChatOpenAI({
|
|
||||||
apiKey,
|
|
||||||
modelName,
|
|
||||||
temperature,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Step 1: Select the best matching process from available processes
|
|
||||||
*/
|
|
||||||
async selectProcess(
|
|
||||||
userMessage: string,
|
|
||||||
availableProcesses: ProcessInfo[],
|
|
||||||
conversationHistory?: { role: string; text: string }[],
|
|
||||||
): Promise<ProcessSelectionResult> {
|
|
||||||
const processList = availableProcesses
|
|
||||||
.map((p) => `- ${p.name} (ID: ${p.id}): ${p.description || 'No description'}`)
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const historyContext =
|
|
||||||
conversationHistory && conversationHistory.length > 0
|
|
||||||
? `\n\nConversation history:\n${conversationHistory
|
|
||||||
.map((msg) => `${msg.role}: ${msg.text}`)
|
|
||||||
.join('\n')}`
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const systemPrompt = `You are an intelligent process orchestrator. Your task is to select the most appropriate business process based on the user's request.
|
|
||||||
|
|
||||||
Available processes:
|
|
||||||
${processList}
|
|
||||||
|
|
||||||
Rules:
|
|
||||||
1. Select exactly ONE process that best matches the user's intent
|
|
||||||
2. If the request is ambiguous or matches multiple processes, ask for clarification
|
|
||||||
3. If no process matches, indicate no match
|
|
||||||
4. Always provide reasoning for your decision
|
|
||||||
|
|
||||||
Respond with JSON:
|
|
||||||
{
|
|
||||||
"action": "select_process" | "need_more_info" | "no_match",
|
|
||||||
"processId": "selected process ID or null",
|
|
||||||
"question": "clarifying question if needed",
|
|
||||||
"reasoning": "brief explanation of decision"
|
|
||||||
}`;
|
|
||||||
|
|
||||||
const userPrompt = `User request: ${userMessage}${historyContext}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.model.invoke([
|
|
||||||
new SystemMessage(systemPrompt),
|
|
||||||
new HumanMessage(userPrompt),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const parser = new JsonOutputParser<ProcessSelectionResult>();
|
|
||||||
const content = response.content as string;
|
|
||||||
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
|
||||||
|
|
||||||
if (jsonMatch) {
|
|
||||||
return await parser.parse(jsonMatch[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
action: 'no_match',
|
|
||||||
reasoning: 'Failed to parse LLM response',
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Process selection error:', error);
|
|
||||||
return {
|
|
||||||
action: 'no_match',
|
|
||||||
reasoning: `Error: ${error.message}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Step 2: Extract required inputs from user message
|
|
||||||
*/
|
|
||||||
async extractInputs(
|
|
||||||
userMessage: string,
|
|
||||||
requiredFields: { name: string; description: string; required: boolean }[],
|
|
||||||
conversationHistory?: { role: string; text: string }[],
|
|
||||||
context?: Record<string, unknown>,
|
|
||||||
): Promise<InputExtractionResult> {
|
|
||||||
const fieldsList = requiredFields
|
|
||||||
.map((f) => `- ${f.name} (${f.required ? 'required' : 'optional'}): ${f.description}`)
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const historyContext =
|
|
||||||
conversationHistory && conversationHistory.length > 0
|
|
||||||
? `\n\nConversation history:\n${conversationHistory
|
|
||||||
.map((msg) => `${msg.role}: ${msg.text}`)
|
|
||||||
.join('\n')}`
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const contextInfo = context ? `\n\nAvailable context: ${JSON.stringify(context)}` : '';
|
|
||||||
|
|
||||||
const systemPrompt = `You are an input extraction assistant. Extract structured data from the user's message and conversation history.
|
|
||||||
|
|
||||||
Required fields for this process:
|
|
||||||
${fieldsList}${contextInfo}
|
|
||||||
|
|
||||||
Rules:
|
|
||||||
1. Extract as many fields as possible from the message and context
|
|
||||||
2. Only mark hasAllInputs=true if ALL required fields are present
|
|
||||||
3. If required fields are missing, generate a natural question to ask the user
|
|
||||||
4. Use context data when available (e.g., current page context)
|
|
||||||
|
|
||||||
Respond with JSON:
|
|
||||||
{
|
|
||||||
"hasAllInputs": true | false,
|
|
||||||
"extractedInputs": { "field1": "value1", ... },
|
|
||||||
"missingFields": ["field1", "field2"] or undefined,
|
|
||||||
"question": "natural language question" or undefined
|
|
||||||
}`;
|
|
||||||
|
|
||||||
const userPrompt = `User message: ${userMessage}${historyContext}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.model.invoke([
|
|
||||||
new SystemMessage(systemPrompt),
|
|
||||||
new HumanMessage(userPrompt),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const parser = new JsonOutputParser<InputExtractionResult>();
|
|
||||||
const content = response.content as string;
|
|
||||||
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
|
||||||
|
|
||||||
if (jsonMatch) {
|
|
||||||
return await parser.parse(jsonMatch[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
hasAllInputs: false,
|
|
||||||
extractedInputs: {},
|
|
||||||
missingFields: requiredFields.filter((f) => f.required).map((f) => f.name),
|
|
||||||
question: 'I need more information to proceed. Could you provide additional details?',
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Input extraction error:', error);
|
|
||||||
return {
|
|
||||||
hasAllInputs: false,
|
|
||||||
extractedInputs: {},
|
|
||||||
question: 'I encountered an error processing your request. Please try again.',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Step 3: Generate a friendly response explaining what will happen
|
|
||||||
*/
|
|
||||||
async generateStartMessage(
|
|
||||||
processName: string,
|
|
||||||
extractedInputs: Record<string, unknown>,
|
|
||||||
): Promise<string> {
|
|
||||||
const systemPrompt = `You are a friendly assistant explaining what process will be executed. Be concise and clear.`;
|
|
||||||
|
|
||||||
const userPrompt = `Generate a brief message (1-2 sentences) confirming that you will execute the "${processName}" process with these inputs: ${JSON.stringify(extractedInputs)}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.model.invoke([
|
|
||||||
new SystemMessage(systemPrompt),
|
|
||||||
new HumanMessage(userPrompt),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (response.content as string).trim();
|
|
||||||
} catch (error) {
|
|
||||||
return `I'll execute the ${processName} process with your provided information.`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
import { ProcessGraphDefinition } from './ai-processes.types';
|
|
||||||
|
|
||||||
export const demoRegisterNewPetProcess: ProcessGraphDefinition = {
|
|
||||||
id: 'register_new_pet',
|
|
||||||
name: 'Register New Pet',
|
|
||||||
description: 'Resolve account/contact then create pet.',
|
|
||||||
allowCycles: false,
|
|
||||||
nodes: [
|
|
||||||
{
|
|
||||||
id: 'start',
|
|
||||||
type: 'Start',
|
|
||||||
data: { label: 'Start' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'decide_account',
|
|
||||||
type: 'LLMDecisionNode',
|
|
||||||
data: {
|
|
||||||
label: 'Decide Account Action',
|
|
||||||
promptTemplate:
|
|
||||||
'Decide whether to find or create an account. Return JSON {"accountAction":"find|create","accountName":"string"}.',
|
|
||||||
inputKeys: ['accountName'],
|
|
||||||
outputSchema: {
|
|
||||||
type: 'object',
|
|
||||||
required: ['accountAction', 'accountName'],
|
|
||||||
properties: {
|
|
||||||
accountAction: { type: 'string', enum: ['find', 'create'] },
|
|
||||||
accountName: { type: 'string' },
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
},
|
|
||||||
model: { name: 'gpt-4o-mini', temperature: 0 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'find_account',
|
|
||||||
type: 'ToolNode',
|
|
||||||
data: {
|
|
||||||
label: 'Find Account',
|
|
||||||
toolName: 'findAccount',
|
|
||||||
argsTemplate: { accountName: '{{state.accountName}}' },
|
|
||||||
outputMapping: { accountId: 'accountId', found: 'accountFound' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_account',
|
|
||||||
type: 'ToolNode',
|
|
||||||
data: {
|
|
||||||
label: 'Create Account',
|
|
||||||
toolName: 'createAccount',
|
|
||||||
argsTemplate: { accountName: '{{state.accountName}}' },
|
|
||||||
outputMapping: { accountId: 'accountId' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'decide_contact',
|
|
||||||
type: 'LLMDecisionNode',
|
|
||||||
data: {
|
|
||||||
label: 'Decide Contact Action',
|
|
||||||
promptTemplate:
|
|
||||||
'Decide whether to find or create a contact. Return JSON {"contactAction":"find|create","firstName":"string","lastName":"string"}.',
|
|
||||||
inputKeys: ['firstName', 'lastName'],
|
|
||||||
outputSchema: {
|
|
||||||
type: 'object',
|
|
||||||
required: ['contactAction', 'firstName', 'lastName'],
|
|
||||||
properties: {
|
|
||||||
contactAction: { type: 'string', enum: ['find', 'create'] },
|
|
||||||
firstName: { type: 'string' },
|
|
||||||
lastName: { type: 'string' },
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
},
|
|
||||||
model: { name: 'gpt-4o-mini', temperature: 0 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'find_contact',
|
|
||||||
type: 'ToolNode',
|
|
||||||
data: {
|
|
||||||
label: 'Find Contact',
|
|
||||||
toolName: 'findContact',
|
|
||||||
argsTemplate: {
|
|
||||||
accountId: '{{state.accountId}}',
|
|
||||||
firstName: '{{state.firstName}}',
|
|
||||||
lastName: '{{state.lastName}}',
|
|
||||||
},
|
|
||||||
outputMapping: { contactId: 'contactId', found: 'contactFound' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_contact',
|
|
||||||
type: 'ToolNode',
|
|
||||||
data: {
|
|
||||||
label: 'Create Contact',
|
|
||||||
toolName: 'createContact',
|
|
||||||
argsTemplate: {
|
|
||||||
accountId: '{{state.accountId}}',
|
|
||||||
firstName: '{{state.firstName}}',
|
|
||||||
lastName: '{{state.lastName}}',
|
|
||||||
},
|
|
||||||
outputMapping: { contactId: 'contactId' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'need_pet',
|
|
||||||
type: 'HumanInputNode',
|
|
||||||
data: {
|
|
||||||
label: 'Collect Pet Info',
|
|
||||||
promptToUser: 'What is the pet name and type?',
|
|
||||||
requiredFieldsSchema: {
|
|
||||||
type: 'object',
|
|
||||||
required: ['petName', 'petType'],
|
|
||||||
properties: {
|
|
||||||
petName: { type: 'string' },
|
|
||||||
petType: { type: 'string' },
|
|
||||||
},
|
|
||||||
additionalProperties: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'create_pet',
|
|
||||||
type: 'ToolNode',
|
|
||||||
data: {
|
|
||||||
label: 'Create Pet',
|
|
||||||
toolName: 'createPet',
|
|
||||||
argsTemplate: {
|
|
||||||
contactId: '{{state.contactId}}',
|
|
||||||
petName: '{{state.petName}}',
|
|
||||||
petType: '{{state.petType}}',
|
|
||||||
},
|
|
||||||
outputMapping: { petId: 'petId' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'end',
|
|
||||||
type: 'End',
|
|
||||||
data: { label: 'End' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
edges: [
|
|
||||||
{ id: 'e_start_account', source: 'start', target: 'decide_account' },
|
|
||||||
{
|
|
||||||
id: 'e_account_find',
|
|
||||||
source: 'decide_account',
|
|
||||||
target: 'find_account',
|
|
||||||
condition: { '==': [{ var: 'accountAction' }, 'find'] },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'e_account_create',
|
|
||||||
source: 'decide_account',
|
|
||||||
target: 'create_account',
|
|
||||||
condition: { '==': [{ var: 'accountAction' }, 'create'] },
|
|
||||||
},
|
|
||||||
{ id: 'e_account_to_contact', source: 'find_account', target: 'decide_contact' },
|
|
||||||
{ id: 'e_create_account_to_contact', source: 'create_account', target: 'decide_contact' },
|
|
||||||
{
|
|
||||||
id: 'e_contact_find',
|
|
||||||
source: 'decide_contact',
|
|
||||||
target: 'find_contact',
|
|
||||||
condition: { '==': [{ var: 'contactAction' }, 'find'] },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'e_contact_create',
|
|
||||||
source: 'decide_contact',
|
|
||||||
target: 'create_contact',
|
|
||||||
condition: { '==': [{ var: 'contactAction' }, 'create'] },
|
|
||||||
},
|
|
||||||
{ id: 'e_contact_to_pet', source: 'find_contact', target: 'need_pet' },
|
|
||||||
{ id: 'e_create_contact_to_pet', source: 'create_contact', target: 'need_pet' },
|
|
||||||
{ id: 'e_need_pet_to_create', source: 'need_pet', target: 'create_pet' },
|
|
||||||
{ id: 'e_pet_to_end', source: 'create_pet', target: 'end' },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { IsArray, IsObject, IsOptional, IsString } from 'class-validator';
|
|
||||||
|
|
||||||
export class CreateChatSessionDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
context?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SendChatMessageDto {
|
|
||||||
@IsString()
|
|
||||||
message!: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsArray()
|
|
||||||
history?: { role: string; text: string }[];
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsObject()
|
|
||||||
context?: Record<string, unknown>;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
sessionId?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
processId?: string;
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { IsArray, IsObject, IsOptional, IsString } from 'class-validator';
|
|
||||||
import { ProcessGraphDefinition } from '../ai-processes.types';
|
|
||||||
|
|
||||||
export class CreateAiProcessDto {
|
|
||||||
@IsString()
|
|
||||||
name!: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
description?: string;
|
|
||||||
|
|
||||||
@IsObject()
|
|
||||||
graph!: ProcessGraphDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UpdateAiProcessDto {
|
|
||||||
@IsObject()
|
|
||||||
graph!: ProcessGraphDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiProcessListResponseDto {
|
|
||||||
@IsArray()
|
|
||||||
items!: Record<string, unknown>[];
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { IsObject, IsOptional, IsString } from 'class-validator';
|
|
||||||
|
|
||||||
export class CreateAiRunDto {
|
|
||||||
@IsObject()
|
|
||||||
input!: Record<string, unknown>;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
sessionId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ResumeAiRunDto {
|
|
||||||
@IsObject()
|
|
||||||
input!: Record<string, unknown>;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
sessionId?: string;
|
|
||||||
}
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
import { ToolContext, ToolHandler } from './tool-registry';
|
|
||||||
import { Account } from '../../models/account.model';
|
|
||||||
import { Contact } from '../../models/contact.model';
|
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Demo tools that wrap ObjectService operations
|
|
||||||
* These tools provide structured access to CRM entities
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const findAccount: ToolHandler = async (ctx, args) => {
|
|
||||||
if (!ctx.knex) {
|
|
||||||
throw new Error('Knex connection required for findAccount');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { name } = args as { name?: string };
|
|
||||||
|
|
||||||
if (!name) {
|
|
||||||
return { found: false, accountId: null, message: 'Name required' };
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const query = Account.query(ctx.knex).where('name', 'like', `%${name}%`);
|
|
||||||
|
|
||||||
const account = await query.first();
|
|
||||||
|
|
||||||
if (account) {
|
|
||||||
return {
|
|
||||||
found: true,
|
|
||||||
accountId: account.id,
|
|
||||||
account: {
|
|
||||||
id: account.id,
|
|
||||||
name: account.name,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { found: false, accountId: null };
|
|
||||||
} catch (error: any) {
|
|
||||||
return { found: false, error: error.message };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createAccount: ToolHandler = async (ctx, args) => {
|
|
||||||
if (!ctx.knex) {
|
|
||||||
throw new Error('Knex connection required for createAccount');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { name, email, phone, industry } = args as {
|
|
||||||
name: string;
|
|
||||||
email?: string;
|
|
||||||
phone?: string;
|
|
||||||
industry?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!name) {
|
|
||||||
throw new Error('Account name is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const accountId = randomUUID();
|
|
||||||
await ctx.knex('accounts').insert({
|
|
||||||
id: accountId,
|
|
||||||
name,
|
|
||||||
phone,
|
|
||||||
industry,
|
|
||||||
ownerId: ctx.userId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
accountId,
|
|
||||||
account: {
|
|
||||||
id: accountId,
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
return { success: false, error: error.message };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const findContact: ToolHandler = async (ctx, args) => {
|
|
||||||
if (!ctx.knex) {
|
|
||||||
throw new Error('Knex connection required for findContact');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { firstName, lastName, accountId } = args as {
|
|
||||||
firstName?: string;
|
|
||||||
lastName?: string;
|
|
||||||
accountId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!firstName && !lastName) {
|
|
||||||
return {
|
|
||||||
found: false,
|
|
||||||
contactId: null,
|
|
||||||
message: 'First name or last name required',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let query = Contact.query(ctx.knex);
|
|
||||||
|
|
||||||
if (firstName) {
|
|
||||||
query = query.where('firstName', 'like', `%${firstName}%`);
|
|
||||||
}
|
|
||||||
if (lastName) {
|
|
||||||
query = query.where('lastName', 'like', `%${lastName}%`);
|
|
||||||
}
|
|
||||||
if (accountId) {
|
|
||||||
query = query.where('accountId', accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const contact = await query.first();
|
|
||||||
|
|
||||||
if (contact) {
|
|
||||||
return {
|
|
||||||
found: true,
|
|
||||||
contactId: contact.id,
|
|
||||||
contact: {
|
|
||||||
id: contact.id,
|
|
||||||
firstName: contact.firstName,
|
|
||||||
lastName: contact.lastName,
|
|
||||||
accountId: contact.accountId,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { found: false, contactId: null };
|
|
||||||
} catch (error: any) {
|
|
||||||
return { found: false, error: error.message };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createContact: ToolHandler = async (ctx, args) => {
|
|
||||||
if (!ctx.knex) {
|
|
||||||
throw new Error('Knex connection required for createContact');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { firstName, lastName, email, phone, accountId } = args as {
|
|
||||||
firstName: string;
|
|
||||||
lastName: string;
|
|
||||||
email?: string;
|
|
||||||
phone?: string;
|
|
||||||
accountId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!firstName || !lastName) {
|
|
||||||
throw new Error('First name and last name are required');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const contactId = randomUUID();
|
|
||||||
await ctx.knex('contacts').insert({
|
|
||||||
id: contactId,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
accountId,
|
|
||||||
ownerId: ctx.userId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
contactId,
|
|
||||||
contact: {
|
|
||||||
id: contactId,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
accountId,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
return { success: false, error: error.message };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createPet: ToolHandler = async (ctx, args) => {
|
|
||||||
if (!ctx.knex) {
|
|
||||||
throw new Error('Knex connection required for createPet');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { name, species, breed, age, ownerId } = args as {
|
|
||||||
name: string;
|
|
||||||
species: string;
|
|
||||||
breed?: string;
|
|
||||||
age?: number;
|
|
||||||
ownerId: string; // Contact ID
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!name || !ownerId) {
|
|
||||||
throw new Error('Pet name and owner (contact) are required');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const petId = randomUUID();
|
|
||||||
|
|
||||||
// Get the accountId from the contact
|
|
||||||
const contact = await ctx.knex('contacts').where('id', ownerId).first();
|
|
||||||
|
|
||||||
// Insert into dogs table
|
|
||||||
await ctx.knex('dogs').insert({
|
|
||||||
id: petId,
|
|
||||||
name,
|
|
||||||
ownerId,
|
|
||||||
accountId: contact?.accountId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
petId,
|
|
||||||
pet: { id: petId, name, ownerId, accountId: contact?.accountId },
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
|
||||||
return { success: false, error: error.message };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Export all demo tools
|
|
||||||
export const demoTools = {
|
|
||||||
findAccount,
|
|
||||||
createAccount,
|
|
||||||
findContact,
|
|
||||||
createContact,
|
|
||||||
createPet,
|
|
||||||
};
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { Knex } from 'knex';
|
|
||||||
import { AiToolConfig } from '../../models/ai-process.model';
|
|
||||||
|
|
||||||
export interface ToolContext {
|
|
||||||
tenantId: string;
|
|
||||||
userId: string;
|
|
||||||
knex?: Knex;
|
|
||||||
authScopes?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ToolHandler = (
|
|
||||||
ctx: ToolContext,
|
|
||||||
args: Record<string, unknown>,
|
|
||||||
) => Promise<Record<string, unknown>>;
|
|
||||||
|
|
||||||
export interface ToolDefinition {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
handler: ToolHandler;
|
|
||||||
inputSchema?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultTools: Record<string, ToolHandler> = {
|
|
||||||
findAccount: async () => ({ accountId: null, found: false }),
|
|
||||||
createAccount: async (_ctx, args) => ({ accountId: `acc_${Date.now()}`, args }),
|
|
||||||
findContact: async () => ({ contactId: null, found: false }),
|
|
||||||
createContact: async (_ctx, args) => ({ contactId: `con_${Date.now()}`, args }),
|
|
||||||
createPet: async (_ctx, args) => ({ petId: `pet_${Date.now()}`, args }),
|
|
||||||
};
|
|
||||||
|
|
||||||
const tenantAllowlist: Record<string, string[]> = {
|
|
||||||
default: Object.keys(defaultTools),
|
|
||||||
};
|
|
||||||
|
|
||||||
export class ToolRegistry {
|
|
||||||
private tools: Record<string, ToolHandler>;
|
|
||||||
private allowlist: Record<string, string[]>;
|
|
||||||
private dbAllowlistCache: Map<string, Set<string>> = new Map();
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
tools: Record<string, ToolHandler> = defaultTools,
|
|
||||||
allowlist: Record<string, string[]> = tenantAllowlist,
|
|
||||||
) {
|
|
||||||
this.tools = tools;
|
|
||||||
this.allowlist = allowlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerTool(name: string, handler: ToolHandler) {
|
|
||||||
this.tools[name] = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadTenantAllowlist(tenantId: string, knex: Knex) {
|
|
||||||
const configs = await AiToolConfig.query(knex)
|
|
||||||
.where('enabled', true);
|
|
||||||
|
|
||||||
const allowed = new Set(configs.map((c) => c.toolName));
|
|
||||||
this.dbAllowlistCache.set(tenantId, allowed);
|
|
||||||
return allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
async isToolAllowed(tenantId: string, toolName: string, knex?: Knex) {
|
|
||||||
// Check database cache first
|
|
||||||
if (this.dbAllowlistCache.has(tenantId)) {
|
|
||||||
return this.dbAllowlistCache.get(tenantId)!.has(toolName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load from database if knex provided
|
|
||||||
if (knex) {
|
|
||||||
const allowed = await this.loadTenantAllowlist(tenantId, knex);
|
|
||||||
return allowed.has(toolName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to static allowlist
|
|
||||||
const allowed = this.allowlist[tenantId] || this.allowlist.default || [];
|
|
||||||
return allowed.includes(toolName);
|
|
||||||
}
|
|
||||||
|
|
||||||
getTool(toolName: string): ToolHandler {
|
|
||||||
const tool = this.tools[toolName];
|
|
||||||
if (!tool) {
|
|
||||||
throw new Error(`Tool ${toolName} is not registered.`);
|
|
||||||
}
|
|
||||||
return tool;
|
|
||||||
}
|
|
||||||
|
|
||||||
getAllToolNames(): string[] {
|
|
||||||
return Object.keys(this.tools);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ import { AppBuilderModule } from './app-builder/app-builder.module';
|
|||||||
import { PageLayoutModule } from './page-layout/page-layout.module';
|
import { PageLayoutModule } from './page-layout/page-layout.module';
|
||||||
import { VoiceModule } from './voice/voice.module';
|
import { VoiceModule } from './voice/voice.module';
|
||||||
import { AiAssistantModule } from './ai-assistant/ai-assistant.module';
|
import { AiAssistantModule } from './ai-assistant/ai-assistant.module';
|
||||||
import { AiProcessesModule } from './ai-processes/ai-processes.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -25,7 +24,6 @@ import { AiProcessesModule } from './ai-processes/ai-processes.module';
|
|||||||
PageLayoutModule,
|
PageLayoutModule,
|
||||||
VoiceModule,
|
VoiceModule,
|
||||||
AiAssistantModule,
|
AiAssistantModule,
|
||||||
AiProcessesModule,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { snakeCaseMappers } from 'objection';
|
|
||||||
import { BaseModel } from './base.model';
|
|
||||||
|
|
||||||
export class AiChatSession extends BaseModel {
|
|
||||||
static tableName = 'ai_chat_sessions';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
userId!: string;
|
|
||||||
createdAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert() {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
this.createdAt = this.createdAt || new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
$beforeUpdate() {}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
messages: {
|
|
||||||
relation: BaseModel.HasManyRelation,
|
|
||||||
modelClass: AiChatMessage,
|
|
||||||
join: {
|
|
||||||
from: 'ai_chat_sessions.id',
|
|
||||||
to: 'ai_chat_messages.session_id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiChatMessage extends BaseModel {
|
|
||||||
static tableName = 'ai_chat_messages';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
sessionId!: string;
|
|
||||||
role!: string;
|
|
||||||
content!: string;
|
|
||||||
createdAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert() {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
this.createdAt = this.createdAt || new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
$beforeUpdate() {}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
session: {
|
|
||||||
relation: BaseModel.BelongsToOneRelation,
|
|
||||||
modelClass: AiChatSession,
|
|
||||||
join: {
|
|
||||||
from: 'ai_chat_messages.session_id',
|
|
||||||
to: 'ai_chat_sessions.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { QueryContext, snakeCaseMappers } from 'objection';
|
|
||||||
import { BaseModel } from './base.model';
|
|
||||||
|
|
||||||
export class AiProcess extends BaseModel {
|
|
||||||
static tableName = 'ai_processes';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
name!: string;
|
|
||||||
description?: string;
|
|
||||||
latestVersion!: number;
|
|
||||||
createdBy!: string;
|
|
||||||
createdAt!: Date;
|
|
||||||
updatedAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert(queryContext: QueryContext) {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
super.$beforeInsert(queryContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
versions: {
|
|
||||||
relation: BaseModel.HasManyRelation,
|
|
||||||
modelClass: AiProcessVersion,
|
|
||||||
join: {
|
|
||||||
from: 'ai_processes.id',
|
|
||||||
to: 'ai_process_versions.process_id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
runs: {
|
|
||||||
relation: BaseModel.HasManyRelation,
|
|
||||||
modelClass: AiProcessRun,
|
|
||||||
join: {
|
|
||||||
from: 'ai_processes.id',
|
|
||||||
to: 'ai_process_runs.process_id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiProcessVersion extends BaseModel {
|
|
||||||
static tableName = 'ai_process_versions';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
static jsonAttributes = ['graphJson', 'compiledJson'];
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
processId!: string;
|
|
||||||
version!: number;
|
|
||||||
graphJson!: Record<string, unknown>;
|
|
||||||
compiledJson!: Record<string, unknown>;
|
|
||||||
createdBy!: string;
|
|
||||||
createdAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert() {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
this.createdAt = this.createdAt || new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
$beforeUpdate() {}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
process: {
|
|
||||||
relation: BaseModel.BelongsToOneRelation,
|
|
||||||
modelClass: AiProcess,
|
|
||||||
join: {
|
|
||||||
from: 'ai_process_versions.process_id',
|
|
||||||
to: 'ai_processes.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiProcessRun extends BaseModel {
|
|
||||||
static tableName = 'ai_process_runs';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
static jsonAttributes = ['inputJson', 'outputJson', 'errorJson', 'stateJson'];
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
processId!: string;
|
|
||||||
version!: number;
|
|
||||||
status!: string;
|
|
||||||
inputJson!: Record<string, unknown>;
|
|
||||||
outputJson?: Record<string, unknown> | null;
|
|
||||||
errorJson?: Record<string, unknown> | null;
|
|
||||||
stateJson?: Record<string, unknown>;
|
|
||||||
currentNodeId?: string | null;
|
|
||||||
startedAt?: Date;
|
|
||||||
endedAt?: Date | null;
|
|
||||||
|
|
||||||
$beforeInsert() {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
this.startedAt = this.startedAt || new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
$beforeUpdate() {}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
process: {
|
|
||||||
relation: BaseModel.BelongsToOneRelation,
|
|
||||||
modelClass: AiProcess,
|
|
||||||
join: {
|
|
||||||
from: 'ai_process_runs.process_id',
|
|
||||||
to: 'ai_processes.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiAuditEvent extends BaseModel {
|
|
||||||
static tableName = 'ai_audit_events';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
static jsonAttributes = ['payloadJson'];
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
runId!: string;
|
|
||||||
eventType!: string;
|
|
||||||
payloadJson!: Record<string, unknown>;
|
|
||||||
createdAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert() {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
this.createdAt = this.createdAt || new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
$beforeUpdate() {}
|
|
||||||
|
|
||||||
static get relationMappings() {
|
|
||||||
return {
|
|
||||||
run: {
|
|
||||||
relation: BaseModel.BelongsToOneRelation,
|
|
||||||
modelClass: AiProcessRun,
|
|
||||||
join: {
|
|
||||||
from: 'ai_audit_events.run_id',
|
|
||||||
to: 'ai_process_runs.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AiToolConfig extends BaseModel {
|
|
||||||
static tableName = 'ai_tool_configs';
|
|
||||||
static columnNameMappers = snakeCaseMappers();
|
|
||||||
static jsonAttributes = ['configJson'];
|
|
||||||
|
|
||||||
id!: string;
|
|
||||||
toolName!: string;
|
|
||||||
enabled!: boolean;
|
|
||||||
configJson?: Record<string, unknown>;
|
|
||||||
createdAt!: Date;
|
|
||||||
updatedAt!: Date;
|
|
||||||
|
|
||||||
$beforeInsert(queryContext: QueryContext) {
|
|
||||||
this.id = this.id || randomUUID();
|
|
||||||
super.$beforeInsert(queryContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -79,6 +79,10 @@ export class FieldMapperService {
|
|||||||
const frontendType = this.mapFieldType(field.type);
|
const frontendType = this.mapFieldType(field.type);
|
||||||
const isLookupField = frontendType === 'belongsTo' || field.type.toLowerCase().includes('lookup');
|
const isLookupField = frontendType === 'belongsTo' || field.type.toLowerCase().includes('lookup');
|
||||||
|
|
||||||
|
// Hide 'id' field from list view by default
|
||||||
|
const isIdField = field.apiName === 'id';
|
||||||
|
const defaultShowOnList = isIdField ? false : true;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: field.id,
|
id: field.id,
|
||||||
apiName: field.apiName,
|
apiName: field.apiName,
|
||||||
@@ -95,7 +99,7 @@ export class FieldMapperService {
|
|||||||
isReadOnly: field.isSystem || uiMetadata.isReadOnly || false,
|
isReadOnly: field.isSystem || uiMetadata.isReadOnly || false,
|
||||||
|
|
||||||
// View visibility
|
// View visibility
|
||||||
showOnList: uiMetadata.showOnList !== false,
|
showOnList: uiMetadata.showOnList !== undefined ? uiMetadata.showOnList : defaultShowOnList,
|
||||||
showOnDetail: uiMetadata.showOnDetail !== false,
|
showOnDetail: uiMetadata.showOnDetail !== false,
|
||||||
showOnEdit: uiMetadata.showOnEdit !== false && !field.isSystem,
|
showOnEdit: uiMetadata.showOnEdit !== false && !field.isSystem,
|
||||||
sortable: uiMetadata.sortable !== false,
|
sortable: uiMetadata.sortable !== false,
|
||||||
@@ -141,6 +145,7 @@ export class FieldMapperService {
|
|||||||
'boolean': 'boolean',
|
'boolean': 'boolean',
|
||||||
'date': 'date',
|
'date': 'date',
|
||||||
'datetime': 'datetime',
|
'datetime': 'datetime',
|
||||||
|
'date_time': 'datetime',
|
||||||
'time': 'time',
|
'time': 'time',
|
||||||
'email': 'email',
|
'email': 'email',
|
||||||
'url': 'url',
|
'url': 'url',
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { IsString, IsUUID, IsBoolean, IsOptional, IsObject } from 'class-validator';
|
import { IsString, IsUUID, IsBoolean, IsOptional, IsObject, IsIn } from 'class-validator';
|
||||||
|
|
||||||
|
export type PageLayoutType = 'detail' | 'list';
|
||||||
|
|
||||||
export class CreatePageLayoutDto {
|
export class CreatePageLayoutDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -7,18 +9,25 @@ export class CreatePageLayoutDto {
|
|||||||
@IsUUID()
|
@IsUUID()
|
||||||
objectId: string;
|
objectId: string;
|
||||||
|
|
||||||
|
@IsIn(['detail', 'list'])
|
||||||
|
@IsOptional()
|
||||||
|
layoutType?: PageLayoutType = 'detail';
|
||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
isDefault?: boolean;
|
isDefault?: boolean;
|
||||||
|
|
||||||
@IsObject()
|
@IsObject()
|
||||||
layoutConfig: {
|
layoutConfig: {
|
||||||
|
// For detail layouts: grid-based field positions
|
||||||
fields: Array<{
|
fields: Array<{
|
||||||
fieldId: string;
|
fieldId: string;
|
||||||
x: number;
|
x?: number;
|
||||||
y: number;
|
y?: number;
|
||||||
w: number;
|
w?: number;
|
||||||
h: number;
|
h?: number;
|
||||||
|
// For list layouts: field order (optional, defaults to array index)
|
||||||
|
order?: number;
|
||||||
}>;
|
}>;
|
||||||
relatedLists?: string[];
|
relatedLists?: string[];
|
||||||
};
|
};
|
||||||
@@ -42,10 +51,11 @@ export class UpdatePageLayoutDto {
|
|||||||
layoutConfig?: {
|
layoutConfig?: {
|
||||||
fields: Array<{
|
fields: Array<{
|
||||||
fieldId: string;
|
fieldId: string;
|
||||||
x: number;
|
x?: number;
|
||||||
y: number;
|
y?: number;
|
||||||
w: number;
|
w?: number;
|
||||||
h: number;
|
h?: number;
|
||||||
|
order?: number;
|
||||||
}>;
|
}>;
|
||||||
relatedLists?: string[];
|
relatedLists?: string[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PageLayoutService } from './page-layout.service';
|
import { PageLayoutService } from './page-layout.service';
|
||||||
import { CreatePageLayoutDto, UpdatePageLayoutDto } from './dto/page-layout.dto';
|
import { CreatePageLayoutDto, UpdatePageLayoutDto, PageLayoutType } from './dto/page-layout.dto';
|
||||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||||
import { TenantId } from '../tenant/tenant.decorator';
|
import { TenantId } from '../tenant/tenant.decorator';
|
||||||
|
|
||||||
@@ -25,13 +25,21 @@ export class PageLayoutController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
findAll(@TenantId() tenantId: string, @Query('objectId') objectId?: string) {
|
findAll(
|
||||||
return this.pageLayoutService.findAll(tenantId, objectId);
|
@TenantId() tenantId: string,
|
||||||
|
@Query('objectId') objectId?: string,
|
||||||
|
@Query('layoutType') layoutType?: PageLayoutType,
|
||||||
|
) {
|
||||||
|
return this.pageLayoutService.findAll(tenantId, objectId, layoutType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('default/:objectId')
|
@Get('default/:objectId')
|
||||||
findDefaultByObject(@TenantId() tenantId: string, @Param('objectId') objectId: string) {
|
findDefaultByObject(
|
||||||
return this.pageLayoutService.findDefaultByObject(tenantId, objectId);
|
@TenantId() tenantId: string,
|
||||||
|
@Param('objectId') objectId: string,
|
||||||
|
@Query('layoutType') layoutType?: PageLayoutType,
|
||||||
|
) {
|
||||||
|
return this.pageLayoutService.findDefaultByObject(tenantId, objectId, layoutType || 'detail');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { TenantDatabaseService } from '../tenant/tenant-database.service';
|
import { TenantDatabaseService } from '../tenant/tenant-database.service';
|
||||||
import { CreatePageLayoutDto, UpdatePageLayoutDto } from './dto/page-layout.dto';
|
import { CreatePageLayoutDto, UpdatePageLayoutDto, PageLayoutType } from './dto/page-layout.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PageLayoutService {
|
export class PageLayoutService {
|
||||||
@@ -8,17 +8,19 @@ export class PageLayoutService {
|
|||||||
|
|
||||||
async create(tenantId: string, createDto: CreatePageLayoutDto) {
|
async create(tenantId: string, createDto: CreatePageLayoutDto) {
|
||||||
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
||||||
|
const layoutType = createDto.layoutType || 'detail';
|
||||||
|
|
||||||
// If this layout is set as default, unset other defaults for the same object
|
// If this layout is set as default, unset other defaults for the same object and layout type
|
||||||
if (createDto.isDefault) {
|
if (createDto.isDefault) {
|
||||||
await knex('page_layouts')
|
await knex('page_layouts')
|
||||||
.where({ object_id: createDto.objectId })
|
.where({ object_id: createDto.objectId, layout_type: layoutType })
|
||||||
.update({ is_default: false });
|
.update({ is_default: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
const [id] = await knex('page_layouts').insert({
|
const [id] = await knex('page_layouts').insert({
|
||||||
name: createDto.name,
|
name: createDto.name,
|
||||||
object_id: createDto.objectId,
|
object_id: createDto.objectId,
|
||||||
|
layout_type: layoutType,
|
||||||
is_default: createDto.isDefault || false,
|
is_default: createDto.isDefault || false,
|
||||||
layout_config: JSON.stringify(createDto.layoutConfig),
|
layout_config: JSON.stringify(createDto.layoutConfig),
|
||||||
description: createDto.description || null,
|
description: createDto.description || null,
|
||||||
@@ -29,7 +31,7 @@ export class PageLayoutService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(tenantId: string, objectId?: string) {
|
async findAll(tenantId: string, objectId?: string, layoutType?: PageLayoutType) {
|
||||||
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
||||||
|
|
||||||
let query = knex('page_layouts');
|
let query = knex('page_layouts');
|
||||||
@@ -38,6 +40,10 @@ export class PageLayoutService {
|
|||||||
query = query.where({ object_id: objectId });
|
query = query.where({ object_id: objectId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (layoutType) {
|
||||||
|
query = query.where({ layout_type: layoutType });
|
||||||
|
}
|
||||||
|
|
||||||
const layouts = await query.orderByRaw('is_default DESC, name ASC');
|
const layouts = await query.orderByRaw('is_default DESC, name ASC');
|
||||||
return layouts;
|
return layouts;
|
||||||
}
|
}
|
||||||
@@ -54,11 +60,11 @@ export class PageLayoutService {
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findDefaultByObject(tenantId: string, objectId: string) {
|
async findDefaultByObject(tenantId: string, objectId: string, layoutType: PageLayoutType = 'detail') {
|
||||||
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
||||||
|
|
||||||
const layout = await knex('page_layouts')
|
const layout = await knex('page_layouts')
|
||||||
.where({ object_id: objectId, is_default: true })
|
.where({ object_id: objectId, is_default: true, layout_type: layoutType })
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
return layout || null;
|
return layout || null;
|
||||||
@@ -68,13 +74,12 @@ export class PageLayoutService {
|
|||||||
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
const knex = await this.tenantDbService.getTenantKnex(tenantId);
|
||||||
|
|
||||||
// Check if layout exists
|
// Check if layout exists
|
||||||
await this.findOne(tenantId, id);
|
const layout = await this.findOne(tenantId, id);
|
||||||
|
|
||||||
// If setting as default, unset other defaults for the same object
|
// If setting as default, unset other defaults for the same object and layout type
|
||||||
if (updateDto.isDefault) {
|
if (updateDto.isDefault) {
|
||||||
const layout = await this.findOne(tenantId, id);
|
|
||||||
await knex('page_layouts')
|
await knex('page_layouts')
|
||||||
.where({ object_id: layout.object_id })
|
.where({ object_id: layout.object_id, layout_type: layout.layout_type })
|
||||||
.whereNot({ id })
|
.whereNot({ id })
|
||||||
.update({ is_default: false });
|
.update({ is_default: false });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,9 +110,8 @@ export class TenantDatabaseService {
|
|||||||
* @deprecated Use getTenantKnexByDomain or getTenantKnexById instead
|
* @deprecated Use getTenantKnexByDomain or getTenantKnexById instead
|
||||||
*/
|
*/
|
||||||
async getTenantKnex(tenantIdOrSlug: string): Promise<Knex> {
|
async getTenantKnex(tenantIdOrSlug: string): Promise<Knex> {
|
||||||
// Resolve tenant ID first, then get connection by ID
|
// Assume it's a domain if it contains a dot
|
||||||
const tenantId = await this.resolveTenantId(tenantIdOrSlug);
|
return this.getTenantKnexByDomain(tenantIdOrSlug);
|
||||||
return this.getTenantKnexById(tenantId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>AI Process Builder</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/main.tsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ai-processes-editor",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.1.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite --port 5174",
|
|
||||||
"build": "vite build",
|
|
||||||
"preview": "vite preview --port 5174"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@xyflow/react": "^12.0.4",
|
|
||||||
"react": "^18.3.1",
|
|
||||||
"react-dom": "^18.3.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/react": "^18.3.4",
|
|
||||||
"@types/react-dom": "^18.3.0",
|
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
|
||||||
"typescript": "^5.6.2",
|
|
||||||
"vite": "^5.4.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import { useCallback, useEffect } from 'react'
|
|
||||||
import {
|
|
||||||
Background,
|
|
||||||
Controls,
|
|
||||||
MiniMap,
|
|
||||||
ReactFlow,
|
|
||||||
useEdgesState,
|
|
||||||
useNodesState,
|
|
||||||
addEdge,
|
|
||||||
Connection,
|
|
||||||
Edge,
|
|
||||||
Node,
|
|
||||||
Panel,
|
|
||||||
} from '@xyflow/react'
|
|
||||||
import '@xyflow/react/dist/style.css'
|
|
||||||
import './styles.css'
|
|
||||||
|
|
||||||
const nodeTypes = {
|
|
||||||
Start: { style: { background: '#22c55e', color: 'white', padding: 10, borderRadius: 5 } },
|
|
||||||
LLMDecisionNode: { style: { background: '#3b82f6', color: 'white', padding: 10, borderRadius: 5 } },
|
|
||||||
ToolNode: { style: { background: '#f59e0b', color: 'white', padding: 10, borderRadius: 5 } },
|
|
||||||
HumanInputNode: { style: { background: '#8b5cf6', color: 'white', padding: 10, borderRadius: 5 } },
|
|
||||||
End: { style: { background: '#ef4444', color: 'white', padding: 10, borderRadius: 5 } },
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialNodes: Node[] = [
|
|
||||||
{
|
|
||||||
id: 'start-1',
|
|
||||||
type: 'default',
|
|
||||||
data: { label: '🟢 Start', type: 'Start' },
|
|
||||||
position: { x: 250, y: 50 },
|
|
||||||
style: nodeTypes.Start.style,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'end-1',
|
|
||||||
type: 'default',
|
|
||||||
data: { label: '🔴 End', type: 'End' },
|
|
||||||
position: { x: 250, y: 400 },
|
|
||||||
style: nodeTypes.End.style,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const initialEdges: Edge[] = []
|
|
||||||
|
|
||||||
export const App = () => {
|
|
||||||
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes)
|
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges)
|
|
||||||
|
|
||||||
const onConnect = useCallback(
|
|
||||||
(params: Connection) => setEdges((eds) => addEdge(params, eds)),
|
|
||||||
[setEdges]
|
|
||||||
)
|
|
||||||
|
|
||||||
// Send graph updates to parent window
|
|
||||||
const notifyParent = useCallback(() => {
|
|
||||||
const graphData = {
|
|
||||||
id: 'process-graph',
|
|
||||||
name: 'Process',
|
|
||||||
nodes: nodes.map((node) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: node.data.type || 'Start',
|
|
||||||
position: node.position,
|
|
||||||
data: node.data,
|
|
||||||
})),
|
|
||||||
edges: edges.map((edge) => ({
|
|
||||||
id: edge.id,
|
|
||||||
source: edge.source,
|
|
||||||
target: edge.target,
|
|
||||||
condition: edge.data?.condition,
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
|
|
||||||
window.parent.postMessage(
|
|
||||||
{
|
|
||||||
type: 'GRAPH_UPDATED',
|
|
||||||
payload: graphData,
|
|
||||||
},
|
|
||||||
'*'
|
|
||||||
)
|
|
||||||
}, [nodes, edges])
|
|
||||||
|
|
||||||
// Listen for graph load from parent
|
|
||||||
useEffect(() => {
|
|
||||||
const handleMessage = (event: MessageEvent) => {
|
|
||||||
if (event.data.type === 'LOAD_GRAPH') {
|
|
||||||
const graph = event.data.payload
|
|
||||||
if (graph && graph.nodes && graph.edges) {
|
|
||||||
setNodes(
|
|
||||||
graph.nodes.map((node: any) => ({
|
|
||||||
id: node.id,
|
|
||||||
type: 'default',
|
|
||||||
data: { label: node.data.label || node.type, ...node.data },
|
|
||||||
position: node.position,
|
|
||||||
style: nodeTypes[node.type as keyof typeof nodeTypes]?.style || {},
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
setEdges(
|
|
||||||
graph.edges.map((edge: any) => ({
|
|
||||||
id: edge.id,
|
|
||||||
source: edge.source,
|
|
||||||
target: edge.target,
|
|
||||||
data: edge.condition ? { condition: edge.condition } : undefined,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('message', handleMessage)
|
|
||||||
return () => window.removeEventListener('message', handleMessage)
|
|
||||||
}, [setNodes, setEdges])
|
|
||||||
|
|
||||||
// Notify parent on changes
|
|
||||||
useEffect(() => {
|
|
||||||
notifyParent()
|
|
||||||
}, [nodes, edges, notifyParent])
|
|
||||||
|
|
||||||
const addNode = (type: string) => {
|
|
||||||
const newNode: Node = {
|
|
||||||
id: `${type.toLowerCase()}-${Date.now()}`,
|
|
||||||
type: 'default',
|
|
||||||
data: { label: `${type}`, type },
|
|
||||||
position: { x: Math.random() * 400 + 50, y: Math.random() * 300 + 100 },
|
|
||||||
style: nodeTypes[type as keyof typeof nodeTypes]?.style || {},
|
|
||||||
}
|
|
||||||
setNodes((nds) => nds.concat(newNode))
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="editor-shell">
|
|
||||||
<ReactFlow
|
|
||||||
nodes={nodes}
|
|
||||||
edges={edges}
|
|
||||||
onNodesChange={onNodesChange}
|
|
||||||
onEdgesChange={onEdgesChange}
|
|
||||||
onConnect={onConnect}
|
|
||||||
fitView
|
|
||||||
>
|
|
||||||
<Panel position="top-left" className="node-palette">
|
|
||||||
<h3>Node Palette</h3>
|
|
||||||
<button onClick={() => addNode('LLMDecisionNode')}>🔵 LLM Decision</button>
|
|
||||||
<button onClick={() => addNode('ToolNode')}>🟠 Tool</button>
|
|
||||||
<button onClick={() => addNode('HumanInputNode')}>🟣 Human Input</button>
|
|
||||||
<button onClick={() => addNode('End')}>🔴 End</button>
|
|
||||||
</Panel>
|
|
||||||
<MiniMap />
|
|
||||||
<Controls />
|
|
||||||
<Background />
|
|
||||||
</ReactFlow>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import { createRoot } from 'react-dom/client'
|
|
||||||
import { App } from './App'
|
|
||||||
|
|
||||||
const root = document.getElementById('root')
|
|
||||||
if (root) {
|
|
||||||
createRoot(root).render(<App />)
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
color: #0f172a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root {
|
|
||||||
width: 100%;
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.editor-shell {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100vh;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-palette {
|
|
||||||
background: white;
|
|
||||||
border: 1px solid #e2e8f0;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 12px;
|
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
||||||
min-width: 150px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-palette h3 {
|
|
||||||
margin: 0 0 12px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #1e293b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-palette button {
|
|
||||||
display: block;
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px 12px;
|
|
||||||
margin-bottom: 6px;
|
|
||||||
background: white;
|
|
||||||
border: 1px solid #e2e8f0;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-size: 13px;
|
|
||||||
cursor: pointer;
|
|
||||||
text-align: left;
|
|
||||||
transition: all 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-palette button:hover {
|
|
||||||
background: #f1f5f9;
|
|
||||||
border-color: #cbd5e1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-palette button:active {
|
|
||||||
background: #e2e8f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__node {
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__edge-path {
|
|
||||||
stroke: #64748b;
|
|
||||||
stroke-width: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__edge.selected .react-flow__edge-path {
|
|
||||||
stroke: #3b82f6;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
import react from '@vitejs/plugin-react'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [react()],
|
|
||||||
server: {
|
|
||||||
port: 5174,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@@ -7,36 +7,15 @@ import {
|
|||||||
InputGroupText,
|
InputGroupText,
|
||||||
} from '@/components/ui/input-group'
|
} from '@/components/ui/input-group'
|
||||||
import { Separator } from '@/components/ui/separator'
|
import { Separator } from '@/components/ui/separator'
|
||||||
import { ArrowUp, Loader2 } from 'lucide-vue-next'
|
import { ArrowUp } from 'lucide-vue-next'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { useApi } from '@/composables/useApi'
|
import { useApi } from '@/composables/useApi'
|
||||||
|
|
||||||
interface ChatMessage {
|
|
||||||
role: 'user' | 'assistant' | 'system';
|
|
||||||
text: string;
|
|
||||||
isStreaming?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface StreamEvent {
|
|
||||||
type: string;
|
|
||||||
data?: any;
|
|
||||||
processId?: string;
|
|
||||||
nodeId?: string;
|
|
||||||
toolName?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatInput = ref('')
|
const chatInput = ref('')
|
||||||
const messages = ref<ChatMessage[]>([])
|
const messages = ref<{ role: 'user' | 'assistant'; text: string }[]>([])
|
||||||
const sending = ref(false)
|
const sending = ref(false)
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { api } = useApi()
|
const { api } = useApi()
|
||||||
const sessionId = ref<string | null>(null)
|
|
||||||
const eventSource = ref<EventSource | null>(null)
|
|
||||||
|
|
||||||
const getTenantId = () => {
|
|
||||||
if (!import.meta.client) return 'tenant1'
|
|
||||||
return localStorage.getItem('tenantId') || 'tenant1'
|
|
||||||
}
|
|
||||||
|
|
||||||
const buildContext = () => {
|
const buildContext = () => {
|
||||||
const recordId = route.params.recordId ? String(route.params.recordId) : undefined
|
const recordId = route.params.recordId ? String(route.params.recordId) : undefined
|
||||||
@@ -54,97 +33,6 @@ const buildContext = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectToStream = (sessionIdValue: string) => {
|
|
||||||
if (eventSource.value) {
|
|
||||||
eventSource.value.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseUrl = window.location.hostname === 'localhost'
|
|
||||||
? 'http://localhost:3000'
|
|
||||||
: `https://${window.location.hostname}`
|
|
||||||
|
|
||||||
eventSource.value = new EventSource(
|
|
||||||
`${baseUrl}/tenants/${getTenantId()}/ai-chat/stream?sessionId=${sessionIdValue}`
|
|
||||||
)
|
|
||||||
|
|
||||||
eventSource.value.onmessage = (event) => {
|
|
||||||
try {
|
|
||||||
const payload: StreamEvent = JSON.parse(event.data)
|
|
||||||
handleStreamEvent(payload)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to parse stream event:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventSource.value.onerror = () => {
|
|
||||||
eventSource.value?.close()
|
|
||||||
eventSource.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleStreamEvent = (event: StreamEvent) => {
|
|
||||||
switch (event.type) {
|
|
||||||
case 'agent_started':
|
|
||||||
// Agent is thinking
|
|
||||||
break
|
|
||||||
case 'processes_listed':
|
|
||||||
// Processes discovered
|
|
||||||
break
|
|
||||||
case 'process_selected':
|
|
||||||
messages.value.push({
|
|
||||||
role: 'system',
|
|
||||||
text: `🔄 Selected process: ${event.data?.processName || 'Process'}`,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
case 'agent_message':
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: event.data?.message || '',
|
|
||||||
})
|
|
||||||
break
|
|
||||||
case 'node_started':
|
|
||||||
const lastMsg = messages.value[messages.value.length - 1]
|
|
||||||
if (lastMsg?.isStreaming) {
|
|
||||||
lastMsg.text += `\n⚙️ Executing step...`
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'tool_called':
|
|
||||||
const lastToolMsg = messages.value[messages.value.length - 1]
|
|
||||||
if (lastToolMsg?.isStreaming) {
|
|
||||||
lastToolMsg.text += `\n🔧 Using tool: ${event.toolName}`
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'need_input':
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: event.data?.prompt || 'I need some additional information from you.',
|
|
||||||
})
|
|
||||||
sending.value = false
|
|
||||||
break
|
|
||||||
case 'final':
|
|
||||||
if (event.data?.output) {
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: event.data.message || '✅ Process completed successfully!',
|
|
||||||
})
|
|
||||||
} else if (event.data?.reply) {
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: event.data.reply,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
sending.value = false
|
|
||||||
break
|
|
||||||
case 'error':
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: `❌ Error: ${event.data?.error || 'An error occurred'}`,
|
|
||||||
})
|
|
||||||
sending.value = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSend = async () => {
|
const handleSend = async () => {
|
||||||
if (!chatInput.value.trim()) return
|
if (!chatInput.value.trim()) return
|
||||||
|
|
||||||
@@ -153,53 +41,31 @@ const handleSend = async () => {
|
|||||||
chatInput.value = ''
|
chatInput.value = ''
|
||||||
sending.value = true
|
sending.value = true
|
||||||
|
|
||||||
// Add a streaming message placeholder
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: '🤔 Thinking...',
|
|
||||||
isStreaming: true
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const history = messages.value
|
const history = messages.value.slice(0, -1).slice(-6)
|
||||||
.filter(m => m.role !== 'system' && !m.isStreaming)
|
const response = await api.post('/ai/chat', {
|
||||||
.slice(0, -1)
|
|
||||||
.slice(-6)
|
|
||||||
.map(m => ({ role: m.role, text: m.text }))
|
|
||||||
|
|
||||||
const response = await api.post(`/tenants/${getTenantId()}/ai-chat/messages`, {
|
|
||||||
message,
|
message,
|
||||||
history,
|
history,
|
||||||
context: buildContext(),
|
context: buildContext(),
|
||||||
sessionId: sessionId.value || undefined,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.sessionId && !sessionId.value) {
|
messages.value.push({
|
||||||
sessionId.value = response.sessionId
|
role: 'assistant',
|
||||||
connectToStream(response.sessionId)
|
text: response.reply || 'Let me know what else you need.',
|
||||||
}
|
})
|
||||||
|
|
||||||
// Remove streaming placeholder and add response
|
if (response.action === 'create_record') {
|
||||||
messages.value = messages.value.filter(m => !m.isStreaming)
|
window.dispatchEvent(
|
||||||
|
new CustomEvent('ai-record-created', {
|
||||||
if (response.reply) {
|
detail: {
|
||||||
messages.value.push({
|
objectApiName: buildContext().objectApiName,
|
||||||
role: 'assistant',
|
record: response.record,
|
||||||
text: response.reply,
|
},
|
||||||
})
|
}),
|
||||||
}
|
)
|
||||||
|
|
||||||
// If process is running, stream will handle updates
|
|
||||||
if (response.runId) {
|
|
||||||
messages.value.push({
|
|
||||||
role: 'assistant',
|
|
||||||
text: '⏳ Processing workflow...',
|
|
||||||
isStreaming: true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Failed to send AI chat message:', error)
|
console.error('Failed to send AI chat message:', error)
|
||||||
messages.value = messages.value.filter(m => !m.isStreaming)
|
|
||||||
messages.value.push({
|
messages.value.push({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
text: error.message || 'Sorry, I ran into an error. Please try again.',
|
text: error.message || 'Sorry, I ran into an error. Please try again.',
|
||||||
@@ -208,17 +74,11 @@ const handleSend = async () => {
|
|||||||
sending.value = false
|
sending.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
if (eventSource.value) {
|
|
||||||
eventSource.value.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="ai-chat-area w-full border-t border-border p-4 bg-neutral-50">
|
<div class="ai-chat-area w-full border-t border-border p-4 bg-neutral-50">
|
||||||
<div class="ai-chat-messages mb-4 space-y-3 max-h-[400px] overflow-y-auto">
|
<div class="ai-chat-messages mb-4 space-y-3">
|
||||||
<div
|
<div
|
||||||
v-for="(message, index) in messages"
|
v-for="(message, index) in messages"
|
||||||
:key="`${message.role}-${index}`"
|
:key="`${message.role}-${index}`"
|
||||||
@@ -226,19 +86,14 @@ onUnmounted(() => {
|
|||||||
:class="message.role === 'user' ? 'justify-end' : 'justify-start'"
|
:class="message.role === 'user' ? 'justify-end' : 'justify-start'"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="max-w-[80%] rounded-lg px-3 py-2 text-sm whitespace-pre-line"
|
class="max-w-[80%] rounded-lg px-3 py-2 text-sm"
|
||||||
:class="{
|
:class="message.role === 'user' ? 'bg-primary text-primary-foreground' : 'bg-white border border-border text-foreground'"
|
||||||
'bg-primary text-primary-foreground': message.role === 'user',
|
|
||||||
'bg-white border border-border text-foreground': message.role === 'assistant',
|
|
||||||
'bg-blue-50 border border-blue-200 text-blue-900 text-xs': message.role === 'system',
|
|
||||||
}"
|
|
||||||
>
|
>
|
||||||
<Loader2 v-if="message.isStreaming" class="inline-block size-3 animate-spin mr-1" />
|
|
||||||
{{ message.text }}
|
{{ message.text }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="messages.length === 0" class="text-sm text-muted-foreground">
|
<p v-if="messages.length === 0" class="text-sm text-muted-foreground">
|
||||||
Ask the assistant to execute business processes, add records, or answer questions.
|
Ask the assistant to add records, filter lists, or summarize the page.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
|
|||||||
264
frontend/components/ListViewLayoutEditor.vue
Normal file
264
frontend/components/ListViewLayoutEditor.vue
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
<template>
|
||||||
|
<div class="list-view-layout-editor">
|
||||||
|
<div class="flex h-full">
|
||||||
|
<!-- Selected Fields Area -->
|
||||||
|
<div class="flex-1 p-4 overflow-auto">
|
||||||
|
<div class="mb-4 flex justify-between items-center">
|
||||||
|
<h3 class="text-lg font-semibold">{{ layoutName || 'List View Layout' }}</h3>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<Button variant="outline" size="sm" @click="handleClear">
|
||||||
|
Clear All
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" @click="handleSave">
|
||||||
|
Save Layout
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="border rounded-lg bg-slate-50 dark:bg-slate-900 p-4 min-h-[400px]">
|
||||||
|
<p class="text-sm text-muted-foreground mb-4">
|
||||||
|
Drag fields to reorder them. Fields will appear in the list view in this order.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div v-if="selectedFields.length === 0" class="text-center py-8 text-muted-foreground">
|
||||||
|
<p>No fields selected.</p>
|
||||||
|
<p class="text-sm">Click or drag fields from the right panel to add them.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
ref="sortableContainer"
|
||||||
|
class="space-y-2"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="(field, index) in selectedFields"
|
||||||
|
:key="field.id"
|
||||||
|
class="p-3 border rounded cursor-move bg-white dark:bg-slate-800 hover:border-primary transition-colors flex items-center justify-between"
|
||||||
|
draggable="true"
|
||||||
|
@dragstart="handleDragStart($event, index)"
|
||||||
|
@dragover.prevent="handleDragOver($event, index)"
|
||||||
|
@drop="handleDrop($event, index)"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<span class="text-muted-foreground cursor-grab">
|
||||||
|
<GripVertical class="w-4 h-4" />
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<div class="font-medium text-sm">{{ field.label }}</div>
|
||||||
|
<div class="text-xs text-muted-foreground">
|
||||||
|
{{ field.apiName }} • {{ formatFieldType(field.type) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
class="text-destructive hover:text-destructive"
|
||||||
|
@click="removeField(field.id)"
|
||||||
|
>
|
||||||
|
<X class="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Available Fields Sidebar -->
|
||||||
|
<div class="w-80 border-l bg-white dark:bg-slate-950 p-4 overflow-auto">
|
||||||
|
<h3 class="text-lg font-semibold mb-4">Available Fields</h3>
|
||||||
|
<p class="text-xs text-muted-foreground mb-4">Click or drag to add field to list</p>
|
||||||
|
|
||||||
|
<div v-if="availableFields.length === 0" class="text-center py-4 text-muted-foreground text-sm">
|
||||||
|
All fields have been added to the layout.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="space-y-2">
|
||||||
|
<div
|
||||||
|
v-for="field in availableFields"
|
||||||
|
:key="field.id"
|
||||||
|
class="p-3 border rounded cursor-pointer bg-white dark:bg-slate-900 hover:border-primary hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors"
|
||||||
|
draggable="true"
|
||||||
|
@dragstart="handleAvailableFieldDragStart($event, field)"
|
||||||
|
@click="addField(field)"
|
||||||
|
>
|
||||||
|
<div class="font-medium text-sm">{{ field.label }}</div>
|
||||||
|
<div class="text-xs text-muted-foreground">
|
||||||
|
{{ field.apiName }} • {{ formatFieldType(field.type) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch } from 'vue'
|
||||||
|
import { GripVertical, X } from 'lucide-vue-next'
|
||||||
|
import type { FieldLayoutItem } from '~/types/page-layout'
|
||||||
|
import type { FieldConfig } from '~/types/field-types'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
fields: FieldConfig[]
|
||||||
|
initialLayout?: FieldLayoutItem[]
|
||||||
|
layoutName?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
save: [layout: { fields: FieldLayoutItem[] }]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// Selected fields in order
|
||||||
|
const selectedFieldIds = ref<string[]>([])
|
||||||
|
const draggedIndex = ref<number | null>(null)
|
||||||
|
const draggedAvailableField = ref<FieldConfig | null>(null)
|
||||||
|
|
||||||
|
// Initialize with initial layout
|
||||||
|
watch(() => props.initialLayout, (layout) => {
|
||||||
|
if (layout && layout.length > 0) {
|
||||||
|
// Sort by order if available, otherwise use array order
|
||||||
|
const sorted = [...layout].sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||||
|
selectedFieldIds.value = sorted.map(item => item.fieldId)
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
|
// Computed selected fields in order
|
||||||
|
const selectedFields = computed(() => {
|
||||||
|
return selectedFieldIds.value
|
||||||
|
.map(id => props.fields.find(f => f.id === id))
|
||||||
|
.filter((f): f is FieldConfig => f !== undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Available fields (not selected)
|
||||||
|
const availableFields = computed(() => {
|
||||||
|
const selectedSet = new Set(selectedFieldIds.value)
|
||||||
|
return props.fields.filter(field => !selectedSet.has(field.id))
|
||||||
|
})
|
||||||
|
|
||||||
|
const formatFieldType = (type: string): string => {
|
||||||
|
const typeNames: Record<string, string> = {
|
||||||
|
'TEXT': 'Text',
|
||||||
|
'LONG_TEXT': 'Textarea',
|
||||||
|
'EMAIL': 'Email',
|
||||||
|
'PHONE': 'Phone',
|
||||||
|
'NUMBER': 'Number',
|
||||||
|
'CURRENCY': 'Currency',
|
||||||
|
'PERCENT': 'Percent',
|
||||||
|
'PICKLIST': 'Picklist',
|
||||||
|
'MULTI_PICKLIST': 'Multi-select',
|
||||||
|
'BOOLEAN': 'Checkbox',
|
||||||
|
'DATE': 'Date',
|
||||||
|
'DATE_TIME': 'DateTime',
|
||||||
|
'TIME': 'Time',
|
||||||
|
'URL': 'URL',
|
||||||
|
'LOOKUP': 'Lookup',
|
||||||
|
'FILE': 'File',
|
||||||
|
'IMAGE': 'Image',
|
||||||
|
'JSON': 'JSON',
|
||||||
|
'text': 'Text',
|
||||||
|
'textarea': 'Textarea',
|
||||||
|
'email': 'Email',
|
||||||
|
'number': 'Number',
|
||||||
|
'currency': 'Currency',
|
||||||
|
'select': 'Picklist',
|
||||||
|
'multiSelect': 'Multi-select',
|
||||||
|
'boolean': 'Checkbox',
|
||||||
|
'date': 'Date',
|
||||||
|
'datetime': 'DateTime',
|
||||||
|
'url': 'URL',
|
||||||
|
'lookup': 'Lookup',
|
||||||
|
'belongsTo': 'Lookup',
|
||||||
|
}
|
||||||
|
return typeNames[type] || type
|
||||||
|
}
|
||||||
|
|
||||||
|
const addField = (field: FieldConfig) => {
|
||||||
|
if (!selectedFieldIds.value.includes(field.id)) {
|
||||||
|
selectedFieldIds.value.push(field.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeField = (fieldId: string) => {
|
||||||
|
selectedFieldIds.value = selectedFieldIds.value.filter(id => id !== fieldId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drag and drop for reordering
|
||||||
|
const handleDragStart = (event: DragEvent, index: number) => {
|
||||||
|
draggedIndex.value = index
|
||||||
|
draggedAvailableField.value = null
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.effectAllowed = 'move'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDragOver = (event: DragEvent, index: number) => {
|
||||||
|
event.preventDefault()
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.dropEffect = 'move'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDrop = (event: DragEvent, targetIndex: number) => {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
// Handle drop from available fields
|
||||||
|
if (draggedAvailableField.value) {
|
||||||
|
addField(draggedAvailableField.value)
|
||||||
|
// Move the newly added field to the target position
|
||||||
|
const newFieldId = draggedAvailableField.value.id
|
||||||
|
const currentIndex = selectedFieldIds.value.indexOf(newFieldId)
|
||||||
|
if (currentIndex !== -1 && currentIndex !== targetIndex) {
|
||||||
|
const ids = [...selectedFieldIds.value]
|
||||||
|
ids.splice(currentIndex, 1)
|
||||||
|
ids.splice(targetIndex, 0, newFieldId)
|
||||||
|
selectedFieldIds.value = ids
|
||||||
|
}
|
||||||
|
draggedAvailableField.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle reordering within selected fields
|
||||||
|
if (draggedIndex.value === null || draggedIndex.value === targetIndex) {
|
||||||
|
draggedIndex.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const ids = [...selectedFieldIds.value]
|
||||||
|
const [removed] = ids.splice(draggedIndex.value, 1)
|
||||||
|
ids.splice(targetIndex, 0, removed)
|
||||||
|
selectedFieldIds.value = ids
|
||||||
|
draggedIndex.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drag from available fields
|
||||||
|
const handleAvailableFieldDragStart = (event: DragEvent, field: FieldConfig) => {
|
||||||
|
draggedAvailableField.value = field
|
||||||
|
draggedIndex.value = null
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.effectAllowed = 'copy'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClear = () => {
|
||||||
|
if (confirm('Are you sure you want to clear all fields from the layout?')) {
|
||||||
|
selectedFieldIds.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
const layout: FieldLayoutItem[] = selectedFieldIds.value.map((fieldId, index) => ({
|
||||||
|
fieldId,
|
||||||
|
order: index,
|
||||||
|
}))
|
||||||
|
|
||||||
|
emit('save', { fields: layout })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.list-view-layout-editor {
|
||||||
|
height: calc(100vh - 300px);
|
||||||
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="rounded-lg border border-amber-200 bg-amber-50 p-4">
|
|
||||||
<p class="mb-3 text-sm font-semibold text-amber-900">{{ prompt }}</p>
|
|
||||||
<form class="space-y-3" @submit.prevent="submit">
|
|
||||||
<div v-for="field in fields" :key="field.name" class="space-y-1">
|
|
||||||
<label class="text-xs font-medium text-slate-600">
|
|
||||||
{{ field.label }}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
v-model="form[field.name]"
|
|
||||||
class="w-full rounded border border-slate-300 px-3 py-2 text-sm"
|
|
||||||
:type="field.type === 'number' ? 'number' : 'text'"
|
|
||||||
:required="field.required"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-semibold text-white"
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
const props = defineProps<{
|
|
||||||
schema: Record<string, any>
|
|
||||||
prompt: string
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(event: 'submit', payload: Record<string, unknown>): void
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const form = reactive<Record<string, string>>({})
|
|
||||||
|
|
||||||
const fields = computed(() => {
|
|
||||||
const properties = props.schema?.properties || {}
|
|
||||||
const required = props.schema?.required || []
|
|
||||||
return Object.entries(properties).map(([name, config]: [string, any]) => ({
|
|
||||||
name,
|
|
||||||
label: config.title || name,
|
|
||||||
type: config.type || 'string',
|
|
||||||
required: required.includes(name),
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
const submit = () => {
|
|
||||||
emit('submit', { ...form })
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="rounded-lg border border-slate-200 bg-white shadow">
|
|
||||||
<div class="border-b border-slate-200 px-4 py-3 text-sm font-semibold text-slate-700">
|
|
||||||
Process Graph Editor
|
|
||||||
</div>
|
|
||||||
<iframe
|
|
||||||
class="h-[640px] w-full"
|
|
||||||
:src="editorUrl"
|
|
||||||
title="AI Process Builder"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
const config = useRuntimeConfig()
|
|
||||||
const editorUrl = computed(() =>
|
|
||||||
config.public.aiProcessEditorUrl || 'http://localhost:5174'
|
|
||||||
)
|
|
||||||
</script>
|
|
||||||
@@ -85,9 +85,31 @@ const formatValue = (val: any): string => {
|
|||||||
case FieldType.BELONGS_TO:
|
case FieldType.BELONGS_TO:
|
||||||
return relationshipDisplayValue.value
|
return relationshipDisplayValue.value
|
||||||
case FieldType.DATE:
|
case FieldType.DATE:
|
||||||
return val instanceof Date ? val.toLocaleDateString() : new Date(val).toLocaleDateString()
|
try {
|
||||||
|
const date = val instanceof Date ? val : new Date(val)
|
||||||
|
return date.toLocaleDateString(undefined, {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit'
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return String(val)
|
||||||
|
}
|
||||||
case FieldType.DATETIME:
|
case FieldType.DATETIME:
|
||||||
return val instanceof Date ? val.toLocaleString() : new Date(val).toLocaleString()
|
try {
|
||||||
|
const date = val instanceof Date ? val : new Date(val)
|
||||||
|
return date.toLocaleString(undefined, {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
hour12: false
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return String(val)
|
||||||
|
}
|
||||||
case FieldType.BOOLEAN:
|
case FieldType.BOOLEAN:
|
||||||
return val ? 'Yes' : 'No'
|
return val ? 'Yes' : 'No'
|
||||||
case FieldType.CURRENCY:
|
case FieldType.CURRENCY:
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export const useFields = () => {
|
|||||||
// Hide system fields and auto-generated fields on edit
|
// Hide system fields and auto-generated fields on edit
|
||||||
const shouldHideOnEdit = isSystemField || isAutoGeneratedField
|
const shouldHideOnEdit = isSystemField || isAutoGeneratedField
|
||||||
|
|
||||||
|
// Hide 'id' field from list view by default (check both apiName and id field)
|
||||||
|
const shouldHideOnList = fieldDef.apiName === 'id' || fieldDef.label === 'Id' || fieldDef.label === 'ID'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: fieldDef.id,
|
id: fieldDef.id,
|
||||||
apiName: fieldDef.apiName,
|
apiName: fieldDef.apiName,
|
||||||
@@ -37,7 +40,7 @@ export const useFields = () => {
|
|||||||
validationRules: fieldDef.validationRules || [],
|
validationRules: fieldDef.validationRules || [],
|
||||||
|
|
||||||
// View options - only hide system and auto-generated fields by default
|
// View options - only hide system and auto-generated fields by default
|
||||||
showOnList: fieldDef.showOnList ?? true,
|
showOnList: fieldDef.showOnList ?? !shouldHideOnList,
|
||||||
showOnDetail: fieldDef.showOnDetail ?? true,
|
showOnDetail: fieldDef.showOnDetail ?? true,
|
||||||
showOnEdit: fieldDef.showOnEdit ?? !shouldHideOnEdit,
|
showOnEdit: fieldDef.showOnEdit ?? !shouldHideOnEdit,
|
||||||
sortable: fieldDef.sortable ?? true,
|
sortable: fieldDef.sortable ?? true,
|
||||||
@@ -67,12 +70,36 @@ export const useFields = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a ListView configuration from object definition
|
* Build a ListView configuration from object definition
|
||||||
|
* @param objectDef - The object definition containing fields
|
||||||
|
* @param customConfig - Optional custom configuration
|
||||||
|
* @param listLayoutConfig - Optional list view layout configuration from page_layouts
|
||||||
*/
|
*/
|
||||||
const buildListViewConfig = (
|
const buildListViewConfig = (
|
||||||
objectDef: any,
|
objectDef: any,
|
||||||
customConfig?: Partial<ListViewConfig>
|
customConfig?: Partial<ListViewConfig>,
|
||||||
|
listLayoutConfig?: { fields: Array<{ fieldId: string; order?: number }> } | null
|
||||||
): ListViewConfig => {
|
): ListViewConfig => {
|
||||||
const fields = objectDef.fields?.map(mapFieldDefinitionToConfig) || []
|
let fields = objectDef.fields?.map(mapFieldDefinitionToConfig) || []
|
||||||
|
|
||||||
|
// If a list layout is provided, filter and order fields according to it
|
||||||
|
if (listLayoutConfig && listLayoutConfig.fields && listLayoutConfig.fields.length > 0) {
|
||||||
|
// Sort layout fields by order
|
||||||
|
const sortedLayoutFields = [...listLayoutConfig.fields].sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||||
|
|
||||||
|
// Map layout fields to actual field configs, preserving order
|
||||||
|
const orderedFields: FieldConfig[] = []
|
||||||
|
for (const layoutField of sortedLayoutFields) {
|
||||||
|
const fieldConfig = fields.find((f: FieldConfig) => f.id === layoutField.fieldId)
|
||||||
|
if (fieldConfig) {
|
||||||
|
orderedFields.push(fieldConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use ordered fields if we found any, otherwise fall back to all fields
|
||||||
|
if (orderedFields.length > 0) {
|
||||||
|
fields = orderedFields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
objectApiName: objectDef.apiName,
|
objectApiName: objectDef.apiName,
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import type { PageLayout, CreatePageLayoutRequest, UpdatePageLayoutRequest } from '~/types/page-layout'
|
import type { PageLayout, CreatePageLayoutRequest, UpdatePageLayoutRequest, PageLayoutType } from '~/types/page-layout'
|
||||||
|
|
||||||
export const usePageLayouts = () => {
|
export const usePageLayouts = () => {
|
||||||
const { api } = useApi()
|
const { api } = useApi()
|
||||||
|
|
||||||
const getPageLayouts = async (objectId?: string) => {
|
const getPageLayouts = async (objectId?: string, layoutType?: PageLayoutType) => {
|
||||||
try {
|
try {
|
||||||
const params = objectId ? { objectId } : {}
|
const params: Record<string, string> = {}
|
||||||
|
if (objectId) params.objectId = objectId
|
||||||
|
if (layoutType) params.layoutType = layoutType
|
||||||
const response = await api.get('/page-layouts', { params })
|
const response = await api.get('/page-layouts', { params })
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -24,9 +26,11 @@ export const usePageLayouts = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDefaultPageLayout = async (objectId: string) => {
|
const getDefaultPageLayout = async (objectId: string, layoutType: PageLayoutType = 'detail') => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`/page-layouts/default/${objectId}`)
|
const response = await api.get(`/page-layouts/default/${objectId}`, {
|
||||||
|
params: { layoutType }
|
||||||
|
})
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching default page layout:', error)
|
console.error('Error fetching default page layout:', error)
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ export default defineNuxtConfig({
|
|||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
public: {
|
||||||
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:3000',
|
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:3000',
|
||||||
aiProcessEditorUrl:
|
|
||||||
process.env.NUXT_PUBLIC_AI_PROCESS_EDITOR_URL || 'http://localhost:5174',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
831
frontend/package-lock.json
generated
831
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
|
|||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useApi } from '@/composables/useApi'
|
import { useApi } from '@/composables/useApi'
|
||||||
import { useFields, useViewState } from '@/composables/useFieldViews'
|
import { useFields, useViewState } from '@/composables/useFieldViews'
|
||||||
|
import { usePageLayouts } from '@/composables/usePageLayouts'
|
||||||
import ListView from '@/components/views/ListView.vue'
|
import ListView from '@/components/views/ListView.vue'
|
||||||
import DetailView from '@/components/views/DetailViewEnhanced.vue'
|
import DetailView from '@/components/views/DetailViewEnhanced.vue'
|
||||||
import EditView from '@/components/views/EditViewEnhanced.vue'
|
import EditView from '@/components/views/EditViewEnhanced.vue'
|
||||||
@@ -19,6 +20,7 @@ const route = useRoute()
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { api } = useApi()
|
const { api } = useApi()
|
||||||
const { buildListViewConfig, buildDetailViewConfig, buildEditViewConfig } = useFields()
|
const { buildListViewConfig, buildDetailViewConfig, buildEditViewConfig } = useFields()
|
||||||
|
const { getDefaultPageLayout } = usePageLayouts()
|
||||||
|
|
||||||
// Use breadcrumbs composable
|
// Use breadcrumbs composable
|
||||||
const { setBreadcrumbs } = useBreadcrumbs()
|
const { setBreadcrumbs } = useBreadcrumbs()
|
||||||
@@ -40,6 +42,7 @@ const view = computed(() => {
|
|||||||
|
|
||||||
// State
|
// State
|
||||||
const objectDefinition = ref<any>(null)
|
const objectDefinition = ref<any>(null)
|
||||||
|
const listViewLayout = ref<any>(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
@@ -134,11 +137,13 @@ watch([objectDefinition, currentRecord, recordId], () => {
|
|||||||
// View configs
|
// View configs
|
||||||
const listConfig = computed(() => {
|
const listConfig = computed(() => {
|
||||||
if (!objectDefinition.value) return null
|
if (!objectDefinition.value) return null
|
||||||
|
// Pass the list view layout config to buildListViewConfig if available
|
||||||
|
const layoutConfig = listViewLayout.value?.layout_config || listViewLayout.value?.layoutConfig
|
||||||
return buildListViewConfig(objectDefinition.value, {
|
return buildListViewConfig(objectDefinition.value, {
|
||||||
searchable: true,
|
searchable: true,
|
||||||
exportable: true,
|
exportable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
})
|
}, layoutConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
const detailConfig = computed(() => {
|
const detailConfig = computed(() => {
|
||||||
@@ -172,6 +177,16 @@ const fetchObjectDefinition = async () => {
|
|||||||
error.value = null
|
error.value = null
|
||||||
const response = await api.get(`/setup/objects/${objectApiName.value}`)
|
const response = await api.get(`/setup/objects/${objectApiName.value}`)
|
||||||
objectDefinition.value = response
|
objectDefinition.value = response
|
||||||
|
|
||||||
|
// Fetch the default list view layout for this object
|
||||||
|
if (response?.id) {
|
||||||
|
try {
|
||||||
|
listViewLayout.value = await getDefaultPageLayout(response.id, 'list')
|
||||||
|
} catch (e) {
|
||||||
|
// No list view layout configured, will use default behavior
|
||||||
|
listViewLayout.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e.message || 'Failed to load object definition'
|
error.value = e.message || 'Failed to load object definition'
|
||||||
console.error('Error fetching object definition:', e)
|
console.error('Error fetching object definition:', e)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="space-y-6 p-6">
|
|
||||||
<div>
|
|
||||||
<h1 class="text-2xl font-semibold text-slate-900">
|
|
||||||
AI Process Builder
|
|
||||||
</h1>
|
|
||||||
<p class="text-sm text-slate-600">
|
|
||||||
Define tenant-scoped process graphs and publish versions for orchestration.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ReactFlowIframe />
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { Save, Play, ArrowLeft } from 'lucide-vue-next'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Input } from '@/components/ui/input'
|
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
|
||||||
import { Label } from '@/components/ui/label'
|
|
||||||
import { useApi } from '@/composables/useApi'
|
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
|
||||||
|
|
||||||
interface ProcessGraph {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
description?: string
|
|
||||||
nodes: any[]
|
|
||||||
edges: any[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const { api } = useApi()
|
|
||||||
const router = useRouter()
|
|
||||||
const route = useRoute()
|
|
||||||
const processId = computed(() => route.params.id === 'new' ? null : String(route.params.id))
|
|
||||||
|
|
||||||
const processName = ref('')
|
|
||||||
const processDescription = ref('')
|
|
||||||
const graphDefinition = ref<ProcessGraph | null>(null)
|
|
||||||
const saving = ref(false)
|
|
||||||
const loading = ref(true)
|
|
||||||
|
|
||||||
const getTenantId = () => {
|
|
||||||
if (!import.meta.client) return 'tenant1'
|
|
||||||
return localStorage.getItem('tenantId') || 'tenant1'
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadProcess = async () => {
|
|
||||||
if (!processId.value) {
|
|
||||||
loading.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const data = await api.get(`/tenants/${getTenantId()}/ai-processes/${processId.value}`)
|
|
||||||
processName.value = data.name
|
|
||||||
processDescription.value = data.description || ''
|
|
||||||
|
|
||||||
if (data.versions && data.versions.length > 0) {
|
|
||||||
const latestVersion = data.versions[data.versions.length - 1]
|
|
||||||
graphDefinition.value = latestVersion.graphJson
|
|
||||||
|
|
||||||
// Send graph to iframe
|
|
||||||
sendGraphToEditor(latestVersion.graphJson)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load process:', error)
|
|
||||||
alert('Failed to load process')
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sendGraphToEditor = (graph: any) => {
|
|
||||||
const iframe = document.getElementById('process-editor-iframe') as HTMLIFrameElement
|
|
||||||
if (iframe && iframe.contentWindow) {
|
|
||||||
iframe.contentWindow.postMessage({
|
|
||||||
type: 'LOAD_GRAPH',
|
|
||||||
payload: graph
|
|
||||||
}, '*')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const saveProcess = async () => {
|
|
||||||
if (!processName.value.trim()) {
|
|
||||||
alert('Process name is required')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!graphDefinition.value) {
|
|
||||||
alert('Please design the process graph first')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
saving.value = true
|
|
||||||
try {
|
|
||||||
if (processId.value) {
|
|
||||||
// Update existing process (create new version)
|
|
||||||
await api.post(`/tenants/${getTenantId()}/ai-processes/${processId.value}/versions`, {
|
|
||||||
graph: graphDefinition.value
|
|
||||||
})
|
|
||||||
alert('Process version saved successfully!')
|
|
||||||
} else {
|
|
||||||
// Create new process
|
|
||||||
const result = await api.post(`/tenants/${getTenantId()}/ai-processes`, {
|
|
||||||
name: processName.value,
|
|
||||||
description: processDescription.value,
|
|
||||||
graph: graphDefinition.value
|
|
||||||
})
|
|
||||||
alert('Process created successfully!')
|
|
||||||
router.push(`/ai-processes/${result.id}/edit`)
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to save process:', error)
|
|
||||||
alert(`Save failed: ${error.message || 'Unknown error'}`)
|
|
||||||
} finally {
|
|
||||||
saving.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const testRun = async () => {
|
|
||||||
if (!processId.value) {
|
|
||||||
alert('Please save the process first')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await api.post(`/tenants/${getTenantId()}/ai-processes/${processId.value}/runs`, {
|
|
||||||
input: { test: true }
|
|
||||||
})
|
|
||||||
console.log('Test run result:', result)
|
|
||||||
alert('Test run started! Check the console for details.')
|
|
||||||
} catch (error: any) {
|
|
||||||
alert(`Test failed: ${error.message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEditorMessage = (event: MessageEvent) => {
|
|
||||||
if (event.data.type === 'GRAPH_UPDATED') {
|
|
||||||
graphDefinition.value = event.data.payload
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadProcess()
|
|
||||||
window.addEventListener('message', handleEditorMessage)
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
window.removeEventListener('message', handleEditorMessage)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="h-screen flex flex-col">
|
|
||||||
<!-- Header -->
|
|
||||||
<div class="border-b bg-background px-6 py-3 flex items-center justify-between">
|
|
||||||
<div class="flex items-center gap-4 flex-1">
|
|
||||||
<Button variant="ghost" size="icon" @click="router.push('/ai-processes')">
|
|
||||||
<ArrowLeft class="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<div class="flex-1 max-w-md">
|
|
||||||
<Input
|
|
||||||
v-model="processName"
|
|
||||||
placeholder="Process Name"
|
|
||||||
class="font-semibold"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<Button variant="outline" @click="testRun" :disabled="!processId">
|
|
||||||
<Play class="h-4 w-4 mr-2" />
|
|
||||||
Test Run
|
|
||||||
</Button>
|
|
||||||
<Button @click="saveProcess" :disabled="saving">
|
|
||||||
<Save class="h-4 w-4 mr-2" />
|
|
||||||
{{ saving ? 'Saving...' : 'Save' }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Process Description -->
|
|
||||||
<div class="border-b bg-background px-6 py-2">
|
|
||||||
<Textarea
|
|
||||||
v-model="processDescription"
|
|
||||||
placeholder="Process description (optional)"
|
|
||||||
class="resize-none text-sm"
|
|
||||||
rows="2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Editor Iframe -->
|
|
||||||
<div class="flex-1 relative">
|
|
||||||
<div v-if="loading" class="absolute inset-0 flex items-center justify-center bg-background/80">
|
|
||||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
|
||||||
</div>
|
|
||||||
<iframe
|
|
||||||
id="process-editor-iframe"
|
|
||||||
src="/ai-processes-editor/index.html"
|
|
||||||
class="w-full h-full border-0"
|
|
||||||
title="Process Editor"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { Plus, Workflow, Play } from 'lucide-vue-next'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
|
||||||
import { Badge } from '@/components/ui/badge'
|
|
||||||
import { useApi } from '@/composables/useApi'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
interface Process {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
description?: string
|
|
||||||
latestVersion: number
|
|
||||||
createdAt: string
|
|
||||||
versions?: any[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const { api } = useApi()
|
|
||||||
const router = useRouter()
|
|
||||||
const processes = ref<Process[]>([])
|
|
||||||
const loading = ref(true)
|
|
||||||
|
|
||||||
const getTenantId = () => {
|
|
||||||
if (!import.meta.client) return 'tenant1'
|
|
||||||
return localStorage.getItem('tenantId') || 'tenant1'
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadProcesses = async () => {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const data = await api.get(`/tenants/${getTenantId()}/ai-processes`)
|
|
||||||
processes.value = data || []
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to load processes:', error)
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const createNewProcess = () => {
|
|
||||||
router.push('/ai-processes/new')
|
|
||||||
}
|
|
||||||
|
|
||||||
const editProcess = (processId: string) => {
|
|
||||||
router.push(`/ai-processes/${processId}/edit`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const testProcess = async (processId: string) => {
|
|
||||||
try {
|
|
||||||
const result = await api.post(`/tenants/${getTenantId()}/ai-processes/${processId}/runs`, {
|
|
||||||
input: { test: true },
|
|
||||||
})
|
|
||||||
console.log('Test run result:', result)
|
|
||||||
alert('Process test started! Check console for details.')
|
|
||||||
} catch (error: any) {
|
|
||||||
alert(`Test failed: ${error.message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadProcesses()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="container mx-auto p-6 space-y-6">
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<div>
|
|
||||||
<h1 class="text-3xl font-bold tracking-tight">AI Process Builder</h1>
|
|
||||||
<p class="text-muted-foreground mt-1">
|
|
||||||
Create and manage intelligent business process workflows
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Button @click="createNewProcess">
|
|
||||||
<Plus class="mr-2 h-4 w-4" />
|
|
||||||
New Process
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="loading" class="flex items-center justify-center py-12">
|
|
||||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else-if="processes.length === 0" class="text-center py-12">
|
|
||||||
<Workflow class="mx-auto h-12 w-12 text-muted-foreground/50" />
|
|
||||||
<h3 class="mt-4 text-lg font-semibold">No processes yet</h3>
|
|
||||||
<p class="text-muted-foreground mt-1">
|
|
||||||
Get started by creating your first AI-powered business process
|
|
||||||
</p>
|
|
||||||
<Button @click="createNewProcess" class="mt-4">
|
|
||||||
<Plus class="mr-2 h-4 w-4" />
|
|
||||||
Create Process
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
|
||||||
<Card
|
|
||||||
v-for="process in processes"
|
|
||||||
:key="process.id"
|
|
||||||
class="hover:shadow-lg transition-shadow cursor-pointer"
|
|
||||||
@click="editProcess(process.id)"
|
|
||||||
>
|
|
||||||
<CardHeader>
|
|
||||||
<div class="flex items-start justify-between">
|
|
||||||
<Workflow class="h-5 w-5 text-primary" />
|
|
||||||
<Badge variant="secondary">v{{ process.latestVersion }}</Badge>
|
|
||||||
</div>
|
|
||||||
<CardTitle class="mt-2">{{ process.name }}</CardTitle>
|
|
||||||
<CardDescription>{{ process.description || 'No description' }}</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
@click.stop="editProcess(process.id)"
|
|
||||||
>
|
|
||||||
Edit
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
@click.stop="testProcess(process.id)"
|
|
||||||
>
|
|
||||||
<Play class="h-3 w-3 mr-1" />
|
|
||||||
Test
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -3,6 +3,7 @@ import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
|
|||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useApi } from '@/composables/useApi'
|
import { useApi } from '@/composables/useApi'
|
||||||
import { useFields, useViewState } from '@/composables/useFieldViews'
|
import { useFields, useViewState } from '@/composables/useFieldViews'
|
||||||
|
import { usePageLayouts } from '@/composables/usePageLayouts'
|
||||||
import ListView from '@/components/views/ListView.vue'
|
import ListView from '@/components/views/ListView.vue'
|
||||||
import DetailView from '@/components/views/DetailView.vue'
|
import DetailView from '@/components/views/DetailView.vue'
|
||||||
import EditView from '@/components/views/EditView.vue'
|
import EditView from '@/components/views/EditView.vue'
|
||||||
@@ -11,6 +12,7 @@ const route = useRoute()
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { api } = useApi()
|
const { api } = useApi()
|
||||||
const { buildListViewConfig, buildDetailViewConfig, buildEditViewConfig } = useFields()
|
const { buildListViewConfig, buildDetailViewConfig, buildEditViewConfig } = useFields()
|
||||||
|
const { getDefaultPageLayout } = usePageLayouts()
|
||||||
|
|
||||||
// Get object API name from route
|
// Get object API name from route
|
||||||
const objectApiName = computed(() => route.params.objectName as string)
|
const objectApiName = computed(() => route.params.objectName as string)
|
||||||
@@ -25,6 +27,7 @@ const view = computed(() => {
|
|||||||
|
|
||||||
// State
|
// State
|
||||||
const objectDefinition = ref<any>(null)
|
const objectDefinition = ref<any>(null)
|
||||||
|
const listViewLayout = ref<any>(null)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
@@ -66,11 +69,13 @@ onBeforeUnmount(() => {
|
|||||||
// View configs
|
// View configs
|
||||||
const listConfig = computed(() => {
|
const listConfig = computed(() => {
|
||||||
if (!objectDefinition.value) return null
|
if (!objectDefinition.value) return null
|
||||||
|
// Pass the list view layout config to buildListViewConfig if available
|
||||||
|
const layoutConfig = listViewLayout.value?.layout_config || listViewLayout.value?.layoutConfig
|
||||||
return buildListViewConfig(objectDefinition.value, {
|
return buildListViewConfig(objectDefinition.value, {
|
||||||
searchable: true,
|
searchable: true,
|
||||||
exportable: true,
|
exportable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
})
|
}, layoutConfig)
|
||||||
})
|
})
|
||||||
|
|
||||||
const detailConfig = computed(() => {
|
const detailConfig = computed(() => {
|
||||||
@@ -93,6 +98,16 @@ const fetchObjectDefinition = async () => {
|
|||||||
error.value = null
|
error.value = null
|
||||||
const response = await api.get(`/setup/objects/${objectApiName.value}`)
|
const response = await api.get(`/setup/objects/${objectApiName.value}`)
|
||||||
objectDefinition.value = response
|
objectDefinition.value = response
|
||||||
|
|
||||||
|
// Fetch the default list view layout for this object
|
||||||
|
if (response?.id) {
|
||||||
|
try {
|
||||||
|
listViewLayout.value = await getDefaultPageLayout(response.id, 'list')
|
||||||
|
} catch (e) {
|
||||||
|
// No list view layout configured, will use default behavior
|
||||||
|
listViewLayout.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e.message || 'Failed to load object definition'
|
error.value = e.message || 'Failed to load object definition'
|
||||||
console.error('Error fetching object definition:', e)
|
console.error('Error fetching object definition:', e)
|
||||||
|
|||||||
@@ -16,10 +16,11 @@
|
|||||||
<!-- Tabs -->
|
<!-- Tabs -->
|
||||||
<div class="mb-8">
|
<div class="mb-8">
|
||||||
<Tabs v-model="activeTab" default-value="fields" class="w-full">
|
<Tabs v-model="activeTab" default-value="fields" class="w-full">
|
||||||
<TabsList class="grid w-full grid-cols-3 max-w-2xl">
|
<TabsList class="grid w-full grid-cols-4 max-w-2xl">
|
||||||
<TabsTrigger value="fields">Fields</TabsTrigger>
|
<TabsTrigger value="fields">Fields</TabsTrigger>
|
||||||
<TabsTrigger value="access">Access</TabsTrigger>
|
<TabsTrigger value="access">Access</TabsTrigger>
|
||||||
<TabsTrigger value="layouts">Page Layouts</TabsTrigger>
|
<TabsTrigger value="layouts">Page Layouts</TabsTrigger>
|
||||||
|
<TabsTrigger value="listLayouts">List View Layouts</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
|
||||||
<!-- Fields Tab -->
|
<!-- Fields Tab -->
|
||||||
@@ -148,7 +149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span
|
<span
|
||||||
v-if="layout.isDefault"
|
v-if="layout.isDefault || layout.is_default"
|
||||||
class="px-2 py-1 bg-primary/10 text-primary rounded text-xs"
|
class="px-2 py-1 bg-primary/10 text-primary rounded text-xs"
|
||||||
>
|
>
|
||||||
Default
|
Default
|
||||||
@@ -185,6 +186,84 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
|
<!-- List View Layouts Tab -->
|
||||||
|
<TabsContent value="listLayouts" class="mt-6">
|
||||||
|
<div v-if="!selectedListLayout" class="space-y-4">
|
||||||
|
<div class="flex justify-between items-center mb-4">
|
||||||
|
<h2 class="text-xl font-semibold">List View Layouts</h2>
|
||||||
|
<Button @click="handleCreateListLayout">
|
||||||
|
<Plus class="w-4 h-4 mr-2" />
|
||||||
|
New List Layout
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-sm text-muted-foreground mb-4">
|
||||||
|
Configure which fields appear in list views and their order.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div v-if="loadingListLayouts" class="text-center py-8">
|
||||||
|
Loading list layouts...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="listLayouts.length === 0" class="text-center py-8 text-muted-foreground">
|
||||||
|
No list view layouts yet. Create one to customize your list views.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="space-y-2">
|
||||||
|
<div
|
||||||
|
v-for="layout in listLayouts"
|
||||||
|
:key="layout.id"
|
||||||
|
class="p-4 border rounded-lg bg-card hover:border-primary cursor-pointer transition-colors"
|
||||||
|
@click="handleSelectListLayout(layout)"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h3 class="font-semibold">{{ layout.name }}</h3>
|
||||||
|
<p v-if="layout.description" class="text-sm text-muted-foreground">
|
||||||
|
{{ layout.description }}
|
||||||
|
</p>
|
||||||
|
<p class="text-xs text-muted-foreground mt-1">
|
||||||
|
{{ getListLayoutFieldCount(layout) }} fields configured
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
v-if="layout.isDefault || layout.is_default"
|
||||||
|
class="px-2 py-1 bg-primary/10 text-primary rounded text-xs"
|
||||||
|
>
|
||||||
|
Default
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
@click.stop="handleDeleteListLayout(layout.id)"
|
||||||
|
>
|
||||||
|
<Trash2 class="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- List Layout Editor -->
|
||||||
|
<div v-else>
|
||||||
|
<div class="mb-4">
|
||||||
|
<Button variant="outline" @click="selectedListLayout = null">
|
||||||
|
<ArrowLeft class="w-4 h-4 mr-2" />
|
||||||
|
Back to List Layouts
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ListViewLayoutEditor
|
||||||
|
:fields="object.fields"
|
||||||
|
:initial-layout="(selectedListLayout.layoutConfig || selectedListLayout.layout_config)?.fields || []"
|
||||||
|
:layout-name="selectedListLayout.name"
|
||||||
|
@save="handleSaveListLayout"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -299,6 +378,7 @@ import { Plus, Trash2, ArrowLeft } from 'lucide-vue-next'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||||
import PageLayoutEditor from '@/components/PageLayoutEditor.vue'
|
import PageLayoutEditor from '@/components/PageLayoutEditor.vue'
|
||||||
|
import ListViewLayoutEditor from '@/components/ListViewLayoutEditor.vue'
|
||||||
import ObjectAccessSettings from '@/components/ObjectAccessSettings.vue'
|
import ObjectAccessSettings from '@/components/ObjectAccessSettings.vue'
|
||||||
import FieldTypeSelector from '@/components/fields/FieldTypeSelector.vue'
|
import FieldTypeSelector from '@/components/fields/FieldTypeSelector.vue'
|
||||||
import FieldAttributesCommon from '@/components/fields/FieldAttributesCommon.vue'
|
import FieldAttributesCommon from '@/components/fields/FieldAttributesCommon.vue'
|
||||||
@@ -315,11 +395,16 @@ const loading = ref(true)
|
|||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
const activeTab = ref('fields')
|
const activeTab = ref('fields')
|
||||||
|
|
||||||
// Page layouts state
|
// Page layouts state (detail/edit layouts)
|
||||||
const layouts = ref<PageLayout[]>([])
|
const layouts = ref<PageLayout[]>([])
|
||||||
const loadingLayouts = ref(false)
|
const loadingLayouts = ref(false)
|
||||||
const selectedLayout = ref<PageLayout | null>(null)
|
const selectedLayout = ref<PageLayout | null>(null)
|
||||||
|
|
||||||
|
// List view layouts state
|
||||||
|
const listLayouts = ref<PageLayout[]>([])
|
||||||
|
const loadingListLayouts = ref(false)
|
||||||
|
const selectedListLayout = ref<PageLayout | null>(null)
|
||||||
|
|
||||||
// Field management state
|
// Field management state
|
||||||
const showFieldDialog = ref(false)
|
const showFieldDialog = ref(false)
|
||||||
const fieldDialogMode = ref<'create' | 'edit'>('create')
|
const fieldDialogMode = ref<'create' | 'edit'>('create')
|
||||||
@@ -420,7 +505,8 @@ const fetchLayouts = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
loadingLayouts.value = true
|
loadingLayouts.value = true
|
||||||
layouts.value = await getPageLayouts(object.value.id)
|
// Fetch only detail layouts (default type)
|
||||||
|
layouts.value = await getPageLayouts(object.value.id, 'detail')
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error('Error fetching layouts:', e)
|
console.error('Error fetching layouts:', e)
|
||||||
toast.error('Failed to load page layouts')
|
toast.error('Failed to load page layouts')
|
||||||
@@ -429,6 +515,20 @@ const fetchLayouts = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchListLayouts = async () => {
|
||||||
|
if (!object.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadingListLayouts.value = true
|
||||||
|
listLayouts.value = await getPageLayouts(object.value.id, 'list')
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Error fetching list layouts:', e)
|
||||||
|
toast.error('Failed to load list view layouts')
|
||||||
|
} finally {
|
||||||
|
loadingListLayouts.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const openFieldDialog = async (mode: 'create' | 'edit', field?: any) => {
|
const openFieldDialog = async (mode: 'create' | 'edit', field?: any) => {
|
||||||
fieldDialogMode.value = mode
|
fieldDialogMode.value = mode
|
||||||
fieldDialogError.value = null
|
fieldDialogError.value = null
|
||||||
@@ -684,6 +784,7 @@ const handleCreateLayout = async () => {
|
|||||||
const newLayout = await createPageLayout({
|
const newLayout = await createPageLayout({
|
||||||
name,
|
name,
|
||||||
objectId: object.value.id,
|
objectId: object.value.id,
|
||||||
|
layoutType: 'detail',
|
||||||
isDefault: layouts.value.length === 0,
|
isDefault: layouts.value.length === 0,
|
||||||
layoutConfig: { fields: [], relatedLists: [] },
|
layoutConfig: { fields: [], relatedLists: [] },
|
||||||
})
|
})
|
||||||
@@ -736,6 +837,73 @@ const handleDeleteLayout = async (layoutId: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List View Layout methods
|
||||||
|
const handleCreateListLayout = async () => {
|
||||||
|
const name = prompt('Enter a name for the new list view layout:')
|
||||||
|
if (!name) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newLayout = await createPageLayout({
|
||||||
|
name,
|
||||||
|
objectId: object.value.id,
|
||||||
|
layoutType: 'list',
|
||||||
|
isDefault: listLayouts.value.length === 0,
|
||||||
|
layoutConfig: { fields: [] },
|
||||||
|
})
|
||||||
|
|
||||||
|
listLayouts.value.push(newLayout)
|
||||||
|
selectedListLayout.value = newLayout
|
||||||
|
toast.success('List view layout created successfully')
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Error creating list layout:', e)
|
||||||
|
toast.error('Failed to create list view layout')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSelectListLayout = (layout: PageLayout) => {
|
||||||
|
selectedListLayout.value = layout
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveListLayout = async (layoutConfig: { fields: FieldLayoutItem[] }) => {
|
||||||
|
if (!selectedListLayout.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updated = await updatePageLayout(selectedListLayout.value.id, {
|
||||||
|
layoutConfig,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Update the layout in the list
|
||||||
|
const index = listLayouts.value.findIndex(l => l.id === selectedListLayout.value!.id)
|
||||||
|
if (index !== -1) {
|
||||||
|
listLayouts.value[index] = updated
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedListLayout.value = updated
|
||||||
|
toast.success('List view layout saved successfully')
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Error saving list layout:', e)
|
||||||
|
toast.error('Failed to save list view layout')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDeleteListLayout = async (layoutId: string) => {
|
||||||
|
if (!confirm('Are you sure you want to delete this list view layout?')) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await deletePageLayout(layoutId)
|
||||||
|
listLayouts.value = listLayouts.value.filter(l => l.id !== layoutId)
|
||||||
|
toast.success('List view layout deleted successfully')
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Error deleting list layout:', e)
|
||||||
|
toast.error('Failed to delete list view layout')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getListLayoutFieldCount = (layout: PageLayout): number => {
|
||||||
|
const config = layout.layoutConfig || layout.layout_config
|
||||||
|
return config?.fields?.length || 0
|
||||||
|
}
|
||||||
|
|
||||||
const handleAccessUpdate = (orgWideDefault: string) => {
|
const handleAccessUpdate = (orgWideDefault: string) => {
|
||||||
if (object.value) {
|
if (object.value) {
|
||||||
object.value.orgWideDefault = orgWideDefault
|
object.value.orgWideDefault = orgWideDefault
|
||||||
@@ -747,6 +915,9 @@ watch(activeTab, (newTab) => {
|
|||||||
if (newTab === 'layouts' && layouts.value.length === 0 && !loadingLayouts.value) {
|
if (newTab === 'layouts' && layouts.value.length === 0 && !loadingLayouts.value) {
|
||||||
fetchLayouts()
|
fetchLayouts()
|
||||||
}
|
}
|
||||||
|
if (newTab === 'listLayouts' && listLayouts.value.length === 0 && !loadingListLayouts.value) {
|
||||||
|
fetchListLayouts()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -755,5 +926,8 @@ onMounted(async () => {
|
|||||||
if (activeTab.value === 'layouts') {
|
if (activeTab.value === 'layouts') {
|
||||||
await fetchLayouts()
|
await fetchLayouts()
|
||||||
}
|
}
|
||||||
|
if (activeTab.value === 'listLayouts') {
|
||||||
|
await fetchListLayouts()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
export interface FieldLayoutItem {
|
export interface FieldLayoutItem {
|
||||||
fieldId: string;
|
fieldId: string;
|
||||||
x: number;
|
x?: number;
|
||||||
y: number;
|
y?: number;
|
||||||
w: number;
|
w?: number;
|
||||||
h: number;
|
h?: number;
|
||||||
|
// For list layouts: field order (optional)
|
||||||
|
order?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PageLayoutType = 'detail' | 'list';
|
||||||
|
|
||||||
export interface PageLayoutConfig {
|
export interface PageLayoutConfig {
|
||||||
fields: FieldLayoutItem[];
|
fields: FieldLayoutItem[];
|
||||||
relatedLists?: string[];
|
relatedLists?: string[];
|
||||||
@@ -15,16 +19,23 @@ export interface PageLayout {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
objectId: string;
|
objectId: string;
|
||||||
|
layoutType: PageLayoutType;
|
||||||
isDefault: boolean;
|
isDefault: boolean;
|
||||||
layoutConfig: PageLayoutConfig;
|
layoutConfig: PageLayoutConfig;
|
||||||
description?: string;
|
description?: string;
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
|
// Database column names (snake_case) - used when data comes directly from DB
|
||||||
|
layout_type?: PageLayoutType;
|
||||||
|
layout_config?: PageLayoutConfig;
|
||||||
|
object_id?: string;
|
||||||
|
is_default?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreatePageLayoutRequest {
|
export interface CreatePageLayoutRequest {
|
||||||
name: string;
|
name: string;
|
||||||
objectId: string;
|
objectId: string;
|
||||||
|
layoutType?: PageLayoutType;
|
||||||
isDefault?: boolean;
|
isDefault?: boolean;
|
||||||
layoutConfig: PageLayoutConfig;
|
layoutConfig: PageLayoutConfig;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user