@tuturuuu/ai 0.0.10

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.
Files changed (130) hide show
  1. package/README.md +76 -0
  2. package/package.json +106 -0
  3. package/src/api-key-hash.ts +28 -0
  4. package/src/calendar/events.ts +34 -0
  5. package/src/calendar/route.ts +114 -0
  6. package/src/chat/credit-source.ts +1 -0
  7. package/src/chat/google/chat-request-schema.ts +150 -0
  8. package/src/chat/google/default-system-instruction.ts +198 -0
  9. package/src/chat/google/message-file-processing.ts +212 -0
  10. package/src/chat/google/mira-step-preparation.ts +221 -0
  11. package/src/chat/google/new/route.ts +368 -0
  12. package/src/chat/google/route-auth.ts +81 -0
  13. package/src/chat/google/route-chat-resolution.ts +98 -0
  14. package/src/chat/google/route-credits.ts +61 -0
  15. package/src/chat/google/route-message-preparation.ts +331 -0
  16. package/src/chat/google/route-mira-runtime.ts +206 -0
  17. package/src/chat/google/route.ts +632 -0
  18. package/src/chat/google/stream-finish-persistence.ts +722 -0
  19. package/src/chat/google/summary/route.ts +153 -0
  20. package/src/chat/mira-render-ui-policy.ts +540 -0
  21. package/src/chat/mira-system-instruction.ts +484 -0
  22. package/src/chat-sdk/adapters.ts +389 -0
  23. package/src/chat-sdk/registry.ts +197 -0
  24. package/src/chat-sdk.ts +33 -0
  25. package/src/core.ts +3 -0
  26. package/src/credits/cap-output-tokens.ts +90 -0
  27. package/src/credits/check-credits.ts +232 -0
  28. package/src/credits/constants.ts +30 -0
  29. package/src/credits/index.ts +46 -0
  30. package/src/credits/model-mapping.ts +92 -0
  31. package/src/credits/reservations.ts +514 -0
  32. package/src/credits/resolve-plan-model.ts +219 -0
  33. package/src/credits/sync-gateway-models.ts +351 -0
  34. package/src/credits/types.ts +109 -0
  35. package/src/credits/use-ai-credits.ts +3 -0
  36. package/src/embeddings/metered.ts +283 -0
  37. package/src/executions/route.ts +137 -0
  38. package/src/generate/route.ts +411 -0
  39. package/src/hooks.ts +7 -0
  40. package/src/meetings/summary/route.ts +7 -0
  41. package/src/meetings/transcription/route.ts +134 -0
  42. package/src/memory/client.ts +158 -0
  43. package/src/memory/config.ts +38 -0
  44. package/src/memory/index.ts +32 -0
  45. package/src/memory/ingest.ts +51 -0
  46. package/src/memory/middleware.ts +35 -0
  47. package/src/memory/operations.ts +480 -0
  48. package/src/memory/scope.ts +102 -0
  49. package/src/memory/settings.ts +121 -0
  50. package/src/memory/types.ts +101 -0
  51. package/src/memory/workspace.ts +36 -0
  52. package/src/memory.ts +1 -0
  53. package/src/mind/patch.ts +146 -0
  54. package/src/mind/route.ts +687 -0
  55. package/src/mind/tools.ts +1500 -0
  56. package/src/mind/types.ts +20 -0
  57. package/src/object/core.ts +3 -0
  58. package/src/object/flashcards/route.ts +140 -0
  59. package/src/object/quizzes/explanation/route.ts +145 -0
  60. package/src/object/quizzes/route.ts +142 -0
  61. package/src/object/types.ts +187 -0
  62. package/src/object/year-plan/route.ts +196 -0
  63. package/src/react.ts +1 -0
  64. package/src/scheduling/algorithm.ts +791 -0
  65. package/src/scheduling/default.ts +36 -0
  66. package/src/scheduling/duration-optimizer.ts +689 -0
  67. package/src/scheduling/index.ts +79 -0
  68. package/src/scheduling/priority-calculator.ts +187 -0
  69. package/src/scheduling/recurrence-calculator.ts +621 -0
  70. package/src/scheduling/templates.ts +892 -0
  71. package/src/scheduling/types.ts +136 -0
  72. package/src/scheduling/web-adapter.ts +308 -0
  73. package/src/scheduling.ts +6 -0
  74. package/src/supported-actions.ts +1 -0
  75. package/src/supported-providers.ts +6 -0
  76. package/src/tools/context-builder.ts +372 -0
  77. package/src/tools/core.ts +1 -0
  78. package/src/tools/definitions/calendar.ts +106 -0
  79. package/src/tools/definitions/finance.ts +197 -0
  80. package/src/tools/definitions/image.ts +74 -0
  81. package/src/tools/definitions/memory.ts +83 -0
  82. package/src/tools/definitions/meta.ts +154 -0
  83. package/src/tools/definitions/render-ui.ts +81 -0
  84. package/src/tools/definitions/tasks.ts +343 -0
  85. package/src/tools/definitions/time-tracking.ts +381 -0
  86. package/src/tools/definitions/workspace-context.ts +45 -0
  87. package/src/tools/definitions/workspace-user-chat.ts +111 -0
  88. package/src/tools/executors/calendar.ts +371 -0
  89. package/src/tools/executors/chat.ts +15 -0
  90. package/src/tools/executors/finance.ts +638 -0
  91. package/src/tools/executors/helpers/encryption.ts +107 -0
  92. package/src/tools/executors/image.ts +247 -0
  93. package/src/tools/executors/markitdown.ts +684 -0
  94. package/src/tools/executors/memory.ts +277 -0
  95. package/src/tools/executors/parallel-checks.ts +176 -0
  96. package/src/tools/executors/qr.ts +170 -0
  97. package/src/tools/executors/scope-helpers.ts +192 -0
  98. package/src/tools/executors/search.ts +149 -0
  99. package/src/tools/executors/settings.ts +40 -0
  100. package/src/tools/executors/tasks.ts +1087 -0
  101. package/src/tools/executors/theme.ts +23 -0
  102. package/src/tools/executors/timer/timer-categories-executor.ts +110 -0
  103. package/src/tools/executors/timer/timer-category-mutations.ts +240 -0
  104. package/src/tools/executors/timer/timer-goal-mutations.ts +323 -0
  105. package/src/tools/executors/timer/timer-goals-executor.ts +272 -0
  106. package/src/tools/executors/timer/timer-helpers.ts +372 -0
  107. package/src/tools/executors/timer/timer-mutation-schemas.ts +160 -0
  108. package/src/tools/executors/timer/timer-mutation-types.ts +212 -0
  109. package/src/tools/executors/timer/timer-mutations.ts +19 -0
  110. package/src/tools/executors/timer/timer-queries.ts +18 -0
  111. package/src/tools/executors/timer/timer-session-lifecycle.ts +299 -0
  112. package/src/tools/executors/timer/timer-session-mutations.ts +10 -0
  113. package/src/tools/executors/timer/timer-session-queries.ts +153 -0
  114. package/src/tools/executors/timer/timer-session-updates.ts +200 -0
  115. package/src/tools/executors/timer/timer-sessions-executor.ts +91 -0
  116. package/src/tools/executors/timer/timer-stats-executor.ts +157 -0
  117. package/src/tools/executors/timer.ts +22 -0
  118. package/src/tools/executors/user.ts +60 -0
  119. package/src/tools/executors/workspace.ts +135 -0
  120. package/src/tools/json-render-catalog.ts +875 -0
  121. package/src/tools/mira-tool-definitions.ts +55 -0
  122. package/src/tools/mira-tool-dispatcher.ts +265 -0
  123. package/src/tools/mira-tool-metadata.ts +164 -0
  124. package/src/tools/mira-tool-names.ts +95 -0
  125. package/src/tools/mira-tool-render-ui.ts +54 -0
  126. package/src/tools/mira-tool-types.ts +17 -0
  127. package/src/tools/mira-tools.ts +167 -0
  128. package/src/tools/normalize-render-ui-input.ts +321 -0
  129. package/src/tools/workspace-context.ts +233 -0
  130. package/src/types.ts +38 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Task Scheduling Module
3
+ *
4
+ * This module provides task scheduling algorithms that:
5
+ * - Prioritize tasks by deadline (earlier deadlines get earlier slots)
6
+ * - Respect min/max split durations
7
+ * - Handle existing calendar events (locked events)
8
+ * - Support work, personal, and meeting hour types
9
+ */
10
+
11
+ export {
12
+ prepareTaskChunks,
13
+ promoteEventToTask,
14
+ scheduleTasks,
15
+ scheduleWithFlexibleEvents,
16
+ } from './algorithm';
17
+ export { defaultActiveHours, defaultTasks } from './default';
18
+ export type {
19
+ HabitDurationConfig,
20
+ SlotCharacteristics,
21
+ TaskSlotConfig,
22
+ TimeSlotInfo,
23
+ } from './duration-optimizer';
24
+ export {
25
+ calculateIdealStartTimeForHabit,
26
+ calculateIdealStartTimeForTask,
27
+ calculateOptimalDuration,
28
+ findBestSlotForHabit,
29
+ findBestSlotForTask,
30
+ getEffectiveDurationBounds,
31
+ getSlotCharacteristics,
32
+ roundToNext15Minutes,
33
+ scoreSlotForHabit,
34
+ scoreSlotForTask,
35
+ slotMatchesPreference,
36
+ timeMatchesSlot,
37
+ } from './duration-optimizer';
38
+ export type { PrioritizableItem } from './priority-calculator';
39
+ export {
40
+ calculatePriorityScore,
41
+ canBump,
42
+ comparePriority,
43
+ getEffectivePriority,
44
+ isHigherPriority,
45
+ isUrgent,
46
+ PRIORITY_WEIGHTS,
47
+ sortByPriority,
48
+ } from './priority-calculator';
49
+ export {
50
+ calculateOccurrences,
51
+ getNextOccurrence,
52
+ getNextOccurrenceDescription,
53
+ getOccurrencesInRange,
54
+ isOccurrenceDate,
55
+ } from './recurrence-calculator';
56
+ export { templateScenarios } from './templates';
57
+ export type {
58
+ ActiveHours,
59
+ CalendarHoursType,
60
+ DateRange,
61
+ Event,
62
+ Log,
63
+ ScheduleResult,
64
+ SchedulingWeights,
65
+ Task,
66
+ TemplateScenario,
67
+ WebCalendarEvent,
68
+ WebScheduleResult,
69
+ WebTaskInput,
70
+ } from './types';
71
+ export {
72
+ convertHourSettingsToActiveHours,
73
+ convertWebEventsToLocked,
74
+ convertWebTasksToSchedulerTasks,
75
+ convertWebTaskToSchedulerTask,
76
+ mapCalendarHoursToCategory,
77
+ scheduleWebTask,
78
+ scheduleWebTasks,
79
+ } from './web-adapter';
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Priority Calculator for Unified Scheduling
3
+ *
4
+ * This module provides centralized priority logic for scheduling habits and tasks.
5
+ * It handles:
6
+ * - Explicit priority comparison
7
+ * - Priority inference from deadlines when not set
8
+ * - Consistent priority weights across the system
9
+ */
10
+
11
+ import type { TaskPriority } from '@tuturuuu/types/primitives/Priority';
12
+
13
+ /**
14
+ * Priority weights for comparison (higher = more important)
15
+ */
16
+ export const PRIORITY_WEIGHTS: Record<TaskPriority, number> = {
17
+ critical: 4,
18
+ high: 3,
19
+ normal: 2,
20
+ low: 1,
21
+ } as const;
22
+
23
+ /**
24
+ * Interface for items that can have priority calculated
25
+ */
26
+ export interface PrioritizableItem {
27
+ priority?: TaskPriority | null;
28
+ end_date?: string | null; // deadline
29
+ }
30
+
31
+ /**
32
+ * Get the effective priority for an item
33
+ * If priority is explicitly set, use it.
34
+ * Otherwise, infer from deadline proximity:
35
+ * - < 24 hours: urgent (mapped to critical)
36
+ * - < 48 hours: high
37
+ * - Has deadline: normal
38
+ * - No deadline: low
39
+ */
40
+ export function getEffectivePriority(item: PrioritizableItem): TaskPriority {
41
+ // If priority is explicitly set, use it
42
+ if (item.priority) {
43
+ return item.priority;
44
+ }
45
+
46
+ // No deadline means low priority
47
+ if (!item.end_date) {
48
+ return 'low';
49
+ }
50
+
51
+ // Calculate hours until deadline
52
+ const deadline = new Date(item.end_date);
53
+ const now = new Date();
54
+ const hoursUntilDeadline =
55
+ (deadline.getTime() - now.getTime()) / (1000 * 60 * 60);
56
+
57
+ // Infer priority from deadline proximity
58
+ if (hoursUntilDeadline <= 0) {
59
+ // Overdue - treat as critical
60
+ return 'critical';
61
+ }
62
+ if (hoursUntilDeadline <= 24) {
63
+ return 'critical';
64
+ }
65
+ if (hoursUntilDeadline <= 48) {
66
+ return 'high';
67
+ }
68
+
69
+ // Has deadline but not urgent
70
+ return 'normal';
71
+ }
72
+
73
+ /**
74
+ * Compare two priorities for sorting
75
+ * Returns negative if a should come first (higher priority)
76
+ * Returns positive if b should come first (higher priority)
77
+ * Returns 0 if equal
78
+ */
79
+ export function comparePriority(a: TaskPriority, b: TaskPriority): number {
80
+ return PRIORITY_WEIGHTS[b] - PRIORITY_WEIGHTS[a];
81
+ }
82
+
83
+ /**
84
+ * Check if priority A is higher than priority B
85
+ */
86
+ export function isHigherPriority(a: TaskPriority, b: TaskPriority): boolean {
87
+ return PRIORITY_WEIGHTS[a] > PRIORITY_WEIGHTS[b];
88
+ }
89
+
90
+ /**
91
+ * Check if an item is urgent (critical priority, either explicit or inferred)
92
+ */
93
+ export function isUrgent(item: PrioritizableItem): boolean {
94
+ return getEffectivePriority(item) === 'critical';
95
+ }
96
+
97
+ /**
98
+ * Check if an item can bump another based on priority
99
+ * Bumping is only allowed when:
100
+ * - The bumper has higher effective priority than the target
101
+ * - The bumper is urgent (critical priority)
102
+ */
103
+ export function canBump(
104
+ bumper: PrioritizableItem,
105
+ target: PrioritizableItem
106
+ ): boolean {
107
+ const bumperPriority = getEffectivePriority(bumper);
108
+ const targetPriority = getEffectivePriority(target);
109
+
110
+ // Only urgent items can bump
111
+ if (bumperPriority !== 'critical') {
112
+ return false;
113
+ }
114
+
115
+ // Can bump if target has lower priority
116
+ return isHigherPriority(bumperPriority, targetPriority);
117
+ }
118
+
119
+ /**
120
+ * Sort items by effective priority (highest first)
121
+ * Secondary sort by deadline (earliest first) if priorities are equal
122
+ * Tertiary sort by created_at (oldest first) if available
123
+ */
124
+ export function sortByPriority<
125
+ T extends PrioritizableItem & { created_at?: string },
126
+ >(items: T[]): T[] {
127
+ return [...items].sort((a, b) => {
128
+ // Primary: Priority (highest first)
129
+ const priorityDiff = comparePriority(
130
+ getEffectivePriority(a),
131
+ getEffectivePriority(b)
132
+ );
133
+ if (priorityDiff !== 0) return priorityDiff;
134
+
135
+ // Secondary: Deadline (earliest first, nulls last)
136
+ if (a.end_date && b.end_date) {
137
+ const deadlineDiff =
138
+ new Date(a.end_date).getTime() - new Date(b.end_date).getTime();
139
+ if (deadlineDiff !== 0) return deadlineDiff;
140
+ } else if (a.end_date) {
141
+ return -1; // a has deadline, b doesn't
142
+ } else if (b.end_date) {
143
+ return 1; // b has deadline, a doesn't
144
+ }
145
+
146
+ // Tertiary: Created date (oldest first)
147
+ if (a.created_at && b.created_at) {
148
+ return (
149
+ new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
150
+ );
151
+ }
152
+
153
+ return 0;
154
+ });
155
+ }
156
+
157
+ /**
158
+ * Calculate a numeric priority score for advanced sorting
159
+ * Higher score = higher priority
160
+ */
161
+ export function calculatePriorityScore(item: PrioritizableItem): number {
162
+ const priority = getEffectivePriority(item);
163
+ let score = PRIORITY_WEIGHTS[priority] * 1000;
164
+
165
+ // Add urgency bonus based on deadline proximity
166
+ if (item.end_date) {
167
+ const deadline = new Date(item.end_date);
168
+ const now = new Date();
169
+ const hoursUntilDeadline =
170
+ (deadline.getTime() - now.getTime()) / (1000 * 60 * 60);
171
+
172
+ if (hoursUntilDeadline < 0) {
173
+ // Overdue - maximum urgency
174
+ score += 5000;
175
+ } else if (hoursUntilDeadline < 24) {
176
+ score += 2000;
177
+ } else if (hoursUntilDeadline < 48) {
178
+ score += 1000;
179
+ } else if (hoursUntilDeadline < 72) {
180
+ score += 500;
181
+ } else if (hoursUntilDeadline < 168) {
182
+ score += 200;
183
+ }
184
+ }
185
+
186
+ return score;
187
+ }