@crewx/sdk 0.9.0-rc.3 → 0.9.0-rc.31

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 (56) hide show
  1. package/dist/config/canonicalize-agent-options.d.ts +16 -0
  2. package/dist/config/models.generated.d.ts +22 -0
  3. package/dist/config/models.remote.d.ts +4 -0
  4. package/dist/config/overdrive.d.ts +24 -0
  5. package/dist/config/pricing.d.ts +8 -8
  6. package/dist/config/pricing.generated.d.ts +2 -0
  7. package/dist/config/pricing.remote.d.ts +4 -0
  8. package/dist/config/pricing.types.d.ts +5 -0
  9. package/dist/config/timeout.config.d.ts +3 -0
  10. package/dist/esm/index.js +123 -81
  11. package/dist/esm/plugins/index.js +119 -72
  12. package/dist/esm/repository/index.js +107 -60
  13. package/dist/esm/testing/index.js +1 -1
  14. package/dist/facade/Crewx.d.ts +5 -0
  15. package/dist/index.browser.d.ts +1 -1
  16. package/dist/index.browser.js +2 -2
  17. package/dist/index.d.ts +11 -4
  18. package/dist/index.js +124 -82
  19. package/dist/migrations/0008_careful_black_bird.sql +17 -0
  20. package/dist/migrations/0009_hot_dark_phoenix.sql +1 -0
  21. package/dist/migrations/0010_analyze_stats.sql +6 -0
  22. package/dist/migrations/0011_far_black_tarantula.sql +1 -0
  23. package/dist/migrations/0012_blue_turbo.sql +23 -0
  24. package/dist/migrations/meta/0008_snapshot.json +1327 -0
  25. package/dist/migrations/meta/0009_snapshot.json +1335 -0
  26. package/dist/migrations/meta/0010_snapshot.json +1335 -0
  27. package/dist/migrations/meta/0011_snapshot.json +1342 -0
  28. package/dist/migrations/meta/0012_snapshot.json +1494 -0
  29. package/dist/migrations/meta/_journal.json +35 -0
  30. package/dist/plugins/index.js +119 -72
  31. package/dist/provider/acp/adapters/claude.d.ts +0 -4
  32. package/dist/provider/acp/connection.d.ts +4 -0
  33. package/dist/provider/acp/meta.d.ts +4 -0
  34. package/dist/provider/bridge.d.ts +13 -1
  35. package/dist/provider/cli/adapter.types.d.ts +1 -0
  36. package/dist/provider/cli/adapters/claude.d.ts +0 -1
  37. package/dist/provider/cli/adapters/cli-knob.util.d.ts +2 -0
  38. package/dist/provider/cli/meta.d.ts +10 -2
  39. package/dist/provider/idle-watchdog.d.ts +19 -0
  40. package/dist/provider/models.d.ts +23 -0
  41. package/dist/provider/order.d.ts +1 -0
  42. package/dist/repository/index.d.ts +5 -1
  43. package/dist/repository/index.js +107 -60
  44. package/dist/repository/notification.repository.d.ts +58 -0
  45. package/dist/repository/task.repository.d.ts +34 -0
  46. package/dist/repository/thread.repository.d.ts +16 -2
  47. package/dist/repository/usage-report.repository.d.ts +27 -0
  48. package/dist/schema/index.d.ts +2 -0
  49. package/dist/schema/notifications.d.ts +303 -0
  50. package/dist/schema/usage-reports.d.ts +252 -0
  51. package/dist/testing/index.d.ts +2 -0
  52. package/dist/testing/index.js +1 -1
  53. package/dist/types/index.d.ts +7 -0
  54. package/dist/utils/id.d.ts +1 -1
  55. package/package.json +3 -2
  56. package/templates/agents/default.yaml +34 -0
@@ -0,0 +1,58 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { notifications, notification_reads } from '../schema/index.js';
3
+ export declare const DEFAULT_NOTIFICATION_CAP = 500;
4
+ export type NotificationRow = typeof notifications.$inferSelect;
5
+ export type NewNotification = typeof notifications.$inferInsert;
6
+ export type NotificationReadRow = typeof notification_reads.$inferSelect;
7
+ export type NotificationLevel = 'info' | 'warning' | 'critical';
8
+ export type NotificationSource = 'agent' | 'system';
9
+ export interface CreateNotificationInput {
10
+ workspaceId: string;
11
+ agentId?: string | null;
12
+ taskId?: string | null;
13
+ threadId?: string | null;
14
+ source?: NotificationSource;
15
+ level?: NotificationLevel;
16
+ title: string;
17
+ body?: string | null;
18
+ targetUserId?: string | null;
19
+ metadata?: string | null;
20
+ }
21
+ export interface NotificationListItem extends NotificationRow {
22
+ read: boolean;
23
+ read_at: string | null;
24
+ }
25
+ export interface ListNotificationsParams {
26
+ workspaceId: string;
27
+ userId: string;
28
+ limit?: number;
29
+ }
30
+ export interface UserScope {
31
+ workspaceId: string;
32
+ userId: string;
33
+ }
34
+ export interface MarkReadParams {
35
+ notificationId: string;
36
+ workspaceId: string;
37
+ userId: string;
38
+ }
39
+ export declare const DEFAULT_LIST_LIMIT = 50;
40
+ export declare class NotificationRepository extends BaseSqliteRepository {
41
+ private readonly dbPath?;
42
+ private readonly cap;
43
+ constructor(opts?: {
44
+ dbPath?: string;
45
+ dbRoot?: string;
46
+ cap?: number;
47
+ });
48
+ resolveDbPath(): string;
49
+ private openHandle;
50
+ create(input: CreateNotificationInput): {
51
+ id: string;
52
+ };
53
+ private enforceCap;
54
+ list(params: ListNotificationsParams): NotificationListItem[];
55
+ unreadCount(params: UserScope): number;
56
+ markRead(params: MarkReadParams): boolean;
57
+ markAllRead(params: UserScope): number;
58
+ }
@@ -2,6 +2,12 @@ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
2
  import { tasks } from '../schema/index.js';
3
3
  export type TaskRow = typeof tasks.$inferSelect;
4
4
  export type NewTask = typeof tasks.$inferInsert;
5
+ export type TaskListRow = Pick<TaskRow, 'id' | 'thread_id' | 'agent_id' | 'status' | 'parent_task_id' | 'started_at' | 'completed_at' | 'duration_ms' | 'input_tokens' | 'output_tokens' | 'cost_usd' | 'error'>;
6
+ export interface WorkflowCardRow {
7
+ taskId: string;
8
+ workflowRunId?: string;
9
+ raw?: string;
10
+ }
5
11
  export interface AgentUsageRow {
6
12
  agentId: string;
7
13
  workspaceId: string | null;
@@ -32,8 +38,30 @@ export interface ProviderUsageRow {
32
38
  activeDurationMs: number;
33
39
  lastActiveAt: string | null;
34
40
  }
41
+ export interface ModelUsageRow {
42
+ model: string;
43
+ provider: string;
44
+ totalTasks: number;
45
+ inputTokens: number;
46
+ outputTokens: number;
47
+ cachedInputTokens: number;
48
+ costUsd: number;
49
+ totalTokens: number;
50
+ activeDurationMs: number;
51
+ lastActiveAt: string | null;
52
+ }
53
+ export interface ReportTaskRow {
54
+ threadId: string | null;
55
+ agentId: string;
56
+ startedAt: string;
57
+ status: string;
58
+ error: string | null;
59
+ exitCode: number | null;
60
+ }
61
+ export declare const PID_NULL_REAP_GRACE_MS: number;
35
62
  export declare class TaskRepository extends BaseSqliteRepository {
36
63
  private readonly dbPath?;
64
+ private readonly pidNullObservedSince;
37
65
  constructor(opts?: {
38
66
  dbPath?: string;
39
67
  dbRoot?: string;
@@ -89,6 +117,7 @@ export declare class TaskRepository extends BaseSqliteRepository {
89
117
  pid?: number;
90
118
  };
91
119
  reapOrphanedTasks(): number;
120
+ reapRunningWorkflowTasks(graceMs?: number): number;
92
121
  findTaskStatus(taskId: string, workspaceId?: string): TaskRow | undefined;
93
122
  findChildTasks(parentTaskId: string, workspaceId?: string): TaskRow[];
94
123
  getWorkspaceUsageSummary(workspaceId?: string): Array<{
@@ -104,6 +133,9 @@ export declare class TaskRepository extends BaseSqliteRepository {
104
133
  costUsd: number;
105
134
  };
106
135
  findTasksByThread(threadId: string, workspaceId?: string): TaskRow[];
136
+ private parseWorkflowCardMetadata;
137
+ private extractThreadIdFromCommand;
138
+ batchFetchWorkflowCards(threadIds: string[], workspaceId?: string): Map<string, WorkflowCardRow>;
107
139
  findAllTasks(params: {
108
140
  workspaceId?: string;
109
141
  agentId?: string;
@@ -127,4 +159,6 @@ export declare class TaskRepository extends BaseSqliteRepository {
127
159
  markTaskFailed(taskId: string, error: string, workspaceId?: string): void;
128
160
  findTasksByPromptHint(hint: string, workspaceId?: string): TaskRow[];
129
161
  getProviderUsage(from: string, to: string, workspace?: string): ProviderUsageRow[];
162
+ getModelUsage(from: string, to: string, workspace?: string): ModelUsageRow[];
163
+ getTasksForReport(from: string, to: string, workspace?: string): ReportTaskRow[];
130
164
  }
@@ -1,6 +1,6 @@
1
1
  import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
2
  import { threads } from '../schema/index.js';
3
- import type { TaskRow } from './task.repository.js';
3
+ import type { TaskRow, TaskListRow } from './task.repository.js';
4
4
  export type ThreadRow = typeof threads.$inferSelect;
5
5
  export type NewThread = typeof threads.$inferInsert;
6
6
  export declare class ThreadRepository extends BaseSqliteRepository {
@@ -14,6 +14,7 @@ export declare class ThreadRepository extends BaseSqliteRepository {
14
14
  private validateWorkspaceId;
15
15
  private topLevelTaskPredicateSql;
16
16
  findAllThreads(workspaceId?: string): ThreadRow[];
17
+ findThreadsByIdsOrTitles(ids: string[], workspaceId?: string): ThreadRow[];
17
18
  findThreadById(threadId: string, workspaceId?: string): ThreadRow | undefined;
18
19
  threadExists(threadId: string, workspaceId?: string): boolean;
19
20
  aggregateTaskStats(threadId: string, workspaceId?: string): {
@@ -30,7 +31,9 @@ export declare class ThreadRepository extends BaseSqliteRepository {
30
31
  task: TaskRow;
31
32
  children: TaskRow[];
32
33
  } | undefined;
33
- batchFetchTasks(threadIds: string[], workspaceId?: string): Map<string, TaskRow[]>;
34
+ private batchFetchTasksQuery;
35
+ batchFetchTasks(threadIds: string[], workspaceId?: string): Map<string, TaskListRow[]>;
36
+ explainBatchFetchTasksPlan(threadIds: string[], workspaceId?: string): string[];
34
37
  updateThreadTitle(threadId: string, title: string, workspaceId?: string): void;
35
38
  upsertThread(threadId: string, opts: {
36
39
  platform: string;
@@ -63,4 +66,15 @@ export declare class ThreadRepository extends BaseSqliteRepository {
63
66
  toggleStar(threadId: string, workspaceId?: string): {
64
67
  starred: boolean;
65
68
  } | null;
69
+ resolveOverdriveForRequest(threadId: string, workspaceId: string | undefined, action: 'enable-count' | 'enable-latch' | 'disable' | 'use-current', opts?: {
70
+ turns?: number;
71
+ defaultTurns?: number;
72
+ updatedBy?: string;
73
+ consumeCurrent?: boolean;
74
+ }): {
75
+ applied: boolean;
76
+ appliedMode?: 'count' | 'latch';
77
+ state: 'off' | 'count' | 'latch';
78
+ remaining: number;
79
+ } | null;
66
80
  }
@@ -0,0 +1,27 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { usage_reports } from '../schema/index.js';
3
+ export type UsageReportRow = typeof usage_reports.$inferSelect;
4
+ export type NewUsageReport = typeof usage_reports.$inferInsert;
5
+ export interface PublishReportInput {
6
+ id: string;
7
+ workspaceId: string;
8
+ month: string;
9
+ generatedAt: string;
10
+ sourceRange: string;
11
+ tier: string;
12
+ totalTokens: number;
13
+ totalCostUsd: number;
14
+ payload: string;
15
+ }
16
+ export declare class UsageReportRepository extends BaseSqliteRepository {
17
+ private readonly dbPath?;
18
+ constructor(opts?: {
19
+ dbPath?: string;
20
+ dbRoot?: string;
21
+ });
22
+ resolveDbPath(): string;
23
+ private openHandle;
24
+ publish(input: PublishReportInput): UsageReportRow;
25
+ findByMonth(workspaceId: string, month: string): UsageReportRow | undefined;
26
+ listByWorkspace(workspaceId: string): UsageReportRow[];
27
+ }
@@ -6,3 +6,5 @@ export * from './tool-calls.js';
6
6
  export * from './thread-boxes.js';
7
7
  export * from './request-logs.js';
8
8
  export * from './usage-limit-snapshots.js';
9
+ export * from './usage-reports.js';
10
+ export * from './notifications.js';
@@ -0,0 +1,303 @@
1
+ export declare const notifications: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "notifications";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: "id";
7
+ tableName: "notifications";
8
+ dataType: "string";
9
+ columnType: "SQLiteText";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: false;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}, {
22
+ length: number | undefined;
23
+ }>;
24
+ workspace_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
25
+ name: "workspace_id";
26
+ tableName: "notifications";
27
+ dataType: "string";
28
+ columnType: "SQLiteText";
29
+ data: string;
30
+ driverParam: string;
31
+ notNull: true;
32
+ hasDefault: false;
33
+ isPrimaryKey: false;
34
+ isAutoincrement: false;
35
+ hasRuntimeDefault: false;
36
+ enumValues: [string, ...string[]];
37
+ baseColumn: never;
38
+ identity: undefined;
39
+ generated: undefined;
40
+ }, {}, {
41
+ length: number | undefined;
42
+ }>;
43
+ agent_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
44
+ name: "agent_id";
45
+ tableName: "notifications";
46
+ dataType: "string";
47
+ columnType: "SQLiteText";
48
+ data: string;
49
+ driverParam: string;
50
+ notNull: false;
51
+ hasDefault: false;
52
+ isPrimaryKey: false;
53
+ isAutoincrement: false;
54
+ hasRuntimeDefault: false;
55
+ enumValues: [string, ...string[]];
56
+ baseColumn: never;
57
+ identity: undefined;
58
+ generated: undefined;
59
+ }, {}, {
60
+ length: number | undefined;
61
+ }>;
62
+ task_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
63
+ name: "task_id";
64
+ tableName: "notifications";
65
+ dataType: "string";
66
+ columnType: "SQLiteText";
67
+ data: string;
68
+ driverParam: string;
69
+ notNull: false;
70
+ hasDefault: false;
71
+ isPrimaryKey: false;
72
+ isAutoincrement: false;
73
+ hasRuntimeDefault: false;
74
+ enumValues: [string, ...string[]];
75
+ baseColumn: never;
76
+ identity: undefined;
77
+ generated: undefined;
78
+ }, {}, {
79
+ length: number | undefined;
80
+ }>;
81
+ thread_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
82
+ name: "thread_id";
83
+ tableName: "notifications";
84
+ dataType: "string";
85
+ columnType: "SQLiteText";
86
+ data: string;
87
+ driverParam: string;
88
+ notNull: false;
89
+ hasDefault: false;
90
+ isPrimaryKey: false;
91
+ isAutoincrement: false;
92
+ hasRuntimeDefault: false;
93
+ enumValues: [string, ...string[]];
94
+ baseColumn: never;
95
+ identity: undefined;
96
+ generated: undefined;
97
+ }, {}, {
98
+ length: number | undefined;
99
+ }>;
100
+ source: import("drizzle-orm/sqlite-core").SQLiteColumn<{
101
+ name: "source";
102
+ tableName: "notifications";
103
+ dataType: "string";
104
+ columnType: "SQLiteText";
105
+ data: string;
106
+ driverParam: string;
107
+ notNull: true;
108
+ hasDefault: true;
109
+ isPrimaryKey: false;
110
+ isAutoincrement: false;
111
+ hasRuntimeDefault: false;
112
+ enumValues: [string, ...string[]];
113
+ baseColumn: never;
114
+ identity: undefined;
115
+ generated: undefined;
116
+ }, {}, {
117
+ length: number | undefined;
118
+ }>;
119
+ level: import("drizzle-orm/sqlite-core").SQLiteColumn<{
120
+ name: "level";
121
+ tableName: "notifications";
122
+ dataType: "string";
123
+ columnType: "SQLiteText";
124
+ data: string;
125
+ driverParam: string;
126
+ notNull: true;
127
+ hasDefault: true;
128
+ isPrimaryKey: false;
129
+ isAutoincrement: false;
130
+ hasRuntimeDefault: false;
131
+ enumValues: [string, ...string[]];
132
+ baseColumn: never;
133
+ identity: undefined;
134
+ generated: undefined;
135
+ }, {}, {
136
+ length: number | undefined;
137
+ }>;
138
+ title: import("drizzle-orm/sqlite-core").SQLiteColumn<{
139
+ name: "title";
140
+ tableName: "notifications";
141
+ dataType: "string";
142
+ columnType: "SQLiteText";
143
+ data: string;
144
+ driverParam: string;
145
+ notNull: true;
146
+ hasDefault: false;
147
+ isPrimaryKey: false;
148
+ isAutoincrement: false;
149
+ hasRuntimeDefault: false;
150
+ enumValues: [string, ...string[]];
151
+ baseColumn: never;
152
+ identity: undefined;
153
+ generated: undefined;
154
+ }, {}, {
155
+ length: number | undefined;
156
+ }>;
157
+ body: import("drizzle-orm/sqlite-core").SQLiteColumn<{
158
+ name: "body";
159
+ tableName: "notifications";
160
+ dataType: "string";
161
+ columnType: "SQLiteText";
162
+ data: string;
163
+ driverParam: string;
164
+ notNull: false;
165
+ hasDefault: false;
166
+ isPrimaryKey: false;
167
+ isAutoincrement: false;
168
+ hasRuntimeDefault: false;
169
+ enumValues: [string, ...string[]];
170
+ baseColumn: never;
171
+ identity: undefined;
172
+ generated: undefined;
173
+ }, {}, {
174
+ length: number | undefined;
175
+ }>;
176
+ target_user_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
177
+ name: "target_user_id";
178
+ tableName: "notifications";
179
+ dataType: "string";
180
+ columnType: "SQLiteText";
181
+ data: string;
182
+ driverParam: string;
183
+ notNull: false;
184
+ hasDefault: false;
185
+ isPrimaryKey: false;
186
+ isAutoincrement: false;
187
+ hasRuntimeDefault: false;
188
+ enumValues: [string, ...string[]];
189
+ baseColumn: never;
190
+ identity: undefined;
191
+ generated: undefined;
192
+ }, {}, {
193
+ length: number | undefined;
194
+ }>;
195
+ created_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
196
+ name: "created_at";
197
+ tableName: "notifications";
198
+ dataType: "string";
199
+ columnType: "SQLiteText";
200
+ data: string;
201
+ driverParam: string;
202
+ notNull: true;
203
+ hasDefault: false;
204
+ isPrimaryKey: false;
205
+ isAutoincrement: false;
206
+ hasRuntimeDefault: false;
207
+ enumValues: [string, ...string[]];
208
+ baseColumn: never;
209
+ identity: undefined;
210
+ generated: undefined;
211
+ }, {}, {
212
+ length: number | undefined;
213
+ }>;
214
+ metadata: import("drizzle-orm/sqlite-core").SQLiteColumn<{
215
+ name: "metadata";
216
+ tableName: "notifications";
217
+ dataType: "string";
218
+ columnType: "SQLiteText";
219
+ data: string;
220
+ driverParam: string;
221
+ notNull: false;
222
+ hasDefault: false;
223
+ isPrimaryKey: false;
224
+ isAutoincrement: false;
225
+ hasRuntimeDefault: false;
226
+ enumValues: [string, ...string[]];
227
+ baseColumn: never;
228
+ identity: undefined;
229
+ generated: undefined;
230
+ }, {}, {
231
+ length: number | undefined;
232
+ }>;
233
+ };
234
+ dialect: "sqlite";
235
+ }>;
236
+ export declare const notification_reads: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
237
+ name: "notification_reads";
238
+ schema: undefined;
239
+ columns: {
240
+ notification_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
241
+ name: "notification_id";
242
+ tableName: "notification_reads";
243
+ dataType: "string";
244
+ columnType: "SQLiteText";
245
+ data: string;
246
+ driverParam: string;
247
+ notNull: true;
248
+ hasDefault: false;
249
+ isPrimaryKey: false;
250
+ isAutoincrement: false;
251
+ hasRuntimeDefault: false;
252
+ enumValues: [string, ...string[]];
253
+ baseColumn: never;
254
+ identity: undefined;
255
+ generated: undefined;
256
+ }, {}, {
257
+ length: number | undefined;
258
+ }>;
259
+ user_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
260
+ name: "user_id";
261
+ tableName: "notification_reads";
262
+ dataType: "string";
263
+ columnType: "SQLiteText";
264
+ data: string;
265
+ driverParam: string;
266
+ notNull: true;
267
+ hasDefault: false;
268
+ isPrimaryKey: false;
269
+ isAutoincrement: false;
270
+ hasRuntimeDefault: false;
271
+ enumValues: [string, ...string[]];
272
+ baseColumn: never;
273
+ identity: undefined;
274
+ generated: undefined;
275
+ }, {}, {
276
+ length: number | undefined;
277
+ }>;
278
+ read_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
279
+ name: "read_at";
280
+ tableName: "notification_reads";
281
+ dataType: "string";
282
+ columnType: "SQLiteText";
283
+ data: string;
284
+ driverParam: string;
285
+ notNull: true;
286
+ hasDefault: false;
287
+ isPrimaryKey: false;
288
+ isAutoincrement: false;
289
+ hasRuntimeDefault: false;
290
+ enumValues: [string, ...string[]];
291
+ baseColumn: never;
292
+ identity: undefined;
293
+ generated: undefined;
294
+ }, {}, {
295
+ length: number | undefined;
296
+ }>;
297
+ };
298
+ dialect: "sqlite";
299
+ }>;
300
+ export type Notification = typeof notifications.$inferSelect;
301
+ export type NewNotification = typeof notifications.$inferInsert;
302
+ export type NotificationRead = typeof notification_reads.$inferSelect;
303
+ export type NewNotificationRead = typeof notification_reads.$inferInsert;