@contractspec/example.learning-journey-ambient-coach 1.44.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.
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+
3
+ import { moneyAmbientCoachTrack } from './track';
4
+
5
+ interface TestEvent {
6
+ name: string;
7
+ payload?: Record<string, unknown>;
8
+ }
9
+
10
+ const matchesFilter = (
11
+ filter: Record<string, unknown> | undefined,
12
+ payload: Record<string, unknown> | undefined
13
+ ) => {
14
+ if (!filter) return true;
15
+ if (!payload) return false;
16
+ return Object.entries(filter).every(([key, value]) => payload[key] === value);
17
+ };
18
+
19
+ describe('ambient coach track', () => {
20
+ it('completes steps when tips are acted upon', () => {
21
+ const tipIds = [
22
+ 'cash_buffer_too_high',
23
+ 'no_savings_goal',
24
+ 'irregular_savings',
25
+ ];
26
+
27
+ const events: TestEvent[] = tipIds.flatMap((tipId) => [
28
+ { name: 'coach.tip.triggered', payload: { tipId } },
29
+ { name: 'coach.tip.follow_up_action_taken', payload: { tipId } },
30
+ ]);
31
+
32
+ const progress = moneyAmbientCoachTrack.steps.map((step) => ({
33
+ id: step.id,
34
+ status: 'PENDING' as 'PENDING' | 'COMPLETED',
35
+ }));
36
+
37
+ events.forEach((event) => {
38
+ moneyAmbientCoachTrack.steps.forEach((stepSpec, index) => {
39
+ const step = progress[index];
40
+ if (!step || step.status === 'COMPLETED') return;
41
+ if (stepSpec.completion.kind !== 'event') return;
42
+ if (stepSpec.completion.eventName !== event.name) return;
43
+ if (
44
+ !matchesFilter(
45
+ stepSpec.completion.payloadFilter,
46
+ event.payload as Record<string, unknown> | undefined
47
+ )
48
+ ) {
49
+ return;
50
+ }
51
+ step.status = 'COMPLETED';
52
+ });
53
+ });
54
+
55
+ expect(progress.every((s) => s.status === 'COMPLETED')).toBeTrue();
56
+ });
57
+ });
package/src/track.ts ADDED
@@ -0,0 +1,74 @@
1
+ import type { LearningJourneyTrackSpec } from '@contractspec/module.learning-journey/track-spec';
2
+
3
+ const makeTipStep = (
4
+ id: string,
5
+ tipId: string,
6
+ description: string
7
+ ): LearningJourneyTrackSpec['steps'][number] => ({
8
+ id,
9
+ title: `Resolve tip: ${tipId}`,
10
+ description,
11
+ completion: {
12
+ kind: 'event',
13
+ eventName: 'coach.tip.follow_up_action_taken',
14
+ payloadFilter: { tipId },
15
+ },
16
+ xpReward: 20,
17
+ metadata: { tipId },
18
+ });
19
+
20
+ export const moneyAmbientCoachTrack: LearningJourneyTrackSpec = {
21
+ id: 'money_ambient_coach',
22
+ name: 'Ambient Coach — Money',
23
+ description:
24
+ 'Subtle coaching for money patterns (cash buffer, goals, saving rhythm).',
25
+ targetUserSegment: 'money_user',
26
+ totalXp: 60,
27
+ steps: [
28
+ makeTipStep(
29
+ 'cash_buffer_too_high',
30
+ 'cash_buffer_too_high',
31
+ 'Suggest sweeping excess cash into goals.'
32
+ ),
33
+ makeTipStep(
34
+ 'no_savings_goal',
35
+ 'no_savings_goal',
36
+ 'Prompt setting a first savings goal.'
37
+ ),
38
+ makeTipStep(
39
+ 'irregular_savings',
40
+ 'irregular_savings',
41
+ 'Recommend recurring saves after irregular deposits.'
42
+ ),
43
+ ],
44
+ };
45
+
46
+ export const colivingAmbientCoachTrack: LearningJourneyTrackSpec = {
47
+ id: 'coliving_ambient_coach',
48
+ name: 'Ambient Coach — Coliving',
49
+ description: 'Contextual tips for healthy coliving habits.',
50
+ targetUserSegment: 'coliving',
51
+ totalXp: 60,
52
+ steps: [
53
+ makeTipStep(
54
+ 'noise_late_evening',
55
+ 'noise_late_evening',
56
+ 'Suggest updating quiet hours to reduce evening noise.'
57
+ ),
58
+ makeTipStep(
59
+ 'guest_frequency_high',
60
+ 'guest_frequency_high',
61
+ 'Set guest frequency expectations for the house.'
62
+ ),
63
+ makeTipStep(
64
+ 'shared_space_conflicts',
65
+ 'shared_space_conflicts',
66
+ 'Offer a shared-space checklist to reduce conflicts.'
67
+ ),
68
+ ],
69
+ };
70
+
71
+ export const ambientCoachTracks: LearningJourneyTrackSpec[] = [
72
+ moneyAmbientCoachTrack,
73
+ colivingAmbientCoachTrack,
74
+ ];
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@contractspec/tool.typescript/react-library.json",
3
+ "include": ["src"],
4
+ "exclude": ["node_modules"],
5
+ "compilerOptions": {
6
+ "rootDir": "src",
7
+ "outDir": "dist"
8
+ }
9
+ }