business-as-code 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +431 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +172 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/business-as-code)
|
|
2
|
+
[](https://www.npmjs.com/package/business-as-code)
|
|
3
|
+
[](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
|
+
|
|
11
|
+
> Build, define, launch, experiment, iterate, and grow your business entirely in code.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Business-as-Code represents a revolutionary approach to defining, operating, and scaling businesses. It moves beyond traditional methods by enabling the entire business lifecycle—from initial concept and strategy to execution and iteration—to be managed through clean, structured, and executable code.
|
|
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.
|
|
20
|
+
|
|
21
|
+
## Declarative vs. Imperative Approaches
|
|
22
|
+
|
|
23
|
+
The `business-as-code` package supports two complementary approaches to defining and executing business logic:
|
|
24
|
+
|
|
25
|
+
### Declarative Approach
|
|
26
|
+
|
|
27
|
+
Define your business at a high level using objectives and key results (OKRs). The system, powered by AI, determines the optimal implementation strategy. This approach is ideal for setting strategic direction and allowing flexibility in execution.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Business } from 'business-as-code'
|
|
31
|
+
|
|
32
|
+
const myBusiness = Business({
|
|
33
|
+
name: 'TechInnovators',
|
|
34
|
+
vision: 'Democratize AI for small businesses',
|
|
35
|
+
objectives: {
|
|
36
|
+
customerSuccess: {
|
|
37
|
+
description: 'Create delighted customers who achieve their goals',
|
|
38
|
+
keyResults: [
|
|
39
|
+
'Achieve 95% customer satisfaction score by Q4',
|
|
40
|
+
'Reduce average support ticket resolution time by 30% within 6 months',
|
|
41
|
+
'Increase customer retention rate to 85% year-over-year',
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
productInnovation: {
|
|
45
|
+
description: 'Continuously deliver cutting-edge AI solutions',
|
|
46
|
+
keyResults: [
|
|
47
|
+
'Launch 3 new major features based on customer feedback this year',
|
|
48
|
+
'Secure 2 patents for novel AI algorithms',
|
|
49
|
+
'Increase R&D investment by 15% annually',
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
// More objectives...
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// Let the AI determine and execute the best approach to achieve the objectives
|
|
57
|
+
await myBusiness.execute()
|
|
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
|
+
}
|
|
106
|
+
})
|
|
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
|
+
|
|
125
|
+
// Define autonomous agents
|
|
126
|
+
agents: {
|
|
127
|
+
// Agents can leverage both declarative goals and imperative workflows
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// Execute the business, allowing AI to manage undeclared processes
|
|
132
|
+
// while respecting the defined imperative workflows.
|
|
133
|
+
await combinedBusiness.launch()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Core Primitives
|
|
137
|
+
|
|
138
|
+
Business-as-Code builds upon a foundation of powerful, composable primitives inherited from the [.do](https://dotdo.ai) ecosystem:
|
|
139
|
+
|
|
140
|
+
- **[Functions](/docs/functions)**: The atomic units of work. They can be deterministic code, AI-driven generation, autonomous agent tasks, or even human actions, all with strongly-typed inputs and outputs.
|
|
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.
|
|
143
|
+
|
|
144
|
+
These primitives provide the building blocks for codifying every aspect of a business.
|
|
145
|
+
|
|
146
|
+
## Business Model Components
|
|
147
|
+
|
|
148
|
+
Define key aspects of your business model directly in code. This allows for a structured, version-controlled representation of your strategy, integrating frameworks like Lean Canvas or StoryBrand.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { Business } from 'business-as-code'
|
|
152
|
+
import { LeanCanvas, StoryBrand } from 'business-model-components' // Hypothetical import
|
|
153
|
+
|
|
154
|
+
const myStartup = Business({
|
|
155
|
+
name: 'AgileAI',
|
|
156
|
+
vision: 'Empower teams with AI-driven project management',
|
|
157
|
+
objectives: { /* ... */ },
|
|
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...
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
workflows: { /* ... */ },
|
|
183
|
+
agents: { /* ... */ },
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
await myStartup.launch()
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Experimentation and Iteration
|
|
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.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { Business, Experiment, Workflow } from 'business-as-code' // Assuming Workflow is exported here or import from 'workflows.do'
|
|
195
|
+
|
|
196
|
+
const experimentalBusiness = Business({
|
|
197
|
+
name: 'GrowthHackers Inc.',
|
|
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
|
|
206
|
+
})
|
|
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
|
+
```
|
|
244
|
+
|
|
245
|
+
## Real-World Examples
|
|
246
|
+
|
|
247
|
+
Here's a comprehensive example demonstrating how to define a SaaS business using the `business-as-code` framework:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { Business, Workflow, Agent, Function } from 'business-as-code' // Assuming all primitives are exported
|
|
251
|
+
import { Database } from 'database.do' // Assuming Database comes from database.do
|
|
252
|
+
import { API } from 'apis.do' // Assuming API comes from apis.do
|
|
253
|
+
|
|
254
|
+
// Define core business logic components first (Workflows, Agents, Functions)
|
|
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 })
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
// Define the complete SaaS business
|
|
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
|
+
},
|
|
344
|
+
|
|
345
|
+
// Define core functions the business relies on
|
|
346
|
+
functions: {
|
|
347
|
+
// Example: A function to generate insights from data
|
|
348
|
+
generateReportInsights: Function({
|
|
349
|
+
name: 'GenerateReportInsights',
|
|
350
|
+
input: { reportId: 'string' },
|
|
351
|
+
output: { insights: 'string[]' },
|
|
352
|
+
run: async ({ input, ai, db }) => {
|
|
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
|
|
360
|
+
}
|
|
361
|
+
})
|
|
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
|
+
```
|
|
368
|
+
|
|
369
|
+
## Getting Started
|
|
370
|
+
|
|
371
|
+
### Installation
|
|
372
|
+
|
|
373
|
+
To install the `business-as-code` package, use your preferred package manager:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
pnpm add business-as-code # Using pnpm (recommended for this monorepo)
|
|
377
|
+
# or
|
|
378
|
+
npm install business-as-code
|
|
379
|
+
# or
|
|
380
|
+
yarn add business-as-code
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Basic Usage
|
|
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.
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
import { Business } from 'business-as-code'
|
|
393
|
+
|
|
394
|
+
// 1. Define the business high-level goals
|
|
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
|
+
})
|
|
406
|
+
|
|
407
|
+
// 2. Launch the business
|
|
408
|
+
async function start() {
|
|
409
|
+
await mySimpleBusiness.launch()
|
|
410
|
+
console.log('Business launched!')
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
start()
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
This basic structure provides the starting point for building more complex, fully codified businesses. Explore the examples above and the documentation for individual primitives ([Functions](/docs/functions), [Workflows](/docs/workflows), [Agents](/docs/agents)) to learn more.
|
|
417
|
+
|
|
418
|
+
## License
|
|
419
|
+
|
|
420
|
+
MIT
|
|
421
|
+
|
|
422
|
+
## Foundational Primitives
|
|
423
|
+
|
|
424
|
+
Business-as-Code builds upon and orchestrates the core primitives of the [.do](https://dotdo.ai) ecosystem:
|
|
425
|
+
|
|
426
|
+
- [apis.do](https://www.npmjs.com/package/apis.do) - The foundational SDK for all integrations.
|
|
427
|
+
- [functions.do](https://www.npmjs.com/package/functions.do) - AI-powered Functions-as-a-Service.
|
|
428
|
+
- [workflows.do](https://www.npmjs.com/package/workflows.do) - Elegant business process orchestration.
|
|
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.)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "business-as-code",
|
|
3
|
+
"version": "0.0.1",
|
|
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",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/drivly/ai.git",
|
|
32
|
+
"directory": "pkgs/business-as-code"
|
|
33
|
+
},
|
|
34
|
+
"author": "Drivly",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/drivly/ai/issues"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
41
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
42
|
+
"lint": "eslint \"src/**/*.ts*\"",
|
|
43
|
+
"clean": "rimraf .turbo node_modules dist",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|