business-as-code 0.0.1 → 0.1.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/README.md +171 -368
- package/TODO.md +32 -0
- package/package.json +34 -35
- package/src/index.ts +77 -0
- package/src/types.ts +97 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +12 -0
- package/dist/index.d.ts +0 -146
- package/dist/index.js +0 -172
package/README.md
CHANGED
|
@@ -1,431 +1,234 @@
|
|
|
1
|
+
# business-as-code
|
|
2
|
+
|
|
1
3
|
[](https://www.npmjs.com/package/business-as-code)
|
|
2
|
-
[](https://www.npmjs.com/package/business-as-code)
|
|
3
4
|
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://www.typescriptlang.org/)
|
|
5
|
-
[](https://discord.gg/tafnNeUQdm)
|
|
6
|
-
[](https://github.com/drivly/ai/issues)
|
|
7
|
-
[](https://github.com/drivly/ai)
|
|
8
|
-
|
|
9
|
-
# business-as-code
|
|
10
5
|
|
|
11
|
-
>
|
|
6
|
+
> Define, launch, experiment, iterate, and grow your business entirely in code
|
|
12
7
|
|
|
13
8
|
## Overview
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
This paradigm builds upon core primitives like Functions, Workflows, and Agents, allowing complex business logic, processes, and even autonomous operations to be codified. By treating the business itself as a software system, we unlock unprecedented levels of agility, transparency, experimentation, and optimization.
|
|
18
|
-
|
|
19
|
-
Drawing inspiration from the principles outlined in the [Manifesto](/docs/manifesto) and leveraging the foundational [Primitives](/docs/primitives) of the [.do](https://dotdo.ai) ecosystem, `business-as-code` provides the framework to transform strategic objectives into measurable outcomes through code.
|
|
10
|
+
`business-as-code` enables organizations to represent their businesses and processes in code for human-AI collaboration. Unlike `ai-business` which focuses on AI-only businesses, this package provides interfaces for integrating human roles, AI agents, and defining collaboration points between them.
|
|
20
11
|
|
|
21
|
-
##
|
|
12
|
+
## Installation
|
|
22
13
|
|
|
23
|
-
|
|
14
|
+
```bash
|
|
15
|
+
npm install business-as-code
|
|
16
|
+
# or
|
|
17
|
+
yarn add business-as-code
|
|
18
|
+
# or
|
|
19
|
+
pnpm add business-as-code
|
|
20
|
+
```
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
## Usage
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
### Creating a Business with Human-AI Collaboration
|
|
28
25
|
|
|
29
26
|
```typescript
|
|
30
27
|
import { Business } from 'business-as-code'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
import { Human } from 'humans.do'
|
|
29
|
+
import { Agent } from 'agents.do'
|
|
30
|
+
import { Workflow } from 'workflows.do'
|
|
31
|
+
|
|
32
|
+
// Create human roles
|
|
33
|
+
class CEO extends Human {}
|
|
34
|
+
class CTO extends Human {}
|
|
35
|
+
class MarketingManager extends Human {}
|
|
36
|
+
|
|
37
|
+
// Create AI agents
|
|
38
|
+
class DataAnalyst extends Agent {}
|
|
39
|
+
class CustomerSupportAgent extends Agent {}
|
|
40
|
+
|
|
41
|
+
// Create business processes
|
|
42
|
+
class CustomerOnboarding extends Workflow {}
|
|
43
|
+
class ProductDevelopment extends Workflow {}
|
|
44
|
+
|
|
45
|
+
// Define your business
|
|
46
|
+
const myCompany = Business({
|
|
47
|
+
name: 'Acme Corporation',
|
|
48
|
+
url: 'https://acme.com',
|
|
49
|
+
vision: 'To revolutionize industry X with innovative solutions',
|
|
50
|
+
goals: [
|
|
51
|
+
{
|
|
52
|
+
objective: 'Increase market share by 20%',
|
|
53
|
+
keyResults: ['Launch 3 new products', 'Expand to 2 new geographical markets', 'Increase customer retention by 15%'],
|
|
43
54
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
],
|
|
56
|
+
// Human roles
|
|
57
|
+
roles: {
|
|
58
|
+
ceo: CEO,
|
|
59
|
+
cto: CTO,
|
|
60
|
+
marketingManager: MarketingManager,
|
|
61
|
+
},
|
|
62
|
+
// AI agents
|
|
63
|
+
agents: {
|
|
64
|
+
dataAnalyst: DataAnalyst,
|
|
65
|
+
customerSupport: CustomerSupportAgent,
|
|
66
|
+
},
|
|
67
|
+
// Organizational structure
|
|
68
|
+
departments: {
|
|
69
|
+
engineering: {
|
|
70
|
+
name: 'Engineering Department',
|
|
71
|
+
lead: CTO,
|
|
72
|
+
members: [DataAnalyst],
|
|
51
73
|
},
|
|
52
|
-
|
|
53
|
-
|
|
74
|
+
marketing: {
|
|
75
|
+
name: 'Marketing Department',
|
|
76
|
+
lead: MarketingManager,
|
|
77
|
+
members: [],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
// Business processes
|
|
81
|
+
processes: {
|
|
82
|
+
customerOnboarding: CustomerOnboarding,
|
|
83
|
+
productDevelopment: ProductDevelopment,
|
|
84
|
+
},
|
|
54
85
|
})
|
|
55
86
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Imperative Approach
|
|
61
|
-
|
|
62
|
-
Define specific processes step-by-step using workflows. This approach provides fine-grained control over execution and is suitable for well-defined, repeatable tasks. It leverages the patterns established in [Workflows.do](https://workflows.do).
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { Workflow } from 'workflows.do' // Assuming Workflow comes from workflows.do
|
|
66
|
-
|
|
67
|
-
const customerOnboarding = Workflow({
|
|
68
|
-
name: 'CustomerOnboarding',
|
|
69
|
-
|
|
70
|
-
onCustomerSignup: async ({ ai, api, db, event }) => {
|
|
71
|
-
const { name, email, company } = event
|
|
72
|
-
|
|
73
|
-
// Step 1: Enrich contact details using Integrations.do
|
|
74
|
-
const enrichedContact = await api.apollo.search({ name, email, company })
|
|
75
|
-
|
|
76
|
-
// Step 2: Analyze company background using Functions.do
|
|
77
|
-
const companyProfile = await ai.researchCompany({ company: enrichedContact.companyName || company })
|
|
78
|
-
|
|
79
|
-
// Step 3: Personalize welcome email using Functions.do
|
|
80
|
-
const welcomeEmail = await ai.personalizeWelcomeEmail({
|
|
81
|
-
name,
|
|
82
|
-
companyProfile
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// Step 4: Send email using Integrations.do
|
|
86
|
-
await api.sendgrid.sendEmail({
|
|
87
|
-
to: email,
|
|
88
|
-
subject: 'Welcome to TechInnovators!', // Hardcoded name for example clarity
|
|
89
|
-
body: welcomeEmail.content
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// Step 5: Create user record in Database.do
|
|
93
|
-
await db.users.create({
|
|
94
|
-
name,
|
|
95
|
-
email,
|
|
96
|
-
company: enrichedContact.companyName || company,
|
|
97
|
-
enrichedData: enrichedContact
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
// Step 6: Notify team via Slack using Integrations.do
|
|
101
|
-
await api.slack.postMessage({
|
|
102
|
-
channel: '#signups',
|
|
103
|
-
content: `New signup: ${name} from ${company}`,
|
|
104
|
-
})
|
|
105
|
-
}
|
|
87
|
+
// Event handling
|
|
88
|
+
myCompany.on('new_customer', (data) => {
|
|
89
|
+
// Trigger customer onboarding workflow
|
|
90
|
+
console.log(`New customer: ${data.name}`)
|
|
106
91
|
})
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Integration Between Approaches
|
|
110
|
-
|
|
111
|
-
The true power emerges when combining both approaches. Define high-level business goals declaratively, and implement specific, critical processes imperatively within the same framework.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
const combinedBusiness = Business({
|
|
115
|
-
name: 'HybridSolutions',
|
|
116
|
-
vision: '...',
|
|
117
|
-
objectives: { /* ... */ },
|
|
118
|
-
|
|
119
|
-
// Define specific workflows imperatively
|
|
120
|
-
workflows: {
|
|
121
|
-
customerOnboarding, // Reuse the imperative workflow defined above
|
|
122
|
-
// Add other critical workflows...
|
|
123
|
-
},
|
|
124
92
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
93
|
+
// Scheduled operations
|
|
94
|
+
myCompany.every('day', () => {
|
|
95
|
+
// Daily operations
|
|
96
|
+
console.log('Performing daily operations')
|
|
129
97
|
})
|
|
130
98
|
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
```
|
|
99
|
+
// Task assignment
|
|
100
|
+
myCompany.assign('Analyze quarterly sales data', myCompany.agents.dataAnalyst)
|
|
101
|
+
myCompany.assign('Review marketing strategy', myCompany.roles.marketingManager)
|
|
135
102
|
|
|
136
|
-
|
|
103
|
+
// Track business metrics
|
|
104
|
+
myCompany.track('customer_satisfaction', 4.8)
|
|
105
|
+
myCompany.track('monthly_revenue', 125000)
|
|
106
|
+
```
|
|
137
107
|
|
|
138
|
-
|
|
108
|
+
## Differences from `ai-business`
|
|
139
109
|
|
|
140
|
-
-
|
|
141
|
-
- **[Workflows](/docs/workflows)**: Orchestrate Functions into reliable, repeatable business processes. They combine different function types (Code, Generative, Agent, Human) to achieve specific outcomes aligned with business goals.
|
|
142
|
-
- **[Agents](/docs/agents)**: Autonomous digital workers driven by goals and measured by key results. They execute tasks, interact within workflows, and leverage Functions and external integrations.
|
|
110
|
+
While `ai-business` focuses on AI-driven business functions, `business-as-code` is designed specifically for representing existing organizations with both human employees and AI agents:
|
|
143
111
|
|
|
144
|
-
|
|
112
|
+
| Feature | business-as-code | ai-business |
|
|
113
|
+
| -------------------- | ---------------------------------- | ------------------------------ |
|
|
114
|
+
| Primary focus | Human-AI collaboration | AI-driven business functions |
|
|
115
|
+
| Organizational model | Comprehensive (roles, departments) | Limited (focused on functions) |
|
|
116
|
+
| Human roles | Explicit role definitions | Not specifically modeled |
|
|
117
|
+
| Decision approval | Built-in approval workflows | Automated decision making |
|
|
118
|
+
| Task assignment | Supports both humans and AI | Primarily AI-focused |
|
|
119
|
+
| Integration | Designed for existing org systems | Standalone AI capabilities |
|
|
145
120
|
|
|
146
|
-
##
|
|
121
|
+
## Key Design Considerations
|
|
147
122
|
|
|
148
|
-
|
|
123
|
+
### 1. Organizational hierarchy
|
|
149
124
|
|
|
150
125
|
```typescript
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// Define business model using structured components
|
|
160
|
-
businessModel: {
|
|
161
|
-
leanCanvas: LeanCanvas({
|
|
162
|
-
problem: ['Inefficient project tracking', 'Poor resource allocation'],
|
|
163
|
-
solution: 'AI-powered platform for automated task management and prediction',
|
|
164
|
-
keyMetrics: ['Daily active users', 'Project completion rate'],
|
|
165
|
-
uniqueValueProposition: 'Effortless project management with predictive insights',
|
|
166
|
-
unfairAdvantage: 'Proprietary predictive algorithms',
|
|
167
|
-
channels: ['Direct sales', 'Content marketing'],
|
|
168
|
-
customerSegments: ['Software development teams', 'Marketing agencies'],
|
|
169
|
-
costStructure: ['Cloud hosting', 'R&D salaries', 'Sales commissions'],
|
|
170
|
-
revenueStreams: ['SaaS subscription tiers', 'Premium support'],
|
|
171
|
-
}),
|
|
172
|
-
storyBrand: StoryBrand({
|
|
173
|
-
character: 'Project Managers',
|
|
174
|
-
problem: 'Overwhelmed by complexity and delays',
|
|
175
|
-
plan: 'Implement AgileAI for streamlined workflows',
|
|
176
|
-
success: 'Effortless project delivery and happy teams',
|
|
177
|
-
failure: 'Continued chaos and missed deadlines',
|
|
178
|
-
}),
|
|
179
|
-
// Add other relevant model components...
|
|
126
|
+
// Define departments with reporting lines
|
|
127
|
+
const company = Business({
|
|
128
|
+
departments: {
|
|
129
|
+
engineering: {
|
|
130
|
+
name: 'Engineering',
|
|
131
|
+
lead: CTO,
|
|
132
|
+
members: [SeniorEngineer, JuniorEngineer, AICodeReviewer],
|
|
133
|
+
},
|
|
180
134
|
},
|
|
181
|
-
|
|
182
|
-
workflows: { /* ... */ },
|
|
183
|
-
agents: { /* ... */ },
|
|
184
135
|
})
|
|
185
|
-
|
|
186
|
-
await myStartup.launch()
|
|
187
136
|
```
|
|
188
137
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
Business-as-Code enables rapid experimentation directly within your operational framework. Test hypotheses, measure results, and iterate on your strategies and processes using code.
|
|
138
|
+
### 2. Human-AI collaboration points
|
|
192
139
|
|
|
193
140
|
```typescript
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
vision: '...',
|
|
199
|
-
objectives: {
|
|
200
|
-
userAcquisition: {
|
|
201
|
-
description: 'Maximize new user signups',
|
|
202
|
-
keyResults: ['Increase weekly signups by 20% in Q3']
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
// ... other definitions
|
|
141
|
+
// AI can suggest changes that require human approval
|
|
142
|
+
company.on('content_suggestion', (suggestion, approver) => {
|
|
143
|
+
// Request approval from human
|
|
144
|
+
approver.requestApproval(suggestion)
|
|
206
145
|
})
|
|
207
|
-
|
|
208
|
-
// Define an experiment to test different onboarding flows
|
|
209
|
-
const onboardingExperiment = Experiment({
|
|
210
|
-
name: 'Onboarding Flow Test',
|
|
211
|
-
hypothesis: 'A simplified onboarding flow will increase signup conversion rate.',
|
|
212
|
-
variants: {
|
|
213
|
-
control: { // Current implementation (defined elsewhere or implicitly handled)
|
|
214
|
-
workflow: 'standardOnboardingWorkflow'
|
|
215
|
-
},
|
|
216
|
-
simplified: { // New variant defined imperatively
|
|
217
|
-
workflow: Workflow({
|
|
218
|
-
name: 'SimplifiedOnboarding',
|
|
219
|
-
onUserVisit: async ({ ai, api, event }) => {
|
|
220
|
-
// Minimal steps for quick signup
|
|
221
|
-
const { email } = event
|
|
222
|
-
await api.auth.createAccount({ email })
|
|
223
|
-
await api.sendgrid.sendEmail({ to: email, template: 'quick_welcome' })
|
|
224
|
-
// ... fewer steps than control
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
metrics: ['signupConversionRate', 'timeToSignup'],
|
|
230
|
-
trafficSplit: { control: 0.5, simplified: 0.5 },
|
|
231
|
-
targetObjective: experimentalBusiness.objectives.userAcquisition,
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
// Add the experiment to the business definition
|
|
235
|
-
experimentalBusiness.addExperiment(onboardingExperiment)
|
|
236
|
-
|
|
237
|
-
// Launch the business with the experiment running
|
|
238
|
-
await experimentalBusiness.launch()
|
|
239
|
-
|
|
240
|
-
// Later, analyze results (assuming analysis functions exist)
|
|
241
|
-
// const results = await experimentalBusiness.analyzeExperiment('Onboarding Flow Test')
|
|
242
|
-
// console.log(results)
|
|
243
146
|
```
|
|
244
147
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
Here's a comprehensive example demonstrating how to define a SaaS business using the `business-as-code` framework:
|
|
148
|
+
### 3. Task assignment
|
|
248
149
|
|
|
249
150
|
```typescript
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
// Example: Lead Generation Workflow
|
|
257
|
-
const leadGeneration = Workflow({
|
|
258
|
-
name: 'LeadGeneration',
|
|
259
|
-
onWebsiteVisit: async ({ ai, api, db, event }) => {
|
|
260
|
-
const { visitorId, pageUrl } = event
|
|
261
|
-
// Track visit
|
|
262
|
-
await db.events.log({ type: 'website_visit', visitorId, pageUrl })
|
|
263
|
-
|
|
264
|
-
// If visitor shows interest (e.g., downloads whitepaper)
|
|
265
|
-
if (event.action === 'download_whitepaper') {
|
|
266
|
-
const leadData = await api.hubspot.findContact({ email: event.email }) // Use Integrations.do
|
|
267
|
-
if (!leadData) {
|
|
268
|
-
await api.hubspot.createContact({ email: event.email, name: event.name })
|
|
269
|
-
await api.slack.postMessage({ channel: '#leads', content: `New lead: ${event.name} (${event.email})`})
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
// Example: Customer Support Agent
|
|
276
|
-
const supportAgent = Agent({
|
|
277
|
-
name: 'SupportAgent',
|
|
278
|
-
goal: 'Resolve customer support tickets efficiently and effectively',
|
|
279
|
-
keyResults: [
|
|
280
|
-
'Maintain average first response time under 1 hour',
|
|
281
|
-
'Achieve customer satisfaction score (CSAT) of 90%+'
|
|
282
|
-
],
|
|
283
|
-
onTicketReceived: async ({ ai, api, db, ticket }) => {
|
|
284
|
-
// Analyze ticket content
|
|
285
|
-
const analysis = await ai.analyzeSupportTicket({ content: ticket.description })
|
|
286
|
-
|
|
287
|
-
// Find relevant documentation using Functions.do
|
|
288
|
-
const relevantDocs = await ai.findRelevantDocs({ query: analysis.topic })
|
|
289
|
-
|
|
290
|
-
// Draft response
|
|
291
|
-
const draftResponse = await ai.draftSupportResponse({
|
|
292
|
-
query: ticket.description,
|
|
293
|
-
context: relevantDocs
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
// Post response (or assign to human if needed)
|
|
297
|
-
await api.zendesk.updateTicket({ id: ticket.id, comment: draftResponse.content })
|
|
151
|
+
// Assign tasks based on nature and complexity
|
|
152
|
+
function assignTask(task) {
|
|
153
|
+
if (task.requiresCreativity) {
|
|
154
|
+
company.assign(task, company.roles.humanCreative)
|
|
155
|
+
} else if (task.isRepetitive) {
|
|
156
|
+
company.assign(task, company.agents.automationAgent)
|
|
298
157
|
}
|
|
299
|
-
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
300
160
|
|
|
301
|
-
|
|
302
|
-
const saasCompany = Business({
|
|
303
|
-
name: 'DataInsights',
|
|
304
|
-
vision: 'Make data analytics accessible to non-technical teams',
|
|
305
|
-
|
|
306
|
-
objectives: {
|
|
307
|
-
growth: {
|
|
308
|
-
description: 'Achieve market leadership in SMB analytics',
|
|
309
|
-
keyResults: [
|
|
310
|
-
'Acquire 1000 paying customers by end of year',
|
|
311
|
-
'Reach $1M ARR within 18 months',
|
|
312
|
-
]
|
|
313
|
-
},
|
|
314
|
-
product: {
|
|
315
|
-
description: 'Deliver an intuitive and powerful analytics platform',
|
|
316
|
-
keyResults: [
|
|
317
|
-
'Achieve a Net Promoter Score (NPS) of 50+',
|
|
318
|
-
'Reduce onboarding time to under 30 minutes',
|
|
319
|
-
]
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
// Integrate defined workflows
|
|
324
|
-
workflows: {
|
|
325
|
-
leadGeneration,
|
|
326
|
-
customerOnboarding, // Reuse from earlier example
|
|
327
|
-
// Add billing, feature-request workflows etc.
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
// Integrate defined agents
|
|
331
|
-
agents: {
|
|
332
|
-
supportAgent,
|
|
333
|
-
// Add sales outreach agent, data analysis agent etc.
|
|
334
|
-
},
|
|
335
|
-
|
|
336
|
-
// Define the core data model using Database.do concepts
|
|
337
|
-
dataModel: {
|
|
338
|
-
users: Database.collection({ /* ... schema ... */ }),
|
|
339
|
-
organizations: Database.collection({ /* ... schema ... */ }),
|
|
340
|
-
datasets: Database.collection({ /* ... schema ... */ }),
|
|
341
|
-
reports: Database.collection({ /* ... schema ... */ }),
|
|
342
|
-
// Define relationships, indexes etc.
|
|
343
|
-
},
|
|
161
|
+
### 4. Event handling differences
|
|
344
162
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const reportData = await db.reports.find({ id: input.reportId })
|
|
354
|
-
// Complex AI logic to derive insights...
|
|
355
|
-
const insights = await ai.analyzeDataAndGenerateInsights({ data: reportData })
|
|
356
|
-
return { insights }
|
|
357
|
-
}
|
|
358
|
-
})
|
|
359
|
-
// Add other core business functions
|
|
163
|
+
```typescript
|
|
164
|
+
// Human events may require notifications
|
|
165
|
+
company.on('urgent_issue', (issue) => {
|
|
166
|
+
if (issue.assignee instanceof Human) {
|
|
167
|
+
sendNotification(issue.assignee)
|
|
168
|
+
} else {
|
|
169
|
+
// AI can handle immediately
|
|
170
|
+
issue.assignee.handle(issue)
|
|
360
171
|
}
|
|
361
172
|
})
|
|
362
|
-
|
|
363
|
-
// Launch the business operations
|
|
364
|
-
await saasCompany.launch()
|
|
365
|
-
|
|
366
|
-
console.log(`Business '${saasCompany.name}' launched successfully.`) // Note: Backticks are fine for template literals
|
|
367
173
|
```
|
|
368
174
|
|
|
369
|
-
|
|
175
|
+
### 5. Permission workflows
|
|
370
176
|
|
|
371
|
-
|
|
177
|
+
```typescript
|
|
178
|
+
// AI can draft but needs human approval for publishing
|
|
179
|
+
company.agents.contentWriter.setPermission('content.publish', 'suggest')
|
|
180
|
+
company.roles.contentManager.setPermission('content.publish', 'approve')
|
|
181
|
+
```
|
|
372
182
|
|
|
373
|
-
|
|
183
|
+
### 6. System integration
|
|
374
184
|
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
185
|
+
```typescript
|
|
186
|
+
// Connect with existing organizational systems
|
|
187
|
+
company.integrate('crm', {
|
|
188
|
+
endpoint: 'https://crm.company.com/api',
|
|
189
|
+
handlers: {
|
|
190
|
+
// Map events between systems
|
|
191
|
+
'crm:new_customer': (data) => company.trigger('new_customer', data),
|
|
192
|
+
},
|
|
193
|
+
})
|
|
381
194
|
```
|
|
382
195
|
|
|
383
|
-
###
|
|
384
|
-
|
|
385
|
-
1. **Import necessary components**: Start by importing `Business` and other primitives like `Workflow`, `Agent`, or `Function` as needed.
|
|
386
|
-
2. **Define your Business**: Use the `Business()` constructor, providing a name, vision, and objectives.
|
|
387
|
-
3. **Codify Components**: Define your core workflows, agents, data models, and functions using the respective primitives.
|
|
388
|
-
4. **Integrate Components**: Add your defined workflows, agents, etc., into the `Business` definition.
|
|
389
|
-
5. **Launch**: Call the `.launch()` method on your business instance to start its operations.
|
|
196
|
+
### 7. Role guidelines
|
|
390
197
|
|
|
391
198
|
```typescript
|
|
392
|
-
|
|
199
|
+
// Define when to use humans vs AI
|
|
200
|
+
const roleGuidelines = {
|
|
201
|
+
customer_complaints: {
|
|
202
|
+
simple: company.agents.customerSupport,
|
|
203
|
+
complex: company.roles.customerSuccessManager,
|
|
204
|
+
criteria: (complaint) => (complaint.sentiment < -0.8 ? 'complex' : 'simple'),
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
```
|
|
393
208
|
|
|
394
|
-
|
|
395
|
-
const mySimpleBusiness = Business({
|
|
396
|
-
name: 'My First Coded Business',
|
|
397
|
-
vision: 'To automate simple tasks',
|
|
398
|
-
objectives: {
|
|
399
|
-
taskAutomation: {
|
|
400
|
-
description: 'Automate one repetitive task this quarter',
|
|
401
|
-
keyResults: ['Successfully automate task X by end of Q3']
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
// Add simple workflows or functions if needed
|
|
405
|
-
})
|
|
209
|
+
## API Reference
|
|
406
210
|
|
|
407
|
-
|
|
408
|
-
async function start() {
|
|
409
|
-
await mySimpleBusiness.launch()
|
|
410
|
-
console.log('Business launched!')
|
|
411
|
-
}
|
|
211
|
+
### Functions
|
|
412
212
|
|
|
413
|
-
|
|
414
|
-
```
|
|
213
|
+
- `Business(config)` - Creates a new business representation
|
|
415
214
|
|
|
416
|
-
|
|
215
|
+
### Types
|
|
417
216
|
|
|
418
|
-
|
|
217
|
+
- `BusinessConfig` - Configuration for creating a business
|
|
218
|
+
- `BusinessInstance` - Instance returned by the Business function
|
|
219
|
+
- `PermissionLevel` - Enum for permission levels (VIEW, SUGGEST, EXECUTE, APPROVE, ADMIN)
|
|
220
|
+
- `Task` - Interface for task assignments
|
|
221
|
+
- `BusinessEvent` - Interface for business events
|
|
419
222
|
|
|
420
|
-
|
|
223
|
+
### Business Instance Methods
|
|
421
224
|
|
|
422
|
-
|
|
225
|
+
- `on(event, handler)` - Register event handler
|
|
226
|
+
- `every(schedule, operation)` - Register scheduled operation
|
|
227
|
+
- `assign(task, to)` - Assign a task to a human or AI
|
|
228
|
+
- `track(metric, value)` - Track business metrics
|
|
423
229
|
|
|
424
|
-
|
|
230
|
+
## Dependencies
|
|
425
231
|
|
|
426
|
-
- [
|
|
427
|
-
- [
|
|
428
|
-
- [workflows.do](https://
|
|
429
|
-
- [agents.do](https://www.npmjs.com/package/agents.do) - Autonomous AI workers.
|
|
430
|
-
- [database.do](https://www.npmjs.com/package/database.do) - AI Native Data Access.
|
|
431
|
-
- Other `.do` services as needed (Events, Analytics, etc.)
|
|
232
|
+
- [agents.do](https://github.com/drivly/agents.do) - Agent framework for AI operations
|
|
233
|
+
- [humans.do](https://github.com/drivly/humans.do) - Human role definitions and interactions
|
|
234
|
+
- [workflows.do](https://github.com/drivly/workflows.do) - Workflow definitions for business processes
|
package/TODO.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# business-as-code Implementation TODO
|
|
2
|
+
|
|
3
|
+
## Current Implementation Status
|
|
4
|
+
|
|
5
|
+
- [x] Created package structure
|
|
6
|
+
- [x] Implemented package.json with basic configuration
|
|
7
|
+
- [x] Implemented tsup.config.ts for build configuration
|
|
8
|
+
- [x] Implemented tsconfig.json
|
|
9
|
+
- [x] Created types.ts with BusinessConfig interface
|
|
10
|
+
- [x] Implemented Business function in index.ts
|
|
11
|
+
- [x] Created comprehensive README.md
|
|
12
|
+
- [ ] Implement actual dependencies for human-AI collaboration
|
|
13
|
+
- [ ] Test integration with other packages
|
|
14
|
+
|
|
15
|
+
## Technical Challenges and Blockers
|
|
16
|
+
|
|
17
|
+
- The package currently uses placeholder types for `Agent`, `Human`, and `Workflow` since the actual dependencies (`agents.do`, `humans.do`, `workflows.do`) don't exist yet
|
|
18
|
+
- Need to implement or find suitable replacements for these dependencies
|
|
19
|
+
- The Business function implementation is a proof of concept and needs to be expanded with actual functionality
|
|
20
|
+
|
|
21
|
+
## Verification Requirements
|
|
22
|
+
|
|
23
|
+
- Ensure the package builds correctly
|
|
24
|
+
- Verify TypeScript types are generated correctly
|
|
25
|
+
- Test integration with other packages when dependencies are available
|
|
26
|
+
|
|
27
|
+
## Next Steps
|
|
28
|
+
|
|
29
|
+
- Replace placeholder types with actual implementations when dependencies are available
|
|
30
|
+
- Expand the Business function with more comprehensive features
|
|
31
|
+
- Add tests for the Business function
|
|
32
|
+
- Integrate with existing systems and workflows
|
package/package.json
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "business-as-code",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Define, launch, experiment, iterate, and grow your business entirely in code
|
|
5
|
-
"keywords": [
|
|
6
|
-
"ai",
|
|
7
|
-
"business",
|
|
8
|
-
"strategy",
|
|
9
|
-
"operations",
|
|
10
|
-
"automation",
|
|
11
|
-
"sdk",
|
|
12
|
-
"typescript"
|
|
13
|
-
],
|
|
14
|
-
"homepage": "https://business-as-code.dev",
|
|
15
|
-
"type": "module",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Define, launch, experiment, iterate, and grow your business entirely in code",
|
|
16
5
|
"main": "dist/index.js",
|
|
17
|
-
"module": "dist/index.
|
|
6
|
+
"module": "dist/index.mjs",
|
|
18
7
|
"types": "dist/index.d.ts",
|
|
19
8
|
"exports": {
|
|
20
9
|
".": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
23
13
|
}
|
|
24
14
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"zod": "^3.24.3"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.13.10",
|
|
20
|
+
"esbuild": "^0.25.2",
|
|
21
|
+
"eslint": "^9.17.0",
|
|
22
|
+
"prettier": "^3.4.2",
|
|
23
|
+
"typescript": "^5.8.2",
|
|
24
|
+
"tsup": "^8.4.0"
|
|
25
|
+
},
|
|
29
26
|
"repository": {
|
|
30
27
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/drivly/ai.git"
|
|
32
|
-
"directory": "pkgs/business-as-code"
|
|
28
|
+
"url": "https://github.com/drivly/primitives.org.ai.git"
|
|
33
29
|
},
|
|
34
|
-
"
|
|
35
|
-
"license": "MIT",
|
|
30
|
+
"homepage": "https://mdx.org.ai",
|
|
36
31
|
"bugs": {
|
|
37
|
-
"url": "https://github.com/drivly/ai/issues"
|
|
32
|
+
"url": "https://github.com/drivly/primitives.org.ai/issues"
|
|
38
33
|
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"ai",
|
|
36
|
+
"business",
|
|
37
|
+
"human-ai-collaboration",
|
|
38
|
+
"organization",
|
|
39
|
+
"processes",
|
|
40
|
+
"departments",
|
|
41
|
+
"roles"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
39
44
|
"scripts": {
|
|
40
|
-
"build": "tsup
|
|
41
|
-
"dev": "tsup
|
|
42
|
-
"
|
|
43
|
-
"clean": "rimraf .turbo node_modules dist",
|
|
44
|
-
"test": "vitest run",
|
|
45
|
-
"test:watch": "vitest"
|
|
46
|
-
},
|
|
47
|
-
"engines": {
|
|
48
|
-
"node": ">=18.0.0"
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"format": "prettier --write ."
|
|
49
48
|
}
|
|
50
|
-
}
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Agent, Human, Workflow } from './types'
|
|
2
|
+
import { BusinessConfig, BusinessInstance, PermissionLevel, Task, BusinessEvent } from './types'
|
|
3
|
+
|
|
4
|
+
export { Agent, Human, Workflow }
|
|
5
|
+
export type { BusinessConfig, BusinessInstance, PermissionLevel, Task, BusinessEvent }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a business representation for human-AI collaboration
|
|
9
|
+
*
|
|
10
|
+
* @param config The business configuration
|
|
11
|
+
* @returns A business instance with methods for event handling, scheduling, and task management
|
|
12
|
+
*/
|
|
13
|
+
export function Business(config: BusinessConfig): BusinessInstance {
|
|
14
|
+
const eventHandlers: Record<string, Function[]> = {}
|
|
15
|
+
|
|
16
|
+
const scheduledOperations: Record<string, Function[]> = {}
|
|
17
|
+
|
|
18
|
+
const tasks: Task[] = []
|
|
19
|
+
|
|
20
|
+
const metrics: Record<string, any[]> = {}
|
|
21
|
+
|
|
22
|
+
const business: BusinessInstance = {
|
|
23
|
+
...config,
|
|
24
|
+
|
|
25
|
+
on: (event: string, handler: Function) => {
|
|
26
|
+
if (!eventHandlers[event]) {
|
|
27
|
+
eventHandlers[event] = []
|
|
28
|
+
}
|
|
29
|
+
eventHandlers[event].push(handler)
|
|
30
|
+
|
|
31
|
+
return business // For chaining
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
every: (schedule: string, operation: Function) => {
|
|
35
|
+
if (!scheduledOperations[schedule]) {
|
|
36
|
+
scheduledOperations[schedule] = []
|
|
37
|
+
}
|
|
38
|
+
scheduledOperations[schedule].push(operation)
|
|
39
|
+
|
|
40
|
+
return business // For chaining
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
assign: (taskTitle: string, to: Human | Agent) => {
|
|
44
|
+
const task: Task = {
|
|
45
|
+
id: `task_${Date.now()}`,
|
|
46
|
+
title: taskTitle,
|
|
47
|
+
assignee: to,
|
|
48
|
+
status: 'pending',
|
|
49
|
+
timestamp: new Date(),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
tasks.push(task)
|
|
53
|
+
|
|
54
|
+
if (to instanceof Agent) {
|
|
55
|
+
task.status = 'in_progress'
|
|
56
|
+
} else {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return task // Return task for reference
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
track: (metric: string, value: any) => {
|
|
63
|
+
if (!metrics[metric]) {
|
|
64
|
+
metrics[metric] = []
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
metrics[metric].push({
|
|
68
|
+
value,
|
|
69
|
+
timestamp: new Date(),
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
return business // For chaining
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return business
|
|
77
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export class Agent {}
|
|
2
|
+
export class Human {}
|
|
3
|
+
export class Workflow {}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Business configuration interface
|
|
7
|
+
*/
|
|
8
|
+
export interface BusinessConfig {
|
|
9
|
+
name: string
|
|
10
|
+
url?: string
|
|
11
|
+
vision?: string
|
|
12
|
+
goals?: Array<{
|
|
13
|
+
objective: string
|
|
14
|
+
keyResults?: string[]
|
|
15
|
+
}>
|
|
16
|
+
roles?: Record<string, Human>
|
|
17
|
+
agents?: Record<string, Agent>
|
|
18
|
+
departments?: Record<
|
|
19
|
+
string,
|
|
20
|
+
{
|
|
21
|
+
name: string
|
|
22
|
+
lead: Human | Agent
|
|
23
|
+
members?: Array<Human | Agent>
|
|
24
|
+
}
|
|
25
|
+
>
|
|
26
|
+
processes?: Record<string, Workflow>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Business instance returned by the Business function
|
|
31
|
+
*/
|
|
32
|
+
export interface BusinessInstance {
|
|
33
|
+
name: string
|
|
34
|
+
url?: string
|
|
35
|
+
vision?: string
|
|
36
|
+
goals?: Array<{
|
|
37
|
+
objective: string
|
|
38
|
+
keyResults?: string[]
|
|
39
|
+
}>
|
|
40
|
+
roles?: Record<string, Human>
|
|
41
|
+
agents?: Record<string, Agent>
|
|
42
|
+
departments?: Record<
|
|
43
|
+
string,
|
|
44
|
+
{
|
|
45
|
+
name: string
|
|
46
|
+
lead: Human | Agent
|
|
47
|
+
members?: Array<Human | Agent>
|
|
48
|
+
}
|
|
49
|
+
>
|
|
50
|
+
processes?: Record<string, Workflow>
|
|
51
|
+
|
|
52
|
+
on: (event: string, handler: Function) => void
|
|
53
|
+
|
|
54
|
+
every: (schedule: string, operation: Function) => void
|
|
55
|
+
|
|
56
|
+
assign: (task: string, to: Human | Agent) => void
|
|
57
|
+
|
|
58
|
+
track: (metric: string, value: any) => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Permission level enum for human-AI collaboration
|
|
63
|
+
*/
|
|
64
|
+
export enum PermissionLevel {
|
|
65
|
+
VIEW = 'view',
|
|
66
|
+
SUGGEST = 'suggest',
|
|
67
|
+
EXECUTE = 'execute',
|
|
68
|
+
APPROVE = 'approve',
|
|
69
|
+
ADMIN = 'admin',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Task assignment interface
|
|
74
|
+
*/
|
|
75
|
+
export interface Task {
|
|
76
|
+
id: string
|
|
77
|
+
title: string
|
|
78
|
+
description?: string
|
|
79
|
+
assignee?: Human | Agent
|
|
80
|
+
dueDate?: Date
|
|
81
|
+
status?: 'pending' | 'in_progress' | 'completed' | 'blocked'
|
|
82
|
+
priority?: 'low' | 'medium' | 'high' | 'critical'
|
|
83
|
+
requiredPermission?: PermissionLevel
|
|
84
|
+
dependencies?: string[]
|
|
85
|
+
timestamp?: Date
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Event interface for business events
|
|
90
|
+
*/
|
|
91
|
+
export interface BusinessEvent {
|
|
92
|
+
type: string
|
|
93
|
+
data: any
|
|
94
|
+
source?: string
|
|
95
|
+
timestamp: Date
|
|
96
|
+
requiredApproval?: Human[]
|
|
97
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
package/dist/index.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
interface BusinessInterface {
|
|
2
|
-
name: string;
|
|
3
|
-
vision: string;
|
|
4
|
-
objectives: Record<string, Objective>;
|
|
5
|
-
workflows?: Record<string, Workflow>;
|
|
6
|
-
agents?: Record<string, Agent>;
|
|
7
|
-
businessModel?: BusinessModel;
|
|
8
|
-
execute(): Promise<void>;
|
|
9
|
-
launch(): Promise<void>;
|
|
10
|
-
addExperiment(experiment: ExperimentInterface): void;
|
|
11
|
-
}
|
|
12
|
-
interface Objective {
|
|
13
|
-
description: string;
|
|
14
|
-
keyResults: string[] | KeyResult[];
|
|
15
|
-
}
|
|
16
|
-
interface KeyResult {
|
|
17
|
-
description: string;
|
|
18
|
-
target?: number;
|
|
19
|
-
currentValue?: number;
|
|
20
|
-
unit?: string;
|
|
21
|
-
dueDate?: Date;
|
|
22
|
-
}
|
|
23
|
-
interface ExperimentInterface {
|
|
24
|
-
name: string;
|
|
25
|
-
hypothesis: string;
|
|
26
|
-
variants: Record<string, ExperimentVariant>;
|
|
27
|
-
metrics: string[];
|
|
28
|
-
trafficSplit: Record<string, number>;
|
|
29
|
-
targetObjective?: Objective;
|
|
30
|
-
start(): Promise<void>;
|
|
31
|
-
stop(): Promise<void>;
|
|
32
|
-
analyze(): Promise<ExperimentResults>;
|
|
33
|
-
}
|
|
34
|
-
interface ExperimentVariant {
|
|
35
|
-
workflow?: Workflow | string;
|
|
36
|
-
agent?: Agent | string;
|
|
37
|
-
function?: Function | string;
|
|
38
|
-
configuration?: Record<string, any>;
|
|
39
|
-
}
|
|
40
|
-
interface ExperimentResults {
|
|
41
|
-
variantPerformance: Record<string, VariantPerformance>;
|
|
42
|
-
winner?: string;
|
|
43
|
-
confidence?: number;
|
|
44
|
-
insights: string[];
|
|
45
|
-
}
|
|
46
|
-
interface VariantPerformance {
|
|
47
|
-
metrics: Record<string, number>;
|
|
48
|
-
sampleSize: number;
|
|
49
|
-
}
|
|
50
|
-
interface BusinessModel {
|
|
51
|
-
leanCanvas?: LeanCanvasModel;
|
|
52
|
-
storyBrand?: StoryBrandModel;
|
|
53
|
-
valueProposition?: ValuePropositionModel;
|
|
54
|
-
revenueStreams?: RevenueStream[];
|
|
55
|
-
customerSegments?: CustomerSegment[];
|
|
56
|
-
}
|
|
57
|
-
interface LeanCanvasModel {
|
|
58
|
-
problem: string[];
|
|
59
|
-
solution: string[];
|
|
60
|
-
uniqueValueProposition: string;
|
|
61
|
-
unfairAdvantage?: string;
|
|
62
|
-
customerSegments: string[];
|
|
63
|
-
keyMetrics: string[];
|
|
64
|
-
channels: string[];
|
|
65
|
-
costStructure: string[];
|
|
66
|
-
revenueStreams: string[];
|
|
67
|
-
}
|
|
68
|
-
interface StoryBrandModel {
|
|
69
|
-
hero: string;
|
|
70
|
-
problem: string;
|
|
71
|
-
guide: string;
|
|
72
|
-
plan: string[];
|
|
73
|
-
callToAction: string;
|
|
74
|
-
failure: string;
|
|
75
|
-
success: string;
|
|
76
|
-
}
|
|
77
|
-
interface ValuePropositionModel {
|
|
78
|
-
customerJobs: string[];
|
|
79
|
-
pains: string[];
|
|
80
|
-
gains: string[];
|
|
81
|
-
products: string[];
|
|
82
|
-
painRelievers: string[];
|
|
83
|
-
gainCreators: string[];
|
|
84
|
-
}
|
|
85
|
-
interface RevenueStream {
|
|
86
|
-
name: string;
|
|
87
|
-
type: 'subscription' | 'transactional' | 'service' | 'product' | 'other';
|
|
88
|
-
pricingModel: string;
|
|
89
|
-
estimatedRevenue?: number;
|
|
90
|
-
}
|
|
91
|
-
interface CustomerSegment {
|
|
92
|
-
name: string;
|
|
93
|
-
description: string;
|
|
94
|
-
needs: string[];
|
|
95
|
-
demographics?: Record<string, string>;
|
|
96
|
-
behaviors?: string[];
|
|
97
|
-
}
|
|
98
|
-
interface Workflow {
|
|
99
|
-
name: string;
|
|
100
|
-
steps: WorkflowStep[];
|
|
101
|
-
execute(input?: any): Promise<any>;
|
|
102
|
-
}
|
|
103
|
-
interface WorkflowStep {
|
|
104
|
-
name: string;
|
|
105
|
-
function?: Function | string;
|
|
106
|
-
agent?: Agent | string;
|
|
107
|
-
input?: Record<string, any> | ((context: any) => any);
|
|
108
|
-
condition?: (context: any) => boolean;
|
|
109
|
-
onSuccess?: WorkflowStep | string;
|
|
110
|
-
onError?: WorkflowStep | string;
|
|
111
|
-
}
|
|
112
|
-
interface Function {
|
|
113
|
-
name: string;
|
|
114
|
-
execute(input?: any): Promise<any>;
|
|
115
|
-
}
|
|
116
|
-
interface Agent {
|
|
117
|
-
name: string;
|
|
118
|
-
execute(task: string, context?: any): Promise<any>;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Creates a new Business instance
|
|
123
|
-
*/
|
|
124
|
-
declare function Business(config: Omit<BusinessInterface, 'execute' | 'launch' | 'addExperiment'>): BusinessInterface;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Creates a new Experiment instance
|
|
128
|
-
*/
|
|
129
|
-
declare function Experiment(config: Omit<ExperimentInterface, 'start' | 'stop' | 'analyze'>): ExperimentInterface;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Creates a new LeanCanvas instance
|
|
133
|
-
*/
|
|
134
|
-
declare function LeanCanvas(config: LeanCanvasModel): LeanCanvasModel;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Creates a new StoryBrand instance
|
|
138
|
-
*/
|
|
139
|
-
declare function StoryBrand(config: StoryBrandModel): StoryBrandModel;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Creates a new ValueProposition instance
|
|
143
|
-
*/
|
|
144
|
-
declare function ValueProposition(config: ValuePropositionModel): ValuePropositionModel;
|
|
145
|
-
|
|
146
|
-
export { type Agent, Business, type BusinessInterface, type BusinessModel, type CustomerSegment, Experiment, type ExperimentInterface, type ExperimentResults, type ExperimentVariant, type Function, type KeyResult, LeanCanvas, type Objective, type RevenueStream, StoryBrand, ValueProposition, type VariantPerformance, type Workflow, type WorkflowStep };
|
package/dist/index.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// src/business.ts
|
|
2
|
-
function Business(config) {
|
|
3
|
-
const experiments = [];
|
|
4
|
-
const state = {
|
|
5
|
-
isLaunched: false,
|
|
6
|
-
isExecuting: false,
|
|
7
|
-
metrics: {}
|
|
8
|
-
};
|
|
9
|
-
const business = {
|
|
10
|
-
...config,
|
|
11
|
-
addExperiment(experiment) {
|
|
12
|
-
experiments.push(experiment);
|
|
13
|
-
},
|
|
14
|
-
async launch() {
|
|
15
|
-
if (state.isLaunched) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (business.workflows) {
|
|
19
|
-
for (const workflowKey in business.workflows) {
|
|
20
|
-
const workflow = business.workflows[workflowKey];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (business.agents) {
|
|
24
|
-
for (const agentKey in business.agents) {
|
|
25
|
-
const agent = business.agents[agentKey];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
state.isLaunched = true;
|
|
29
|
-
},
|
|
30
|
-
async execute() {
|
|
31
|
-
if (state.isExecuting) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (!state.isLaunched) {
|
|
35
|
-
await business.launch();
|
|
36
|
-
}
|
|
37
|
-
state.isExecuting = true;
|
|
38
|
-
try {
|
|
39
|
-
if (business.workflows) {
|
|
40
|
-
for (const workflowKey in business.workflows) {
|
|
41
|
-
const workflow = business.workflows[workflowKey];
|
|
42
|
-
await workflow.execute();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
for (const experiment of experiments) {
|
|
46
|
-
await experiment.start();
|
|
47
|
-
}
|
|
48
|
-
} finally {
|
|
49
|
-
state.isExecuting = false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
return business;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/experiment.ts
|
|
57
|
-
function Experiment(config) {
|
|
58
|
-
const state = {
|
|
59
|
-
isRunning: false,
|
|
60
|
-
startTime: null,
|
|
61
|
-
endTime: null,
|
|
62
|
-
variantData: {}
|
|
63
|
-
};
|
|
64
|
-
for (const variantKey in config.variants) {
|
|
65
|
-
state.variantData[variantKey] = {
|
|
66
|
-
metrics: config.metrics.reduce((acc, metric) => {
|
|
67
|
-
acc[metric] = [];
|
|
68
|
-
return acc;
|
|
69
|
-
}, {}),
|
|
70
|
-
sampleCount: 0
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const experiment = {
|
|
74
|
-
...config,
|
|
75
|
-
async start() {
|
|
76
|
-
if (state.isRunning) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
state.isRunning = true;
|
|
80
|
-
state.startTime = /* @__PURE__ */ new Date();
|
|
81
|
-
for (const variantKey in experiment.variants) {
|
|
82
|
-
const variant = experiment.variants[variantKey];
|
|
83
|
-
if (typeof variant.workflow === "string") {
|
|
84
|
-
}
|
|
85
|
-
if (typeof variant.agent === "string") {
|
|
86
|
-
}
|
|
87
|
-
if (typeof variant.function === "string") {
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
async stop() {
|
|
92
|
-
if (!state.isRunning) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
state.isRunning = false;
|
|
96
|
-
state.endTime = /* @__PURE__ */ new Date();
|
|
97
|
-
},
|
|
98
|
-
async analyze() {
|
|
99
|
-
if (state.isRunning) {
|
|
100
|
-
await experiment.stop();
|
|
101
|
-
}
|
|
102
|
-
const variantPerformance = {};
|
|
103
|
-
for (const variantKey in state.variantData) {
|
|
104
|
-
const variantData = state.variantData[variantKey];
|
|
105
|
-
const metrics = {};
|
|
106
|
-
for (const metricKey in variantData.metrics) {
|
|
107
|
-
const values = variantData.metrics[metricKey];
|
|
108
|
-
if (values.length > 0) {
|
|
109
|
-
metrics[metricKey] = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
110
|
-
} else {
|
|
111
|
-
metrics[metricKey] = 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
variantPerformance[variantKey] = {
|
|
115
|
-
metrics,
|
|
116
|
-
sampleSize: variantData.sampleCount
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
let winner;
|
|
120
|
-
let highestScore = -Infinity;
|
|
121
|
-
const primaryMetric = experiment.metrics[0];
|
|
122
|
-
for (const variantKey in variantPerformance) {
|
|
123
|
-
const performance = variantPerformance[variantKey];
|
|
124
|
-
const score = performance.metrics[primaryMetric] || 0;
|
|
125
|
-
if (score > highestScore) {
|
|
126
|
-
highestScore = score;
|
|
127
|
-
winner = variantKey;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const insights = [
|
|
131
|
-
`Experiment ran for ${state.startTime && state.endTime ? Math.round((state.endTime.getTime() - state.startTime.getTime()) / (1e3 * 60 * 60 * 24)) : "unknown"} days`,
|
|
132
|
-
winner ? `Variant "${winner}" performed best on primary metric "${primaryMetric}"` : "No clear winner determined"
|
|
133
|
-
];
|
|
134
|
-
return {
|
|
135
|
-
variantPerformance,
|
|
136
|
-
winner,
|
|
137
|
-
confidence: 0.95,
|
|
138
|
-
// Placeholder - would calculate actual confidence in real implementation
|
|
139
|
-
insights
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
return experiment;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/models/lean-canvas.ts
|
|
147
|
-
function LeanCanvas(config) {
|
|
148
|
-
return {
|
|
149
|
-
...config
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/models/story-brand.ts
|
|
154
|
-
function StoryBrand(config) {
|
|
155
|
-
return {
|
|
156
|
-
...config
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// src/models/value-proposition.ts
|
|
161
|
-
function ValueProposition(config) {
|
|
162
|
-
return {
|
|
163
|
-
...config
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
export {
|
|
167
|
-
Business,
|
|
168
|
-
Experiment,
|
|
169
|
-
LeanCanvas,
|
|
170
|
-
StoryBrand,
|
|
171
|
-
ValueProposition
|
|
172
|
-
};
|