xcomponent-ai 0.3.2 → 0.4.2

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.
@@ -0,0 +1,279 @@
1
+ # Subscription Lifecycle Management
2
+ #
3
+ # Ce composant gère le cycle de vie d'un abonnement SaaS:
4
+ # - Période d'essai
5
+ # - Activation et renouvellement
6
+ # - Suspension pour non-paiement
7
+ # - Mise à niveau / rétrogradation
8
+ # - Annulation avec période de grâce
9
+ #
10
+ # Pattern: Lifecycle avec états récurrents
11
+
12
+ name: SubscriptionLifecycle
13
+ entryMachine: Subscription
14
+
15
+ stateMachines:
16
+ - name: Subscription
17
+ initialState: Trial
18
+ publicMemberType: Subscription
19
+
20
+ contextSchema:
21
+ subscriptionId:
22
+ type: string
23
+ label: "Subscription ID"
24
+ required: true
25
+ placeholder: "SUB-001"
26
+ customerId:
27
+ type: string
28
+ label: "Customer ID"
29
+ required: true
30
+ customerEmail:
31
+ type: string
32
+ label: "Customer Email"
33
+ required: true
34
+ plan:
35
+ type: select
36
+ label: "Plan"
37
+ required: true
38
+ options:
39
+ - value: starter
40
+ label: "Starter - 9€/month"
41
+ - value: professional
42
+ label: "Professional - 29€/month"
43
+ - value: enterprise
44
+ label: "Enterprise - 99€/month"
45
+ billingCycle:
46
+ type: select
47
+ label: "Billing Cycle"
48
+ options:
49
+ - value: monthly
50
+ label: "Monthly"
51
+ - value: yearly
52
+ label: "Yearly (2 months free)"
53
+
54
+ states:
55
+ - name: Trial
56
+ type: entry
57
+ description: "Free trial period (14 days)"
58
+ onEntry: sendWelcomeEmail
59
+
60
+ - name: TrialExpiring
61
+ description: "Trial about to expire (3 days left)"
62
+ onEntry: sendTrialExpiringReminder
63
+
64
+ - name: Active
65
+ description: "Subscription is active and paid"
66
+ onEntry: provisionResources
67
+
68
+ - name: PastDue
69
+ description: "Payment failed, grace period"
70
+ onEntry: sendPaymentFailedNotification
71
+
72
+ - name: Suspended
73
+ description: "Service suspended due to non-payment"
74
+ onEntry: suspendService
75
+
76
+ - name: Cancelled
77
+ description: "Subscription cancelled, access until period end"
78
+ onEntry: scheduleCancellation
79
+
80
+ - name: Expired
81
+ type: final
82
+ description: "Subscription has ended"
83
+ onEntry: deprovisionResources
84
+
85
+ - name: Churned
86
+ type: final
87
+ description: "Customer churned (no reactivation)"
88
+ onEntry: recordChurn
89
+
90
+ transitions:
91
+ # Trial flow
92
+ - from: Trial
93
+ to: TrialExpiring
94
+ event: TRIAL_EXPIRING_SOON
95
+ type: timeout
96
+ timeoutMs: 950400000 # 11 days (14 - 3)
97
+
98
+ - from: Trial
99
+ to: Active
100
+ event: SUBSCRIBE
101
+ triggeredMethod: createInitialInvoice
102
+
103
+ - from: Trial
104
+ to: Expired
105
+ event: TRIAL_ENDED
106
+ type: timeout
107
+ timeoutMs: 1209600000 # 14 days
108
+
109
+ - from: TrialExpiring
110
+ to: Active
111
+ event: SUBSCRIBE
112
+ triggeredMethod: createInitialInvoice
113
+
114
+ - from: TrialExpiring
115
+ to: Expired
116
+ event: TRIAL_ENDED
117
+ type: timeout
118
+ timeoutMs: 259200000 # 3 days
119
+
120
+ # Active subscription
121
+ - from: Active
122
+ to: Active
123
+ event: PAYMENT_SUCCESS
124
+ type: internal
125
+ triggeredMethod: extendSubscription
126
+
127
+ - from: Active
128
+ to: Active
129
+ event: PLAN_CHANGED
130
+ type: internal
131
+ triggeredMethod: handlePlanChange
132
+
133
+ - from: Active
134
+ to: PastDue
135
+ event: PAYMENT_FAILED
136
+ triggeredMethod: scheduleRetryPayment
137
+
138
+ - from: Active
139
+ to: Cancelled
140
+ event: CANCEL
141
+ triggeredMethod: calculateEndDate
142
+
143
+ # Past due (grace period)
144
+ - from: PastDue
145
+ to: Active
146
+ event: PAYMENT_SUCCESS
147
+ triggeredMethod: clearPastDueStatus
148
+
149
+ - from: PastDue
150
+ to: PastDue
151
+ event: PAYMENT_FAILED
152
+ type: internal
153
+ triggeredMethod: scheduleRetryPayment
154
+ guard:
155
+ expression: "context.retryCount < 3"
156
+
157
+ - from: PastDue
158
+ to: Suspended
159
+ event: PAYMENT_FAILED
160
+ guard:
161
+ expression: "context.retryCount >= 3"
162
+
163
+ - from: PastDue
164
+ to: Suspended
165
+ event: GRACE_PERIOD_ENDED
166
+ type: timeout
167
+ timeoutMs: 1209600000 # 14 days grace period
168
+
169
+ - from: PastDue
170
+ to: Cancelled
171
+ event: CANCEL
172
+
173
+ # Suspended
174
+ - from: Suspended
175
+ to: Active
176
+ event: PAYMENT_SUCCESS
177
+ triggeredMethod: reactivateService
178
+
179
+ - from: Suspended
180
+ to: Churned
181
+ event: SUSPENSION_TIMEOUT
182
+ type: timeout
183
+ timeoutMs: 2592000000 # 30 days
184
+
185
+ - from: Suspended
186
+ to: Cancelled
187
+ event: CANCEL
188
+
189
+ # Cancelled (access until period end)
190
+ - from: Cancelled
191
+ to: Expired
192
+ event: PERIOD_ENDED
193
+ description: "Triggered when current billing period ends"
194
+
195
+ - from: Cancelled
196
+ to: Active
197
+ event: REACTIVATE
198
+ triggeredMethod: resumeSubscription
199
+
200
+ # Billing processor (handles recurring payments)
201
+ - name: BillingCycle
202
+ initialState: Scheduled
203
+ publicMemberType: Invoice
204
+
205
+ contextSchema:
206
+ invoiceId:
207
+ type: string
208
+ label: "Invoice ID"
209
+ required: true
210
+ subscriptionId:
211
+ type: string
212
+ label: "Subscription ID"
213
+ required: true
214
+ amount:
215
+ type: number
216
+ label: "Amount"
217
+ required: true
218
+
219
+ states:
220
+ - name: Scheduled
221
+ type: entry
222
+ description: "Invoice scheduled for future date"
223
+
224
+ - name: Pending
225
+ description: "Invoice due, awaiting payment"
226
+ onEntry: chargePaymentMethod
227
+
228
+ - name: Processing
229
+ description: "Payment being processed"
230
+
231
+ - name: Paid
232
+ type: final
233
+ description: "Invoice paid successfully"
234
+ onEntry: notifySubscriptionPaymentSuccess
235
+
236
+ - name: Failed
237
+ description: "Payment failed"
238
+ onEntry: notifySubscriptionPaymentFailed
239
+
240
+ - name: Voided
241
+ type: final
242
+ description: "Invoice cancelled/voided"
243
+
244
+ transitions:
245
+ - from: Scheduled
246
+ to: Pending
247
+ event: DUE_DATE_REACHED
248
+ type: timeout
249
+ timeoutMs: 2592000000 # Configurable billing date
250
+
251
+ - from: Pending
252
+ to: Processing
253
+ event: CHARGE_INITIATED
254
+
255
+ - from: Processing
256
+ to: Paid
257
+ event: CHARGE_SUCCESS
258
+
259
+ - from: Processing
260
+ to: Failed
261
+ event: CHARGE_FAILED
262
+
263
+ - from: Failed
264
+ to: Processing
265
+ event: RETRY_CHARGE
266
+ guard:
267
+ expression: "context.attempts < 3"
268
+
269
+ - from: Failed
270
+ to: Voided
271
+ event: MAX_RETRIES_REACHED
272
+
273
+ - from: Scheduled
274
+ to: Voided
275
+ event: SUBSCRIPTION_CANCELLED
276
+
277
+ - from: Pending
278
+ to: Voided
279
+ event: SUBSCRIPTION_CANCELLED
@@ -0,0 +1,218 @@
1
+ # XComponent Pattern Demo
2
+ # Demonstrates the XComponent pattern with:
3
+ # - Entry point machine (OrderManager) that persists
4
+ # - Inter-machine transitions that create new instances
5
+ # - Auto-deallocation of completed instances (except entry point)
6
+ # - Component-level orchestration
7
+
8
+ name: OrderProcessingXComponent
9
+ version: 1.0.0
10
+ metadata:
11
+ description: XComponent pattern demo - orchestration of multiple state machines
12
+ domain: fintech
13
+
14
+ # Entry point - automatically created when component starts
15
+ entryMachine: OrderManager
16
+
17
+ # Optional layout configuration for dashboard visualization
18
+ layout:
19
+ algorithm: grid # auto-layout algorithm: grid, force, hierarchical
20
+ # machines: # manual positioning (overrides algorithm)
21
+ # OrderManager: { x: 100, y: 100 }
22
+ # OrderExecution: { x: 400, y: 100 }
23
+ # Settlement: { x: 700, y: 100 }
24
+
25
+ stateMachines:
26
+ # Entry Point: OrderManager
27
+ # This machine is created automatically and persists even in final state
28
+ # It orchestrates the creation of other machines via inter_machine transitions
29
+ - name: OrderManager
30
+ initialState: Ready
31
+ metadata:
32
+ description: Entry point - orchestrates order processing lifecycle
33
+
34
+ states:
35
+ - name: Ready
36
+ type: entry
37
+ metadata:
38
+ description: Ready to receive new orders
39
+
40
+ - name: OrderReceived
41
+ type: regular
42
+ metadata:
43
+ description: Order received, creating execution instance
44
+
45
+ - name: Processing
46
+ type: regular
47
+ metadata:
48
+ description: Order being processed
49
+
50
+ - name: Completed
51
+ type: final
52
+ metadata:
53
+ description: All orders completed (stays alive as entry point)
54
+
55
+ transitions:
56
+ # Receive new order - normal transition
57
+ - from: Ready
58
+ to: OrderReceived
59
+ event: NEW_ORDER
60
+ type: triggerable
61
+
62
+ # Create OrderExecution instance via inter_machine transition
63
+ - from: OrderReceived
64
+ to: Processing
65
+ event: START_EXECUTION
66
+ type: inter_machine
67
+ targetMachine: OrderExecution
68
+ metadata:
69
+ description: Creates new OrderExecution instance
70
+
71
+ # Back to ready for next order
72
+ - from: Processing
73
+ to: Ready
74
+ event: EXECUTION_COMPLETE
75
+ type: triggerable
76
+
77
+ # Shutdown entry point (but instance persists)
78
+ - from: Ready
79
+ to: Completed
80
+ event: SHUTDOWN
81
+ type: triggerable
82
+
83
+ # OrderExecution: Created dynamically by OrderManager
84
+ # Handles the execution of a single order
85
+ # Auto-deallocated when it reaches final state
86
+ - name: OrderExecution
87
+ initialState: Created
88
+ metadata:
89
+ description: Handles execution of a single order (auto-deallocated when complete)
90
+
91
+ contextSchema:
92
+ orderId:
93
+ type: text
94
+ required: true
95
+ symbol:
96
+ type: text
97
+ required: true
98
+ quantity:
99
+ type: number
100
+ required: true
101
+ executedQuantity:
102
+ type: number
103
+ default: 0
104
+
105
+ states:
106
+ - name: Created
107
+ type: entry
108
+ metadata:
109
+ description: Execution instance created
110
+
111
+ - name: Validating
112
+ type: regular
113
+ metadata:
114
+ description: Validating order parameters
115
+
116
+ - name: Executing
117
+ type: regular
118
+ metadata:
119
+ description: Executing on market
120
+
121
+ - name: Executed
122
+ type: regular
123
+ metadata:
124
+ description: Order executed, starting settlement
125
+
126
+ - name: Settled
127
+ type: final
128
+ metadata:
129
+ description: Order settled and complete (instance auto-deallocated)
130
+
131
+ - name: Failed
132
+ type: error
133
+ metadata:
134
+ description: Execution failed (instance auto-deallocated)
135
+
136
+ transitions:
137
+ - from: Created
138
+ to: Validating
139
+ event: VALIDATE
140
+ type: triggerable
141
+
142
+ - from: Validating
143
+ to: Executing
144
+ event: VALIDATION_OK
145
+ type: triggerable
146
+
147
+ - from: Validating
148
+ to: Failed
149
+ event: VALIDATION_FAILED
150
+ type: triggerable
151
+
152
+ - from: Executing
153
+ to: Executed
154
+ event: EXECUTION_OK
155
+ type: triggerable
156
+
157
+ - from: Executing
158
+ to: Failed
159
+ event: EXECUTION_FAILED
160
+ type: triggerable
161
+
162
+ # Create Settlement instance via inter_machine transition
163
+ - from: Executed
164
+ to: Settled
165
+ event: START_SETTLEMENT
166
+ type: inter_machine
167
+ targetMachine: Settlement
168
+ metadata:
169
+ description: Creates Settlement instance and completes execution
170
+
171
+ # Settlement: Created dynamically by OrderExecution
172
+ # Handles settlement process
173
+ # Auto-deallocated when complete
174
+ - name: Settlement
175
+ initialState: Pending
176
+ metadata:
177
+ description: Handles settlement (auto-deallocated when complete)
178
+
179
+ contextSchema:
180
+ orderId:
181
+ type: text
182
+ required: true
183
+ amount:
184
+ type: number
185
+ required: true
186
+
187
+ states:
188
+ - name: Pending
189
+ type: entry
190
+ metadata:
191
+ description: Settlement pending
192
+
193
+ - name: Confirmed
194
+ type: final
195
+ metadata:
196
+ description: Settlement confirmed (instance auto-deallocated)
197
+
198
+ - name: Failed
199
+ type: error
200
+ metadata:
201
+ description: Settlement failed (instance auto-deallocated)
202
+
203
+ transitions:
204
+ - from: Pending
205
+ to: Confirmed
206
+ event: SETTLEMENT_CONFIRMED
207
+ type: triggerable
208
+
209
+ - from: Pending
210
+ to: Failed
211
+ event: SETTLEMENT_FAILED
212
+ type: triggerable
213
+
214
+ - from: Pending
215
+ to: Failed
216
+ event: TIMEOUT
217
+ type: timeout
218
+ timeoutMs: 30000
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcomponent-ai",
3
- "version": "0.3.2",
3
+ "version": "0.4.2",
4
4
  "description": "LLM-first framework for AI agents (Claude, GPT) to build apps with sanctuarized business logic. Event-driven FSM runtime with multi-instance state machines, cross-component communication, event sourcing, and production-ready persistence (PostgreSQL, MongoDB)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "test:ci": "jest --coverage --ci --maxWorkers=2",
34
34
  "cli": "ts-node src/cli.ts",
35
35
  "api": "ts-node src/api.ts",
36
- "doc": "typedoc --out docs src",
36
+ "doc": "typedoc --out docs/api src",
37
37
  "lint": "eslint src/**/*.ts",
38
38
  "prepare": "npm run build",
39
39
  "prepublishOnly": "npm run clean && npm run build && npm test",