@geenius/ai-workflow 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +69 -1
- package/package.json +60 -27
- package/packages/convex/dist/index.d.ts +363 -0
- package/packages/convex/dist/index.js +200 -0
- package/packages/convex/dist/index.js.map +1 -0
- package/packages/react/dist/index.d.ts +466 -0
- package/packages/react/dist/index.js +13914 -0
- package/packages/react/dist/index.js.map +1 -0
- package/packages/react-css/{src/styles.css → dist/index.css} +107 -253
- package/packages/react-css/dist/index.css.map +1 -0
- package/packages/react-css/dist/index.d.ts +495 -0
- package/packages/react-css/dist/index.js +13901 -0
- package/packages/react-css/dist/index.js.map +1 -0
- package/packages/shared/dist/index.d.ts +1368 -0
- package/packages/shared/dist/index.js +1681 -0
- package/packages/shared/dist/index.js.map +1 -0
- package/packages/solidjs/dist/index.d.ts +452 -0
- package/packages/solidjs/dist/index.js +13830 -0
- package/packages/solidjs/dist/index.js.map +1 -0
- package/packages/solidjs-css/{src/styles.css → dist/index.css} +107 -253
- package/packages/solidjs-css/dist/index.css.map +1 -0
- package/packages/solidjs-css/dist/index.d.ts +471 -0
- package/packages/solidjs-css/dist/index.js +13774 -0
- package/packages/solidjs-css/dist/index.js.map +1 -0
- package/.changeset/config.json +0 -11
- package/.github/CODEOWNERS +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -16
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -11
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/release.yml +0 -29
- package/.nvmrc +0 -1
- package/.project/ACCOUNT.yaml +0 -4
- package/.project/IDEAS.yaml +0 -7
- package/.project/PROJECT.yaml +0 -11
- package/.project/ROADMAP.yaml +0 -15
- package/CODE_OF_CONDUCT.md +0 -16
- package/CONTRIBUTING.md +0 -26
- package/SECURITY.md +0 -15
- package/SUPPORT.md +0 -8
- package/packages/convex/README.md +0 -1
- package/packages/convex/package.json +0 -12
- package/packages/convex/src/convex.config.ts +0 -3
- package/packages/convex/src/index.ts +0 -3
- package/packages/convex/src/mutations.ts +0 -36
- package/packages/convex/src/queries.ts +0 -19
- package/packages/convex/src/schema.ts +0 -24
- package/packages/convex/tsconfig.json +0 -25
- package/packages/react/README.md +0 -1
- package/packages/react/package.json +0 -46
- package/packages/react/src/components/ApprovalModal.tsx +0 -47
- package/packages/react/src/components/StepConfigPanel.tsx +0 -67
- package/packages/react/src/components/StepConnector.tsx +0 -47
- package/packages/react/src/components/StepNode.tsx +0 -38
- package/packages/react/src/components/StepPalette.tsx +0 -48
- package/packages/react/src/components/WorkflowCanvas.tsx +0 -42
- package/packages/react/src/components/WorkflowRunPanel.tsx +0 -64
- package/packages/react/src/components/WorkflowToolbar.tsx +0 -43
- package/packages/react/src/components/index.ts +0 -9
- package/packages/react/src/hooks/index.ts +0 -10
- package/packages/react/src/hooks/useApprovalGate.ts +0 -59
- package/packages/react/src/hooks/useWorkflow.ts +0 -39
- package/packages/react/src/hooks/useWorkflowBuilder.ts +0 -121
- package/packages/react/src/hooks/useWorkflowRun.ts +0 -75
- package/packages/react/src/hooks/useWorkflowStep.ts +0 -52
- package/packages/react/src/hooks/useWorkflowTemplates.ts +0 -54
- package/packages/react/src/index.ts +0 -16
- package/packages/react/src/pages/WorkflowBuilderPage.tsx +0 -81
- package/packages/react/src/pages/WorkflowRunsPage.tsx +0 -59
- package/packages/react/src/pages/index.ts +0 -3
- package/packages/react/tsconfig.json +0 -1
- package/packages/react/tsup.config.ts +0 -7
- package/packages/react-css/README.md +0 -1
- package/packages/react-css/package.json +0 -44
- package/packages/react-css/src/components/ApprovalModal.tsx +0 -6
- package/packages/react-css/src/components/StepConfigPanel.tsx +0 -7
- package/packages/react-css/src/components/StepConnector.tsx +0 -6
- package/packages/react-css/src/components/StepNode.tsx +0 -7
- package/packages/react-css/src/components/StepPalette.tsx +0 -6
- package/packages/react-css/src/components/WorkflowCanvas.tsx +0 -6
- package/packages/react-css/src/components/WorkflowRunPanel.tsx +0 -9
- package/packages/react-css/src/components/WorkflowToolbar.tsx +0 -4
- package/packages/react-css/src/components/index.ts +0 -9
- package/packages/react-css/src/hooks/index.ts +0 -3
- package/packages/react-css/src/hooks/useWorkflow.ts +0 -39
- package/packages/react-css/src/hooks/useWorkflowBuilder.ts +0 -121
- package/packages/react-css/src/index.ts +0 -7
- package/packages/react-css/src/pages/WorkflowBuilderPage.tsx +0 -16
- package/packages/react-css/src/pages/WorkflowRunsPage.tsx +0 -6
- package/packages/react-css/src/pages/index.ts +0 -3
- package/packages/react-css/tsconfig.json +0 -26
- package/packages/react-css/tsup.config.ts +0 -2
- package/packages/shared/README.md +0 -1
- package/packages/shared/package.json +0 -56
- package/packages/shared/src/__tests__/ai-workflow.test.ts +0 -217
- package/packages/shared/src/config.ts +0 -49
- package/packages/shared/src/convex/index.ts +0 -2
- package/packages/shared/src/convex/schemas.ts +0 -42
- package/packages/shared/src/engine.test.ts +0 -1
- package/packages/shared/src/engine.ts +0 -295
- package/packages/shared/src/index.ts +0 -43
- package/packages/shared/src/steps.ts +0 -68
- package/packages/shared/src/templates.ts +0 -172
- package/packages/shared/src/types.ts +0 -237
- package/packages/shared/src/utils/cost.ts +0 -79
- package/packages/shared/src/utils/dag.ts +0 -133
- package/packages/shared/src/utils/index.ts +0 -5
- package/packages/shared/src/utils/interpolation.ts +0 -53
- package/packages/shared/src/validators.ts +0 -215
- package/packages/shared/tsconfig.json +0 -1
- package/packages/shared/tsup.config.ts +0 -5
- package/packages/shared/vitest.config.ts +0 -4
- package/packages/solidjs/README.md +0 -1
- package/packages/solidjs/package.json +0 -45
- package/packages/solidjs/src/components/ApprovalModal.tsx +0 -18
- package/packages/solidjs/src/components/StepConfigPanel.tsx +0 -14
- package/packages/solidjs/src/components/StepConnector.tsx +0 -11
- package/packages/solidjs/src/components/StepNode.tsx +0 -12
- package/packages/solidjs/src/components/StepPalette.tsx +0 -22
- package/packages/solidjs/src/components/WorkflowCanvas.tsx +0 -23
- package/packages/solidjs/src/components/WorkflowRunPanel.tsx +0 -18
- package/packages/solidjs/src/components/WorkflowToolbar.tsx +0 -13
- package/packages/solidjs/src/components/index.ts +0 -9
- package/packages/solidjs/src/index.ts +0 -7
- package/packages/solidjs/src/pages/WorkflowBuilderPage.tsx +0 -37
- package/packages/solidjs/src/pages/WorkflowRunsPage.tsx +0 -20
- package/packages/solidjs/src/pages/index.ts +0 -3
- package/packages/solidjs/src/primitives/createApprovalGate.ts +0 -29
- package/packages/solidjs/src/primitives/createWorkflow.ts +0 -28
- package/packages/solidjs/src/primitives/createWorkflowBuilder.ts +0 -56
- package/packages/solidjs/src/primitives/createWorkflowRun.ts +0 -32
- package/packages/solidjs/src/primitives/createWorkflowStep.ts +0 -23
- package/packages/solidjs/src/primitives/createWorkflowTemplates.ts +0 -28
- package/packages/solidjs/src/primitives/index.ts +0 -8
- package/packages/solidjs/tsconfig.json +0 -1
- package/packages/solidjs/tsup.config.ts +0 -7
- package/packages/solidjs-css/README.md +0 -1
- package/packages/solidjs-css/package.json +0 -43
- package/packages/solidjs-css/src/components/ApprovalModal.tsx +0 -6
- package/packages/solidjs-css/src/components/StepConfigPanel.tsx +0 -7
- package/packages/solidjs-css/src/components/StepConnector.tsx +0 -6
- package/packages/solidjs-css/src/components/StepNode.tsx +0 -7
- package/packages/solidjs-css/src/components/StepPalette.tsx +0 -7
- package/packages/solidjs-css/src/components/WorkflowCanvas.tsx +0 -7
- package/packages/solidjs-css/src/components/WorkflowRunPanel.tsx +0 -8
- package/packages/solidjs-css/src/components/WorkflowToolbar.tsx +0 -5
- package/packages/solidjs-css/src/components/index.ts +0 -9
- package/packages/solidjs-css/src/index.ts +0 -7
- package/packages/solidjs-css/src/pages/WorkflowBuilderPage.tsx +0 -2
- package/packages/solidjs-css/src/pages/WorkflowRunsPage.tsx +0 -7
- package/packages/solidjs-css/src/pages/index.ts +0 -3
- package/packages/solidjs-css/src/primitives/createWorkflow.ts +0 -28
- package/packages/solidjs-css/src/primitives/createWorkflowBuilder.ts +0 -56
- package/packages/solidjs-css/src/primitives/index.ts +0 -1
- package/packages/solidjs-css/tsconfig.json +0 -27
- package/packages/solidjs-css/tsup.config.ts +0 -2
- package/pnpm-workspace.yaml +0 -2
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// @geenius-ai-workflow/shared — src/steps.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Built-in step factory helpers for easy workflow construction.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { WorkflowStepDef, LLMCallConfig, TransformConfig, ConditionConfig, HumanApprovalConfig, WebhookConfig, DelayConfig } from './types'
|
|
8
|
-
|
|
9
|
-
let stepCounter = 0
|
|
10
|
-
function nextId(): string {
|
|
11
|
-
return `step_${++stepCounter}_${Date.now()}`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Create an LLM call step */
|
|
15
|
-
export function llmStep(name: string, config: Omit<LLMCallConfig, 'type'>): WorkflowStepDef {
|
|
16
|
-
return { id: nextId(), name, type: 'llm-call', config: { type: 'llm-call', ...config } }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Create a data transform step */
|
|
20
|
-
export function transformStep(name: string, config: Omit<TransformConfig, 'type'>): WorkflowStepDef {
|
|
21
|
-
return { id: nextId(), name, type: 'transform', config: { type: 'transform', ...config } }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Create a condition (if/else) step */
|
|
25
|
-
export function conditionStep(name: string, config: Omit<ConditionConfig, 'type'>): WorkflowStepDef {
|
|
26
|
-
return { id: nextId(), name, type: 'condition', config: { type: 'condition', ...config } }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Create a human approval gate */
|
|
30
|
-
export function approvalStep(name: string, config: Omit<HumanApprovalConfig, 'type'>): WorkflowStepDef {
|
|
31
|
-
return { id: nextId(), name, type: 'human-approval', config: { type: 'human-approval', ...config } }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Create a webhook call step */
|
|
35
|
-
export function webhookStep(name: string, config: Omit<WebhookConfig, 'type'>): WorkflowStepDef {
|
|
36
|
-
return { id: nextId(), name, type: 'webhook', config: { type: 'webhook', ...config } }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Create a delay step */
|
|
40
|
-
export function delayStep(name: string, durationMs: number): WorkflowStepDef {
|
|
41
|
-
return { id: nextId(), name, type: 'delay', config: { type: 'delay', durationMs } }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Connect two steps (create a DAG edge).
|
|
46
|
-
*/
|
|
47
|
-
export function connect(fromStepId: string, toStepId: string, label?: string) {
|
|
48
|
-
return { fromStepId, toStepId, label }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Build a linear workflow from an ordered list of steps.
|
|
53
|
-
*/
|
|
54
|
-
export function linearWorkflow(
|
|
55
|
-
name: string,
|
|
56
|
-
steps: WorkflowStepDef[],
|
|
57
|
-
): { steps: WorkflowStepDef[]; connections: Array<{ fromStepId: string; toStepId: string }> } {
|
|
58
|
-
const connections = []
|
|
59
|
-
for (let i = 0; i < steps.length - 1; i++) {
|
|
60
|
-
connections.push({ fromStepId: steps[i].id, toStepId: steps[i + 1].id })
|
|
61
|
-
}
|
|
62
|
-
return { steps, connections }
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Reset the step counter (for testing) */
|
|
66
|
-
export function resetStepCounter(): void {
|
|
67
|
-
stepCounter = 0
|
|
68
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// @geenius-ai-workflow/shared — src/templates.ts
|
|
2
|
-
/**
|
|
3
|
-
* Pre-built workflow templates for common AI/business patterns.
|
|
4
|
-
*/
|
|
5
|
-
import type { WorkflowDefinition, WorkflowStepDef, StepConnection } from './types'
|
|
6
|
-
|
|
7
|
-
export interface WorkflowTemplate {
|
|
8
|
-
id: string
|
|
9
|
-
name: string
|
|
10
|
-
description: string
|
|
11
|
-
category: 'content' | 'data' | 'approval' | 'research' | 'devops'
|
|
12
|
-
tags: string[]
|
|
13
|
-
/** Factory that creates a fresh WorkflowDefinition from this template */
|
|
14
|
-
create: (createdBy: string) => WorkflowDefinition
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function uid(): string { return `step_tpl_${Date.now()}_${Math.random().toString(36).slice(2, 8)}` }
|
|
18
|
-
function wfId(): string { return `wf_${Date.now()}_${Math.random().toString(36).slice(2, 8)}` }
|
|
19
|
-
|
|
20
|
-
// ============================================================================
|
|
21
|
-
// 1. Content Pipeline
|
|
22
|
-
// ============================================================================
|
|
23
|
-
|
|
24
|
-
const contentPipeline: WorkflowTemplate = {
|
|
25
|
-
id: 'tpl-content-pipeline',
|
|
26
|
-
name: 'Content Pipeline',
|
|
27
|
-
description: 'Generate, review, and publish content with AI refinement and human approval.',
|
|
28
|
-
category: 'content',
|
|
29
|
-
tags: ['content', 'blog', 'marketing'],
|
|
30
|
-
create: (createdBy) => {
|
|
31
|
-
const draft = uid(), refine = uid(), approve = uid(), publish = uid()
|
|
32
|
-
const steps: WorkflowStepDef[] = [
|
|
33
|
-
{ id: draft, name: 'Generate Draft', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a content writer.', userPromptTemplate: 'Write a blog post about {{topic}}. Tone: {{tone}}.', outputVar: 'draft' }, position: { x: 100, y: 200 } },
|
|
34
|
-
{ id: refine, name: 'Refine Content', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are an editor. Improve clarity, grammar, and engagement.', userPromptTemplate: 'Polish this draft:\n\n{{draft}}', outputVar: 'polished' }, position: { x: 350, y: 200 } },
|
|
35
|
-
{ id: approve, name: 'Human Review', type: 'human-approval', config: { type: 'human-approval', message: 'Please review the polished content before publishing.' }, position: { x: 600, y: 200 } },
|
|
36
|
-
{ id: publish, name: 'Format for Publishing', type: 'transform', config: { type: 'transform', expression: '({ title: polished.split("\\n")[0], body: polished, publishedAt: Date.now() })', inputVars: ['polished'], outputVar: 'publishData' }, position: { x: 850, y: 200 } },
|
|
37
|
-
]
|
|
38
|
-
const connections: StepConnection[] = [
|
|
39
|
-
{ fromStepId: draft, toStepId: refine },
|
|
40
|
-
{ fromStepId: refine, toStepId: approve },
|
|
41
|
-
{ fromStepId: approve, toStepId: publish },
|
|
42
|
-
]
|
|
43
|
-
return { id: wfId(), name: 'Content Pipeline', description: 'AI-powered content generation with editorial review.', version: 1, status: 'draft', steps, connections, inputSchema: [{ name: 'topic', type: 'string', required: true }, { name: 'tone', type: 'string', required: false, default: 'professional' }], tags: ['content'], createdBy, createdAt: Date.now(), updatedAt: Date.now() }
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ============================================================================
|
|
48
|
-
// 2. Data Enrichment
|
|
49
|
-
// ============================================================================
|
|
50
|
-
|
|
51
|
-
const dataEnrichment: WorkflowTemplate = {
|
|
52
|
-
id: 'tpl-data-enrichment',
|
|
53
|
-
name: 'Data Enrichment',
|
|
54
|
-
description: 'Fetch external data, enrich with AI analysis, and transform for downstream use.',
|
|
55
|
-
category: 'data',
|
|
56
|
-
tags: ['data', 'analytics', 'enrichment'],
|
|
57
|
-
create: (createdBy) => {
|
|
58
|
-
const fetch_ = uid(), analyze = uid(), transform = uid()
|
|
59
|
-
const steps: WorkflowStepDef[] = [
|
|
60
|
-
{ id: fetch_, name: 'Fetch Data', type: 'webhook', config: { type: 'webhook', url: '{{dataSourceUrl}}', method: 'GET', outputVar: 'rawData' }, position: { x: 100, y: 200 } },
|
|
61
|
-
{ id: analyze, name: 'AI Analysis', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a data analyst. Analyze the data and extract key insights.', userPromptTemplate: 'Analyze this dataset and return a JSON summary with key metrics:\n\n{{rawData}}', parseJson: true, outputVar: 'analysis' }, position: { x: 400, y: 200 } },
|
|
62
|
-
{ id: transform, name: 'Transform Output', type: 'transform', config: { type: 'transform', expression: '({ ...analysis, enrichedAt: Date.now(), source: dataSourceUrl })', inputVars: ['analysis', 'dataSourceUrl'], outputVar: 'enrichedData' }, position: { x: 700, y: 200 } },
|
|
63
|
-
]
|
|
64
|
-
const connections: StepConnection[] = [
|
|
65
|
-
{ fromStepId: fetch_, toStepId: analyze },
|
|
66
|
-
{ fromStepId: analyze, toStepId: transform },
|
|
67
|
-
]
|
|
68
|
-
return { id: wfId(), name: 'Data Enrichment', version: 1, status: 'draft', steps, connections, inputSchema: [{ name: 'dataSourceUrl', type: 'string', required: true }], tags: ['data'], createdBy, createdAt: Date.now(), updatedAt: Date.now() }
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// ============================================================================
|
|
73
|
-
// 3. Approval Chain
|
|
74
|
-
// ============================================================================
|
|
75
|
-
|
|
76
|
-
const approvalChain: WorkflowTemplate = {
|
|
77
|
-
id: 'tpl-approval-chain',
|
|
78
|
-
name: 'Approval Chain',
|
|
79
|
-
description: 'Multi-level approval workflow with conditional escalation.',
|
|
80
|
-
category: 'approval',
|
|
81
|
-
tags: ['approval', 'governance', 'compliance'],
|
|
82
|
-
create: (createdBy) => {
|
|
83
|
-
const checkRisk = uid(), lowApproval = uid(), highApproval = uid(), finalize = uid()
|
|
84
|
-
const steps: WorkflowStepDef[] = [
|
|
85
|
-
{ id: checkRisk, name: 'Assess Risk Level', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'Assess the risk level of this request. Respond with JSON: {"riskLevel": "low"|"medium"|"high", "reason": "..."}', userPromptTemplate: '{{request}}', parseJson: true, outputVar: 'riskAssessment' }, position: { x: 100, y: 200 } },
|
|
86
|
-
{ id: lowApproval, name: 'Manager Approval', type: 'human-approval', config: { type: 'human-approval', message: 'Low/medium risk: Manager approval needed for: {{request}}' }, position: { x: 400, y: 100 } },
|
|
87
|
-
{ id: highApproval, name: 'Executive Approval', type: 'human-approval', config: { type: 'human-approval', message: 'High risk: Executive approval required for: {{request}}' }, position: { x: 400, y: 300 } },
|
|
88
|
-
{ id: finalize, name: 'Record Decision', type: 'transform', config: { type: 'transform', expression: '({ approved: true, approvedAt: Date.now(), riskLevel: riskAssessment.riskLevel })', inputVars: ['riskAssessment'], outputVar: 'decision' }, position: { x: 700, y: 200 } },
|
|
89
|
-
]
|
|
90
|
-
const connections: StepConnection[] = [
|
|
91
|
-
{ fromStepId: checkRisk, toStepId: lowApproval, condition: 'riskAssessment.riskLevel !== "high"' },
|
|
92
|
-
{ fromStepId: checkRisk, toStepId: highApproval, condition: 'riskAssessment.riskLevel === "high"' },
|
|
93
|
-
{ fromStepId: lowApproval, toStepId: finalize },
|
|
94
|
-
{ fromStepId: highApproval, toStepId: finalize },
|
|
95
|
-
]
|
|
96
|
-
return { id: wfId(), name: 'Approval Chain', version: 1, status: 'draft', steps, connections, inputSchema: [{ name: 'request', type: 'string', required: true }], tags: ['approval'], createdBy, createdAt: Date.now(), updatedAt: Date.now() }
|
|
97
|
-
},
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ============================================================================
|
|
101
|
-
// 4. Research Pipeline
|
|
102
|
-
// ============================================================================
|
|
103
|
-
|
|
104
|
-
const researchPipeline: WorkflowTemplate = {
|
|
105
|
-
id: 'tpl-research',
|
|
106
|
-
name: 'Research Pipeline',
|
|
107
|
-
description: 'Multi-source research with AI synthesis and summary generation.',
|
|
108
|
-
category: 'research',
|
|
109
|
-
tags: ['research', 'analysis', 'summary'],
|
|
110
|
-
create: (createdBy) => {
|
|
111
|
-
const research = uid(), synthesize = uid(), summarize = uid()
|
|
112
|
-
const steps: WorkflowStepDef[] = [
|
|
113
|
-
{ id: research, name: 'Deep Research', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a research assistant. Provide comprehensive, well-sourced research on the given topic.', userPromptTemplate: 'Research the following topic in depth: {{topic}}\n\nFocus areas: {{focusAreas}}', outputVar: 'researchOutput' }, position: { x: 100, y: 200 } },
|
|
114
|
-
{ id: synthesize, name: 'Synthesize Findings', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a synthesis expert. Combine research findings into structured insights with citations.', userPromptTemplate: 'Synthesize these research findings into key themes and actionable insights:\n\n{{researchOutput}}', parseJson: true, outputVar: 'synthesis' }, position: { x: 400, y: 200 } },
|
|
115
|
-
{ id: summarize, name: 'Executive Summary', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'Write a concise executive summary (3-5 paragraphs) suitable for senior leadership.', userPromptTemplate: 'Create an executive summary from:\n\n{{synthesis}}', outputVar: 'executiveSummary' }, position: { x: 700, y: 200 } },
|
|
116
|
-
]
|
|
117
|
-
const connections: StepConnection[] = [
|
|
118
|
-
{ fromStepId: research, toStepId: synthesize },
|
|
119
|
-
{ fromStepId: synthesize, toStepId: summarize },
|
|
120
|
-
]
|
|
121
|
-
return { id: wfId(), name: 'Research Pipeline', version: 1, status: 'draft', steps, connections, inputSchema: [{ name: 'topic', type: 'string', required: true }, { name: 'focusAreas', type: 'string', required: false, default: 'general overview' }], tags: ['research'], createdBy, createdAt: Date.now(), updatedAt: Date.now() }
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ============================================================================
|
|
126
|
-
// 5. Code Review Pipeline
|
|
127
|
-
// ============================================================================
|
|
128
|
-
|
|
129
|
-
const codeReviewPipeline: WorkflowTemplate = {
|
|
130
|
-
id: 'tpl-code-review',
|
|
131
|
-
name: 'Code Review Pipeline',
|
|
132
|
-
description: 'Automated code review with AI analysis, security check, and human approval.',
|
|
133
|
-
category: 'devops',
|
|
134
|
-
tags: ['code', 'review', 'security', 'devops'],
|
|
135
|
-
create: (createdBy) => {
|
|
136
|
-
const analyze = uid(), security = uid(), approve = uid(), report = uid()
|
|
137
|
-
const steps: WorkflowStepDef[] = [
|
|
138
|
-
{ id: analyze, name: 'AI Code Review', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a senior code reviewer. Analyze the code for bugs, performance issues, and best practices. Return JSON: {"issues": [], "suggestions": [], "quality": 1-10}', userPromptTemplate: 'Review this code:\n\n```{{language}}\n{{code}}\n```', parseJson: true, outputVar: 'codeReview' }, position: { x: 100, y: 200 } },
|
|
139
|
-
{ id: security, name: 'Security Scan', type: 'llm-call', config: { type: 'llm-call', systemPrompt: 'You are a security auditor. Check for vulnerabilities (XSS, SQL injection, secrets exposure, etc). Return JSON: {"vulnerabilities": [], "riskLevel": "low"|"medium"|"high"}', userPromptTemplate: 'Security audit for:\n\n```{{language}}\n{{code}}\n```', parseJson: true, outputVar: 'securityReport' }, position: { x: 100, y: 400 } },
|
|
140
|
-
{ id: approve, name: 'Developer Approval', type: 'human-approval', config: { type: 'human-approval', message: 'Review the AI code analysis and security scan before merging.' }, position: { x: 450, y: 300 } },
|
|
141
|
-
{ id: report, name: 'Generate Report', type: 'transform', config: { type: 'transform', expression: '({ codeQuality: codeReview.quality, issues: codeReview.issues.length, vulnerabilities: securityReport.vulnerabilities.length, riskLevel: securityReport.riskLevel, reviewedAt: Date.now() })', inputVars: ['codeReview', 'securityReport'], outputVar: 'finalReport' }, position: { x: 700, y: 300 } },
|
|
142
|
-
]
|
|
143
|
-
const connections: StepConnection[] = [
|
|
144
|
-
{ fromStepId: analyze, toStepId: approve },
|
|
145
|
-
{ fromStepId: security, toStepId: approve },
|
|
146
|
-
{ fromStepId: approve, toStepId: report },
|
|
147
|
-
]
|
|
148
|
-
return { id: wfId(), name: 'Code Review Pipeline', version: 1, status: 'draft', steps, connections, inputSchema: [{ name: 'code', type: 'string', required: true }, { name: 'language', type: 'string', required: false, default: 'typescript' }], tags: ['devops', 'review'], createdBy, createdAt: Date.now(), updatedAt: Date.now() }
|
|
149
|
-
},
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ============================================================================
|
|
153
|
-
// Template Registry
|
|
154
|
-
// ============================================================================
|
|
155
|
-
|
|
156
|
-
export const WORKFLOW_TEMPLATES: WorkflowTemplate[] = [
|
|
157
|
-
contentPipeline,
|
|
158
|
-
dataEnrichment,
|
|
159
|
-
approvalChain,
|
|
160
|
-
researchPipeline,
|
|
161
|
-
codeReviewPipeline,
|
|
162
|
-
]
|
|
163
|
-
|
|
164
|
-
/** Look up a template by ID */
|
|
165
|
-
export function getTemplate(id: string): WorkflowTemplate | undefined {
|
|
166
|
-
return WORKFLOW_TEMPLATES.find(t => t.id === id)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Filter templates by category */
|
|
170
|
-
export function getTemplatesByCategory(category: WorkflowTemplate['category']): WorkflowTemplate[] {
|
|
171
|
-
return WORKFLOW_TEMPLATES.filter(t => t.category === category)
|
|
172
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
// @geenius-ai-workflow/shared — src/types.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Workflow types — definitions, steps, runs, and execution state.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Core Types
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
export type WorkflowStatus = 'draft' | 'active' | 'paused' | 'archived'
|
|
12
|
-
export type RunStatus = 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled'
|
|
13
|
-
export type StepStatus = 'pending' | 'running' | 'completed' | 'failed' | 'skipped' | 'waiting-approval'
|
|
14
|
-
|
|
15
|
-
export type StepType =
|
|
16
|
-
| 'llm-call'
|
|
17
|
-
| 'transform'
|
|
18
|
-
| 'condition'
|
|
19
|
-
| 'human-approval'
|
|
20
|
-
| 'webhook'
|
|
21
|
-
| 'delay'
|
|
22
|
-
| 'parallel'
|
|
23
|
-
| 'loop'
|
|
24
|
-
| 'sub-workflow'
|
|
25
|
-
| 'custom'
|
|
26
|
-
|
|
27
|
-
export interface WorkflowDefinition {
|
|
28
|
-
id: string
|
|
29
|
-
name: string
|
|
30
|
-
description?: string
|
|
31
|
-
version: number
|
|
32
|
-
status: WorkflowStatus
|
|
33
|
-
/** Steps in execution order */
|
|
34
|
-
steps: WorkflowStepDef[]
|
|
35
|
-
/** Connections between steps (DAG edges) */
|
|
36
|
-
connections: StepConnection[]
|
|
37
|
-
/** Input variables the workflow accepts */
|
|
38
|
-
inputSchema?: WorkflowVariable[]
|
|
39
|
-
/** Global variables available to all steps */
|
|
40
|
-
variables?: Record<string, unknown>
|
|
41
|
-
/** Tags for organization */
|
|
42
|
-
tags?: string[]
|
|
43
|
-
createdBy: string
|
|
44
|
-
createdAt: number
|
|
45
|
-
updatedAt: number
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface WorkflowStepDef {
|
|
49
|
-
id: string
|
|
50
|
-
name: string
|
|
51
|
-
type: StepType
|
|
52
|
-
/** Step-specific configuration */
|
|
53
|
-
config: StepConfig
|
|
54
|
-
/** Position for visual builder */
|
|
55
|
-
position?: { x: number; y: number }
|
|
56
|
-
/** Whether this step can be skipped on failure */
|
|
57
|
-
optional?: boolean
|
|
58
|
-
/** Retry config */
|
|
59
|
-
retries?: { maxAttempts: number; backoffMs: number }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type StepConfig =
|
|
63
|
-
| LLMCallConfig
|
|
64
|
-
| TransformConfig
|
|
65
|
-
| ConditionConfig
|
|
66
|
-
| HumanApprovalConfig
|
|
67
|
-
| WebhookConfig
|
|
68
|
-
| DelayConfig
|
|
69
|
-
| ParallelConfig
|
|
70
|
-
| LoopConfig
|
|
71
|
-
| SubWorkflowConfig
|
|
72
|
-
| CustomStepConfig
|
|
73
|
-
|
|
74
|
-
export interface LLMCallConfig {
|
|
75
|
-
type: 'llm-call'
|
|
76
|
-
model?: string
|
|
77
|
-
systemPrompt: string
|
|
78
|
-
userPromptTemplate: string
|
|
79
|
-
temperature?: number
|
|
80
|
-
maxTokens?: number
|
|
81
|
-
/** Parse response as JSON */
|
|
82
|
-
parseJson?: boolean
|
|
83
|
-
/** Output variable name */
|
|
84
|
-
outputVar: string
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface TransformConfig {
|
|
88
|
-
type: 'transform'
|
|
89
|
-
/** JavaScript expression to evaluate (sandboxed) */
|
|
90
|
-
expression: string
|
|
91
|
-
/** Input variable names */
|
|
92
|
-
inputVars: string[]
|
|
93
|
-
/** Output variable name */
|
|
94
|
-
outputVar: string
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface ConditionConfig {
|
|
98
|
-
type: 'condition'
|
|
99
|
-
/** JavaScript expression that evaluates to boolean */
|
|
100
|
-
expression: string
|
|
101
|
-
/** Step ID to go to if true */
|
|
102
|
-
trueStepId: string
|
|
103
|
-
/** Step ID to go to if false */
|
|
104
|
-
falseStepId: string
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface HumanApprovalConfig {
|
|
108
|
-
type: 'human-approval'
|
|
109
|
-
message: string
|
|
110
|
-
/** Who can approve */
|
|
111
|
-
approvers?: string[]
|
|
112
|
-
/** Auto-approve after timeout (ms) */
|
|
113
|
-
autoApproveAfterMs?: number
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface WebhookConfig {
|
|
117
|
-
type: 'webhook'
|
|
118
|
-
url: string
|
|
119
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
120
|
-
headers?: Record<string, string>
|
|
121
|
-
bodyTemplate?: string
|
|
122
|
-
outputVar: string
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface DelayConfig {
|
|
126
|
-
type: 'delay'
|
|
127
|
-
durationMs: number
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface ParallelConfig {
|
|
131
|
-
type: 'parallel'
|
|
132
|
-
/** Step IDs to execute in parallel */
|
|
133
|
-
stepIds: string[]
|
|
134
|
-
/** How to handle failures: 'fail-fast' or 'continue' */
|
|
135
|
-
failurePolicy: 'fail-fast' | 'continue'
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface LoopConfig {
|
|
139
|
-
type: 'loop'
|
|
140
|
-
/** Step IDs to loop over */
|
|
141
|
-
stepIds: string[]
|
|
142
|
-
/** Variable containing the array to iterate */
|
|
143
|
-
iterateVar: string
|
|
144
|
-
/** Variable name for current item */
|
|
145
|
-
itemVar: string
|
|
146
|
-
/** Max iterations */
|
|
147
|
-
maxIterations?: number
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface SubWorkflowConfig {
|
|
151
|
-
type: 'sub-workflow'
|
|
152
|
-
workflowId: string
|
|
153
|
-
inputMapping: Record<string, string>
|
|
154
|
-
outputVar: string
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface CustomStepConfig {
|
|
158
|
-
type: 'custom'
|
|
159
|
-
handler: string
|
|
160
|
-
params: Record<string, unknown>
|
|
161
|
-
outputVar?: string
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface StepConnection {
|
|
165
|
-
fromStepId: string
|
|
166
|
-
toStepId: string
|
|
167
|
-
/** Optional label for the connection */
|
|
168
|
-
label?: string
|
|
169
|
-
/** Condition for conditional edges */
|
|
170
|
-
condition?: string
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export interface WorkflowVariable {
|
|
174
|
-
name: string
|
|
175
|
-
type: 'string' | 'number' | 'boolean' | 'object' | 'array'
|
|
176
|
-
description?: string
|
|
177
|
-
required?: boolean
|
|
178
|
-
default?: unknown
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ============================================================================
|
|
182
|
-
// Run Types
|
|
183
|
-
// ============================================================================
|
|
184
|
-
|
|
185
|
-
export interface WorkflowRun {
|
|
186
|
-
id: string
|
|
187
|
-
workflowId: string
|
|
188
|
-
workflowVersion: number
|
|
189
|
-
status: RunStatus
|
|
190
|
-
/** Input variables provided */
|
|
191
|
-
input: Record<string, unknown>
|
|
192
|
-
/** Current workflow variables state */
|
|
193
|
-
variables: Record<string, unknown>
|
|
194
|
-
/** Step execution results */
|
|
195
|
-
stepResults: StepResult[]
|
|
196
|
-
/** Current step index */
|
|
197
|
-
currentStepIndex: number
|
|
198
|
-
/** Error if failed */
|
|
199
|
-
error?: string
|
|
200
|
-
/** Who triggered the run */
|
|
201
|
-
triggeredBy: string
|
|
202
|
-
startedAt: number
|
|
203
|
-
completedAt?: number
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface StepResult {
|
|
207
|
-
stepId: string
|
|
208
|
-
stepName: string
|
|
209
|
-
type: StepType
|
|
210
|
-
status: StepStatus
|
|
211
|
-
/** Input variables for this step */
|
|
212
|
-
input?: Record<string, unknown>
|
|
213
|
-
/** Output from this step */
|
|
214
|
-
output?: unknown
|
|
215
|
-
/** Error message */
|
|
216
|
-
error?: string
|
|
217
|
-
/** Duration */
|
|
218
|
-
durationMs: number
|
|
219
|
-
/** Tokens used (for LLM steps) */
|
|
220
|
-
tokens?: number
|
|
221
|
-
/** Cost (for LLM steps) */
|
|
222
|
-
costUsd?: number
|
|
223
|
-
startedAt: number
|
|
224
|
-
completedAt?: number
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// ============================================================================
|
|
228
|
-
// Builder Types
|
|
229
|
-
// ============================================================================
|
|
230
|
-
|
|
231
|
-
export interface WorkflowBuilderState {
|
|
232
|
-
definition: WorkflowDefinition
|
|
233
|
-
selectedStepId: string | null
|
|
234
|
-
isDirty: boolean
|
|
235
|
-
undoStack: WorkflowDefinition[]
|
|
236
|
-
redoStack: WorkflowDefinition[]
|
|
237
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// @geenius-ai-workflow/shared — src/utils/cost.ts
|
|
2
|
-
/**
|
|
3
|
-
* Token and cost estimation for workflow runs.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { WorkflowDefinition, LLMCallConfig, StepResult } from '../types'
|
|
7
|
-
|
|
8
|
-
/** Cost-per-token rates by model (USD per 1K tokens) */
|
|
9
|
-
export const MODEL_RATES: Record<string, { input: number; output: number }> = {
|
|
10
|
-
'gpt-4o': { input: 0.0025, output: 0.01 },
|
|
11
|
-
'gpt-4o-mini': { input: 0.00015, output: 0.0006 },
|
|
12
|
-
'gpt-4-turbo': { input: 0.01, output: 0.03 },
|
|
13
|
-
'claude-3.5-sonnet': { input: 0.003, output: 0.015 },
|
|
14
|
-
'claude-3-haiku': { input: 0.00025, output: 0.00125 },
|
|
15
|
-
'gemini-pro': { input: 0.00025, output: 0.0005 },
|
|
16
|
-
'gemini-flash': { input: 0.000075, output: 0.0003 },
|
|
17
|
-
default: { input: 0.001, output: 0.003 },
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Rough token estimation (1 token ≈ 4 chars for English text) */
|
|
21
|
-
export function estimateTokens(text: string): number {
|
|
22
|
-
return Math.ceil(text.length / 4)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Estimate the token count for an LLM step */
|
|
26
|
-
export function estimateStepTokens(config: LLMCallConfig, vars: Record<string, unknown> = {}): { inputTokens: number; outputTokens: number } {
|
|
27
|
-
const systemTokens = estimateTokens(config.systemPrompt)
|
|
28
|
-
const templateTokens = estimateTokens(config.userPromptTemplate)
|
|
29
|
-
// Estimate expanded template by adding variable content lengths
|
|
30
|
-
const varTokens = Object.values(vars).reduce<number>((acc, v) => acc + estimateTokens(String(v ?? '')), 0)
|
|
31
|
-
const inputTokens = systemTokens + templateTokens + varTokens
|
|
32
|
-
const outputTokens = config.maxTokens ?? Math.ceil(inputTokens * 0.6)
|
|
33
|
-
return { inputTokens, outputTokens }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Estimate cost for a single step */
|
|
37
|
-
export function estimateStepCost(config: LLMCallConfig, vars: Record<string, unknown> = {}): number {
|
|
38
|
-
const { inputTokens, outputTokens } = estimateStepTokens(config, vars)
|
|
39
|
-
const rates = MODEL_RATES[config.model ?? 'default'] ?? MODEL_RATES.default
|
|
40
|
-
return (inputTokens / 1000) * rates.input + (outputTokens / 1000) * rates.output
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Estimate total cost for an entire workflow definition */
|
|
44
|
-
export function estimateWorkflowCost(definition: WorkflowDefinition, vars: Record<string, unknown> = {}): { totalCostUsd: number; totalTokens: number; stepEstimates: Array<{ stepId: string; stepName: string; costUsd: number; tokens: number }> } {
|
|
45
|
-
const stepEstimates: Array<{ stepId: string; stepName: string; costUsd: number; tokens: number }> = []
|
|
46
|
-
let totalCostUsd = 0
|
|
47
|
-
let totalTokens = 0
|
|
48
|
-
|
|
49
|
-
for (const step of definition.steps) {
|
|
50
|
-
if (step.config.type === 'llm-call') {
|
|
51
|
-
const config = step.config as LLMCallConfig
|
|
52
|
-
const cost = estimateStepCost(config, vars)
|
|
53
|
-
const { inputTokens, outputTokens } = estimateStepTokens(config, vars)
|
|
54
|
-
const tokens = inputTokens + outputTokens
|
|
55
|
-
stepEstimates.push({ stepId: step.id, stepName: step.name, costUsd: cost, tokens })
|
|
56
|
-
totalCostUsd += cost
|
|
57
|
-
totalTokens += tokens
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { totalCostUsd, totalTokens, stepEstimates }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Calculate actual cost from completed step results */
|
|
65
|
-
export function calculateRunCost(results: StepResult[]): { totalCostUsd: number; totalTokens: number } {
|
|
66
|
-
let totalCostUsd = 0
|
|
67
|
-
let totalTokens = 0
|
|
68
|
-
for (const r of results) {
|
|
69
|
-
if (r.costUsd) totalCostUsd += r.costUsd
|
|
70
|
-
if (r.tokens) totalTokens += r.tokens
|
|
71
|
-
}
|
|
72
|
-
return { totalCostUsd, totalTokens }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Format cost as a human-readable string */
|
|
76
|
-
export function formatCost(usd: number): string {
|
|
77
|
-
if (usd < 0.01) return `$${(usd * 100).toFixed(2)}¢`
|
|
78
|
-
return `$${usd.toFixed(4)}`
|
|
79
|
-
}
|