interaqt 0.7.4 → 0.8.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.
@@ -163,7 +163,37 @@ For **EACH entity** in `requirements/{module}.data-concepts.json`:
163
163
 
164
164
  Analyze `requirements/{module}.interactions-design.json` (using the module name from `.currentmodule`) to identify how entities are created:
165
165
 
166
- **Step A: Find Creation Interactions**
166
+ **Step A: Check if Entity is Integration Event (PRIORITY CHECK)**
167
+ ⚠️ **CRITICAL: This check MUST be performed FIRST, before analyzing interactions.**
168
+
169
+ 1. Check if entity's `entityType` in `requirements/{module}.data-concepts.json` is `"integration-event"`
170
+ 2. Check if entity's `note` or `description` in `requirements/{module}.data-concepts.json` contains keywords: "external event", "integration event", "webhook", "external system"
171
+ 3. If EITHER condition is true:
172
+ - **Type = "integration-event"**
173
+ - **creationInteractions = [] (empty array)**
174
+ - **computationMethod = "Created by external system integration/webhook/callback"**
175
+ - **STOP and skip Step B and Step C**
176
+ - Note: Even if this entity appears in interactions-design.json's creates array, ignore it - the creates entry is only for tracking data flow, not for actual creation logic
177
+
178
+ **Step B: Check if Entity is API Call Entity (PRIORITY CHECK)**
179
+ ⚠️ **CRITICAL: This check MUST be performed after Step A.**
180
+
181
+ 1. Check if entity's `entityType` in `requirements/{module}.data-concepts.json` is `"api-call"`
182
+ 2. If true, API Call entities require special handling as they need dual creation sources:
183
+ - **Type = "mutation-derived"**
184
+ - Set `isAPICallEntity: true` in the output
185
+ - Set `relatedBusinessEntity` to identify the primary business entity that triggers API calls
186
+ - **computationMethod**: Describe using Transform computation to auto-create when business entity is created AND support retry through explicit interactions
187
+ - **STOP and skip Step C and Step D**
188
+
189
+ **Rationale**: API Call entities track external API invocations. They must be:
190
+ - Auto-created when business data is created (via record mutation)
191
+ - Re-creatable through retry interactions when failures occur
192
+ Since both interactions and entity creation produce record mutations, mutation-derived handles both scenarios via Transform computations.
193
+
194
+ **Step C: Find Creation Interactions**
195
+ (Only perform this step if entity is NOT an integration event AND NOT an API call entity)
196
+
167
197
  1. Search all interactions where the entity appears in `interactions.specification.data.creates`
168
198
  2. For each creation interaction, capture:
169
199
  - Interaction name (not ID)
@@ -171,12 +201,22 @@ Analyze `requirements/{module}.interactions-design.json` (using the module name
171
201
  - Dependencies from the creates entry
172
202
  3. Store as `creationInteractions` with detailed information for each interaction
173
203
 
174
- **Step B: Determine Creation Type**
204
+ **Step D: Determine Creation Type**
205
+ (Only perform this step if entity is NOT an integration event AND NOT an API call entity)
206
+
207
+ **Priority Check: User Profile Entity Type**
208
+ 1. Check if entity has `entityType` field in `requirements/{module}.data-concepts.json`
209
+ 2. If `entityType === "user-profile"`:
210
+ - **Type = "derived"**
211
+ - **parent = "User"**
212
+ - **Reason**: User profile entities are automatically derived from the User entity upon User creation
213
+ - **STOP and skip remaining type analysis**
214
+
175
215
  Analyze the creation pattern:
176
216
 
177
217
  - **integration-event**: Entity is an event entity for external system integration
178
- - Identified in Step 1.3 from `requirements/{module}.integration.json`
179
- - Created when external system sends asynchronous responses (webhooks, callbacks)
218
+ - Should have been caught in Step A
219
+ - If you reach this point, review Step A logic
180
220
 
181
221
  - **interaction-created**: Entity is created independently by interactions
182
222
  - Entity appears alone in `data.creates`
@@ -190,15 +230,75 @@ Analyze the creation pattern:
190
230
  - **derived**: Entity is filtered/computed from other entities
191
231
  - No interactions directly create it
192
232
  - Views in `requirements/{module}.data-concepts.json` are typically derived
233
+ - **Special case**: User profile entities (`entityType: "user-profile"`) are derived from User entity (caught by Priority Check above)
193
234
 
194
235
  - **mutation-derived**: Entity is created from record mutation events
195
236
  - Not directly in any interaction's `data.creates`
196
237
  - Created by reactive computations (e.g., Transform) responding to other entities' creation/update/deletion
197
238
  - Check for descriptions mentioning "when X is created/updated/deleted, create Y"
198
239
  - Often used for audit logs, history tracking, or event-driven workflows
240
+ - **Dual-creation pattern**: Entities that need to be both auto-created with business data AND manually created through interactions
241
+ - Both scenarios produce record mutations, so Transform can handle both
242
+ - Example: API Call entities that auto-create when business entity is created, but also support retry interactions
243
+ - Set `relatedBusinessEntity` field to identify the triggering business entity
199
244
 
200
245
  **Example Analysis**:
201
246
  ```json
247
+ // Example 1: User Profile Entity (PRIORITY CHECK catches it)
248
+ // In requirements/user.data-concepts.json:
249
+ {
250
+ "name": "UserProfile",
251
+ "entityType": "user-profile",
252
+ "description": "Extended profile information for users",
253
+ "properties": {
254
+ "bio": {"type": "string"},
255
+ "avatar": {"type": "string"}
256
+ }
257
+ }
258
+ // Analysis using Step D Priority Check:
259
+ // - Entity has entityType field with value "user-profile" ✓
260
+ // - Result: Type = "derived", parent = "User"
261
+ // - STOP, skip remaining type analysis
262
+ // ⚠️ Note: User profile entities are automatically generated with User creation
263
+
264
+ // Example 2: Integration Event (PRIORITY CHECK catches it)
265
+ // In requirements/donate.data-concepts.json:
266
+ {
267
+ "name": "TTSGenerationEvent",
268
+ "note": "External event entity - created when TTS service returns response..."
269
+ }
270
+ // In requirements/donate.interactions-design.json (DonateToContent):
271
+ "creates": [
272
+ {
273
+ "target": "TTSGenerationEvent",
274
+ "description": "Create initial TTSGenerationEvent with status='pending'...",
275
+ "dependencies": ["DonationRecord"]
276
+ }
277
+ ]
278
+ // Analysis using Step A:
279
+ // - Step A check 2: entity note contains "External event entity" ✓
280
+ // - Result: Type = "integration-event", creationInteractions = []
281
+ // - STOP, skip Step B, C and D
282
+ // ⚠️ Note: Ignore the creates entry in interactions - it's only for tracking data flow
283
+
284
+ // Example 3: API Call Entity (mutation-derived with dual creation)
285
+ // In requirements/donate.data-concepts.json:
286
+ {
287
+ "name": "TTSAPICall",
288
+ "entityType": "api-call",
289
+ "description": "Records TTS API call execution for tracking"
290
+ }
291
+ // Analysis using Step B:
292
+ // - Step A: No integration event indicators ✗
293
+ // - Step B: entityType is "api-call" ✓
294
+ // - Result: Type = "mutation-derived"
295
+ // Set isAPICallEntity: true
296
+ // Set relatedBusinessEntity: "DonationRecord"
297
+ // computationMethod: "Transform: Auto-create when DonationRecord is created. Also supports retry via RetryTTSCall interaction. Both paths produce mutations handled by same Transform."
298
+ // - STOP, skip Step C and D
299
+ // ⚠️ Note: Dual creation pattern - auto-created with business entity AND manually via retry interaction
300
+
301
+ // Example 4: Interaction-created
202
302
  // In interaction "CreateDormitory":
203
303
  "data": {
204
304
  "creates": [
@@ -214,15 +314,23 @@ Analyze the creation pattern:
214
314
  }
215
315
  ]
216
316
  }
217
- // Result:
218
- // Dormitory is interaction-created with creation details
219
- // Bed is created-with-parent (parent: Dormitory) with creation details
317
+ // Analysis:
318
+ // - Step A: No integration event indicators ✗
319
+ // - Step B: No api-call entityType
320
+ // - Step D Priority Check: No user-profile entityType ✗
321
+ // - Step C: Find creates entries
322
+ // - Step D: Dormitory is interaction-created, Bed is created-with-parent (parent: Dormitory)
220
323
 
221
- // For mutation-derived entity (not in any interaction's creates):
324
+ // Example 5: Mutation-derived
222
325
  // In requirements/{module}.data-concepts.json: "UserActivityLog: Records all user actions"
223
326
  // In interactions: No interaction directly creates UserActivityLog
224
327
  // In descriptions: "Activity logs are automatically created when users perform actions"
225
- // Result: UserActivityLog is mutation-derived
328
+ // Analysis:
329
+ // - Step A: No integration event indicators ✗
330
+ // - Step B: No api-call entityType ✗
331
+ // - Step D Priority Check: No user-profile entityType ✗
332
+ // - Step C: Not in any creates array
333
+ // - Step D: Result = mutation-derived
226
334
  ```
227
335
 
228
336
  #### 2.2 Determine Deletion Pattern
@@ -272,10 +380,31 @@ Transform the computation description using semantic best practices:
272
380
 
273
381
  #### 3.4 Determine Control Type
274
382
 
275
- Based on the analysis:
276
- - **creation-only**: Only set when entity is created (no updates found)
277
- - **derived-with-parent**: Property of a derived entity
278
- - **independent**: Has separate update logic (found in `data.updates`)
383
+ Follow this decision process:
384
+
385
+ 1. **Check if property has `computation.method: "integration-result"` in `requirements/{module}.data-concepts.json`**
386
+ - If YES **integration-result**
387
+ - Used for properties computed from external API/integration results
388
+ - These properties react to API call entity updates
389
+
390
+ 2. **Check if parent entity's `lifecycle.creation.type` is `"derived"`**
391
+ - If YES → **derived-with-parent**
392
+ - Property belongs to a derived entity (e.g., UserProfile)
393
+
394
+ 3. **Check if property appears in any interaction's `data.updates`**
395
+ - If YES → **independent**
396
+ - Property has explicit update interactions
397
+
398
+ 4. **Check if property is computed**
399
+ - If NO (not computed) → **creation-only**
400
+ - If YES (computed) → **derived-with-parent**
401
+ - Covers reactive computed properties (Count, Summation, etc.)
402
+
403
+ **Control Type Definitions**:
404
+ - **creation-only**: Set once at entity creation, never changes
405
+ - **integration-result**: Computed from external API/integration results, reacts to API call entity changes
406
+ - **derived-with-parent**: Property of a derived entity, or reactive computed property
407
+ - **independent**: Has explicit update interactions separate from creation
279
408
 
280
409
  ### Step 4: Analyze Relations
281
410
 
@@ -523,6 +652,7 @@ Transform the analyzed data into the standard output format:
523
652
  "entities": {
524
653
  "[EntityName]": {
525
654
  "purpose": "[From requirements/{module}.data-concepts.json description]",
655
+ "isAPICallEntity": "[true if entityType is 'api-call', omit otherwise]",
526
656
  "isIntegrationEvent": "[true if this is an integration event entity, false otherwise]",
527
657
  "dataDependencies": "[Dependencies identified in Step 2]",
528
658
  "computationMethod": "[Creation pattern description]",
@@ -530,6 +660,7 @@ Transform the analyzed data into the standard output format:
530
660
  "creation": {
531
661
  "type": "[integration-event | interaction-created | derived | created-with-parent | mutation-derived]",
532
662
  "parent": "[Parent entity name if created-with-parent]",
663
+ "relatedBusinessEntity": "[For API Call entities with mutation-derived type: the business entity that triggers API calls]",
533
664
  "creationInteractions": [
534
665
  {
535
666
  "name": "[Interaction name]",
@@ -676,7 +807,62 @@ Properties affected by multiple sources:
676
807
  }
677
808
  ```
678
809
 
679
- ### 4. Derived Entities
810
+ ### 4. Integration Result Properties
811
+ Properties computed from external API/integration results:
812
+ ```json
813
+ "voiceUrl": {
814
+ "type": "string",
815
+ "purpose": "AI-generated audio URL from TTS service",
816
+ "controlType": "integration-result",
817
+ "dataDependencies": ["TTSAPICall.responseData", "TTSAPICall.status"],
818
+ "interactionDependencies": [],
819
+ "computationMethod": "Statemachine: Extract from latest TTSAPICall.responseData where status='completed'",
820
+ "initialValue": "null"
821
+ }
822
+ ```
823
+
824
+ Note: Use `controlType: "integration-result"` when:
825
+ - Property value comes from external API/service responses
826
+ - Property is computed from API Call entity's response data
827
+ - Always specified in `requirements/{module}.data-concepts.json` with `computation.method: "integration-result"`
828
+
829
+ ### 5. Derived Entities
830
+
831
+ #### 5.1 User Profile Entity (Special Case)
832
+ User profile entities with `entityType: "user-profile"`:
833
+ ```json
834
+ "UserProfile": {
835
+ "purpose": "Extended profile information for users",
836
+ "isIntegrationEvent": false,
837
+ "dataDependencies": ["User"],
838
+ "computationMethod": "Automatically created with User entity creation",
839
+ "lifecycle": {
840
+ "creation": {
841
+ "type": "derived",
842
+ "parent": "User",
843
+ "creationInteractions": []
844
+ },
845
+ "deletion": {
846
+ "canBeDeleted": true,
847
+ "deletionType": "auto-delete",
848
+ "deletionInteractions": []
849
+ }
850
+ },
851
+ "properties": {
852
+ "bio": {
853
+ "type": "string",
854
+ "purpose": "User biography",
855
+ "controlType": "independent",
856
+ "dataDependencies": [],
857
+ "interactionDependencies": ["UpdateProfile"],
858
+ "computationMethod": "Set by user through UpdateProfile interaction",
859
+ "initialValue": "''"
860
+ }
861
+ }
862
+ }
863
+ ```
864
+
865
+ #### 5.2 Filtered/Computed Entities
680
866
  Entities filtered from base entities:
681
867
  ```json
682
868
  "ActiveUser": {
@@ -691,7 +877,7 @@ Entities filtered from base entities:
691
877
  }
692
878
  ```
693
879
 
694
- ### 5. Multiple Creation Interactions
880
+ ### 6. Multiple Creation Interactions
695
881
  Entity created by different interactions with different logic:
696
882
  ```json
697
883
  "Style": {
@@ -716,7 +902,7 @@ Entity created by different interactions with different logic:
716
902
  }
717
903
  ```
718
904
 
719
- ### 6. Integration Event Entity
905
+ ### 7. Integration Event Entity
720
906
  Event entity for tracking asynchronous external system responses:
721
907
  ```json
722
908
  "PaymentEvent": {
@@ -776,10 +962,18 @@ Note: Other business entities (like `Order.paymentStatus`, `User.premiumUntil`)
776
962
  - [ ] All entities from `requirements/{module}.data-concepts.json` are analyzed
777
963
  - [ ] All relations from `requirements/{module}.data-concepts.json` are analyzed
778
964
  - [ ] All dictionaries from `requirements/{module}.data-concepts.json` are analyzed
779
- - [ ] Integration event entities identified from `requirements/{module}.integration.json`
965
+ - [ ] **🔴 CRITICAL: For EACH entity, performed Step A (Integration Event Priority Check) FIRST**
966
+ - [ ] **🔴 CRITICAL: For EACH entity, performed Step B (API Call Entity Priority Check) after Step A**
967
+ - [ ] **🔴 CRITICAL: For EACH entity, performed Step D Priority Check (User Profile Entity Type) after Step A and B**
968
+ - [ ] API Call entities (with `entityType: "api-call"`) have `isAPICallEntity: true` flag set
969
+ - [ ] User profile entities (with `entityType: "user-profile"`) have lifecycle.creation.type set to "derived"
970
+ - [ ] User profile entities have lifecycle.creation.parent set to "User"
971
+ - [ ] Integration event entities identified from `requirements/{module}.integration.json` OR entity notes/descriptions
780
972
  - [ ] Event entities properly marked with `isIntegrationEvent: true`
781
973
  - [ ] Event entities have lifecycle.creation.type set to "integration-event"
974
+ - [ ] Event entities have lifecycle.creation.creationInteractions set to [] (empty array)
782
975
  - [ ] Event entities have deletion.canBeDeleted set to false
976
+ - [ ] **🔴 CRITICAL: Integration event entities do NOT have computationMethod from interactions** (should be "Created by external system...")
783
977
  - [ ] Creation patterns identified for each entity/relation
784
978
  - [ ] **🔴 CRITICAL: For EACH relation, executed the 5-step algorithm in Step 4.2 to determine lifecycle type**
785
979
  - [ ] **🔴 CRITICAL: For relations with type "created-with-entity", verified parent field is set correctly**
@@ -0,0 +1,19 @@
1
+ 我们的项目所使用的框架是一个叫做 Interaqt 的后端响应式数据框架,它会自动根据应用中的数据变化及响应式数据的定义执行相应的数据变化。它只负责处理一般的业务逻辑中表达的数据逻辑,例如一般业务逻辑中会用到 平均/综合 等计算,还有常见的基于状态机等业务逻辑表达等。对于一些非一般的能力需求,例如 大模型生图、大模型生视频、tts、发送邮件、发送信息、完整支付系统等。它需要借助外部系统/api 来完成。
2
+ 我们设计了一个叫做 integration 的概念,专门用来对接当前系统和外部的api/系统。它通过 interaqt 框架提供的数据观察机制,来观察数据变化,根据数据变化来决定如何调用外部的 api。同时通过 webhook 等机制来接受外部的事件,将外部事件同步回系统中,触发响应式的业务逻辑。
3
+
4
+ 我们将 integration 需要集成的功能分成了三种类别:
5
+ 1. 调用外部的 api,为了获得一个具体的返回。例如 tts,大模型生图等。
6
+ 2. 执行某种副作用,例如发送邮件、发送 im 消息等。
7
+ 3. 对接其他有状态的系统,例如支付系统等。
8
+
9
+ 现在我们需要指导 claude code 的 sub agent 合理地识别需要的外部服务以及如何自己实现 integration。
10
+ 1. 指导 `.claude/agents/requirements-analysis-handler.md` 在需求分析阶段,正确分析出 integration 的类型。并在相应的输出的文档中,设计一个字段来表达 integration 的类型。
11
+ 2. 指导 `.claude/agents/implement-design-handler.md` 在设计数据的时候,根据如下原则进行设计:
12
+ 2.1. 不管是哪种类型,都会涉及到对外部 api 的调用,例如执行副作用,也会有副作用 api 的调用。所以我们应该对每一个 api 的调用都设计一个 `{xxx}APICall` 的 entity,它负责记录这次 api 调用的参数、状态、返回值、调用时间等。
13
+ 2.2. 同时设计一个相应的 integraion event entity,当我们通过 webhook 或者自己通过接口查询到 api 调用状态的变化时,在系统内创建相应的 api call result event 事件。并且将上一步创建的 `{xxx}APICall` entity 的 status 和 data 字段写成基于 integration event entity 的 computation,这样就完整符合了框架的响应式范式。也记录了所有应该记录的数据,增强了系统的健壮性。
14
+ 2.3. 如果当前场景是希望基于这个 integration 获得具体的返回值,那么意味着我们系统内的业务数据对这个 `{xxx}APICall` 的 entity 是有依赖的,应该写成基于 `{xxx}APICall` 的 computation。例如我们的有一个 `Greeting` entity,其中有个 `voiceUrl` property 是需要利用外部 tts 能力将文本转化为语音。那么 `Greeting.voiceUrl` 就应该表达为基于 `{ttsAPICall}` entity 的 computation。如果是纯副作用类型等的调用,就不需要了。注意,这种情况下,还需要建立相应的 entity 和 api call entity 之间的关系,才能查找到正确的数据。
15
+ 2.4. `.claude/agents/implement-design-handler.md` 在做 data-design 的时候,应该明确表达出来:1. 设计的哪些实体是 api call 类型的 entity,哪些实体是 api call result event 实体。2. 系统内的业务数据如果需要 api 的返回结果,那么应该依赖正确的 api call entity。
16
+ 3. 指导 `.claude/agents/code-generation-handler.md` 在实现阶段,在写测试用例时,完全可以通过创建正确的 api call result event 来模拟 api 的调用,完整验证系统的内部逻辑的正确性。不需要等到 integration 的真实实现。
17
+ 4. 指导 `.claude/agents/error-check-handler.md` 在合适的阶段对 integration 相关的设计做错误检查。
18
+
19
+ 你充分理解上面的所有思路,并且修改相应的 sub agent 文件来达成目标。