@crewx/sdk 0.8.2 → 0.8.3-rc.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.
Files changed (33) hide show
  1. package/dist/conversation/index.d.ts +0 -1
  2. package/dist/conversation/sqlite-provider.d.ts +2 -3
  3. package/dist/esm/index.js +48 -56
  4. package/dist/esm/plugins/index.js +109 -51
  5. package/dist/esm/repository/index.js +103 -0
  6. package/dist/index.js +48 -56
  7. package/dist/migrations/0000_init.sql +156 -0
  8. package/dist/migrations/meta/0000_snapshot.json +1091 -0
  9. package/dist/migrations/meta/_journal.json +13 -0
  10. package/dist/plugins/index.js +109 -51
  11. package/dist/plugins/sqlite-tracing.d.ts +0 -1
  12. package/dist/repository/base-sqlite-repository.d.ts +6 -0
  13. package/dist/repository/db.d.ts +9 -0
  14. package/dist/repository/errors.d.ts +6 -0
  15. package/dist/repository/index.d.ts +21 -0
  16. package/dist/repository/index.js +103 -0
  17. package/dist/repository/migrate.d.ts +3 -0
  18. package/dist/repository/request-log.repository.d.ts +31 -0
  19. package/dist/repository/span.repository.d.ts +16 -0
  20. package/dist/repository/task.repository.d.ts +115 -0
  21. package/dist/repository/thread-box.repository.d.ts +20 -0
  22. package/dist/repository/thread.repository.d.ts +56 -0
  23. package/dist/repository/tool-call.repository.d.ts +19 -0
  24. package/dist/repository/workspace.repository.d.ts +64 -0
  25. package/dist/schema/index.d.ts +7 -0
  26. package/dist/schema/request-logs.d.ts +309 -0
  27. package/dist/schema/spans.d.ts +254 -0
  28. package/dist/schema/tasks.d.ts +660 -0
  29. package/dist/schema/thread-boxes.d.ts +210 -0
  30. package/dist/schema/threads.d.ts +214 -0
  31. package/dist/schema/tool-calls.d.ts +178 -0
  32. package/dist/schema/workspaces.d.ts +159 -0
  33. package/package.json +14 -3
@@ -0,0 +1,115 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { tasks } from '../schema/index.js';
3
+ export type TaskRow = typeof tasks.$inferSelect;
4
+ export type NewTask = typeof tasks.$inferInsert;
5
+ export interface AgentUsageRow {
6
+ agentId: string;
7
+ totalTasks: number;
8
+ inputTokens: number;
9
+ outputTokens: number;
10
+ cachedInputTokens: number;
11
+ costUsd: number;
12
+ }
13
+ export interface TrendRow {
14
+ date: string;
15
+ agentId: string;
16
+ inputTokens: number;
17
+ outputTokens: number;
18
+ cachedInputTokens: number;
19
+ costUsd: number;
20
+ }
21
+ export declare class TaskRepository extends BaseSqliteRepository {
22
+ private readonly dbPath?;
23
+ constructor(opts?: {
24
+ dbPath?: string;
25
+ dbRoot?: string;
26
+ });
27
+ resolveDbPath(): string;
28
+ private openHandle;
29
+ startTask(opts: {
30
+ id: string;
31
+ agentId: string;
32
+ prompt: string;
33
+ mode: string;
34
+ status: string;
35
+ startedAt: string;
36
+ pid?: number | null;
37
+ parentTaskId?: string | null;
38
+ callerAgentId?: string | null;
39
+ traceId?: string | null;
40
+ command?: string | null;
41
+ metadata?: string | null;
42
+ workspaceId?: string | null;
43
+ workspaceName?: string | null;
44
+ platform?: string | null;
45
+ crewxVersion?: string | null;
46
+ threadId?: string | null;
47
+ model?: string | null;
48
+ renderedPrompt?: string | null;
49
+ codingAgentCommand?: string | null;
50
+ }): void;
51
+ finishTask(opts: {
52
+ id: string;
53
+ status: string;
54
+ result?: string | null;
55
+ error?: string | null;
56
+ completedAt: string;
57
+ durationMs?: number | null;
58
+ exitCode?: number | null;
59
+ inputTokens?: number;
60
+ outputTokens?: number;
61
+ cachedInputTokens?: number;
62
+ costUsd?: number;
63
+ model?: string | null;
64
+ }): void;
65
+ appendLog(taskId: string, entry: {
66
+ timestamp: string;
67
+ level: string;
68
+ message: string;
69
+ }): void;
70
+ getRunningTasks(): TaskRow[];
71
+ getAllTasks(): TaskRow[];
72
+ getTask(id: string): TaskRow | undefined;
73
+ killTask(id: string): {
74
+ killed: boolean;
75
+ pid?: number;
76
+ };
77
+ findTaskStatus(taskId: string, workspaceId?: string): TaskRow | undefined;
78
+ findChildTasks(parentTaskId: string, workspaceId?: string): TaskRow[];
79
+ getWorkspaceUsageSummary(workspaceId?: string): Array<{
80
+ workspace_id: string;
81
+ workspace_name: string;
82
+ input_tokens: number;
83
+ output_tokens: number;
84
+ cost_usd: number;
85
+ task_count: number;
86
+ }>;
87
+ getThreadTokenUsage(threadId: string, workspaceId?: string): {
88
+ inputTokens: number;
89
+ outputTokens: number;
90
+ costUsd: number;
91
+ };
92
+ findTasksByThread(threadId: string, workspaceId?: string): TaskRow[];
93
+ findAllTasks(params: {
94
+ workspaceId?: string;
95
+ agentId?: string;
96
+ agents?: string[];
97
+ status?: string;
98
+ statuses?: string[];
99
+ search?: string;
100
+ q?: string;
101
+ limit: number;
102
+ offset: number;
103
+ sortDir?: 'ASC' | 'DESC';
104
+ from?: string;
105
+ to?: string;
106
+ }): {
107
+ rows: TaskRow[];
108
+ total: number;
109
+ };
110
+ getAgentUsage(from: string, to: string, workspace?: string): AgentUsageRow[];
111
+ getAgentUsageTrendRaw(from: string, to: string, workspace?: string): TrendRow[];
112
+ findTaskForStop(taskId: string, workspaceId: string): TaskRow | undefined;
113
+ markTaskFailed(taskId: string, error: string, workspaceId?: string): void;
114
+ findTasksByPromptHint(hint: string, workspaceId?: string): TaskRow[];
115
+ }
@@ -0,0 +1,20 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { thread_boxes } from '../schema/index.js';
3
+ export type ThreadBoxRow = typeof thread_boxes.$inferSelect;
4
+ export type NewThreadBox = typeof thread_boxes.$inferInsert;
5
+ export declare class ThreadBoxRepository extends BaseSqliteRepository {
6
+ private readonly dbPath?;
7
+ constructor(opts?: {
8
+ dbPath?: string;
9
+ dbRoot?: string;
10
+ });
11
+ resolveDbPath(): string;
12
+ private openHandle;
13
+ private ensureThreadExists;
14
+ findByThreadId(threadId: string): ThreadBoxRow[];
15
+ findById(threadId: string, boxId: string): ThreadBoxRow | undefined;
16
+ insert(data: Omit<NewThreadBox, 'id'> & {
17
+ id: string;
18
+ threadId: string;
19
+ }): ThreadBoxRow;
20
+ }
@@ -0,0 +1,56 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { threads } from '../schema/index.js';
3
+ import type { TaskRow } from './task.repository.js';
4
+ export type ThreadRow = typeof threads.$inferSelect;
5
+ export type NewThread = typeof threads.$inferInsert;
6
+ export declare class ThreadRepository extends BaseSqliteRepository {
7
+ private readonly dbPath?;
8
+ constructor(opts?: {
9
+ dbPath?: string;
10
+ dbRoot?: string;
11
+ });
12
+ resolveDbPath(): string;
13
+ private openHandle;
14
+ private validateWorkspaceId;
15
+ findAllThreads(workspaceId?: string): ThreadRow[];
16
+ findThreadById(threadId: string, workspaceId?: string): ThreadRow | undefined;
17
+ threadExists(threadId: string, workspaceId?: string): boolean;
18
+ aggregateTaskStats(threadId: string, workspaceId?: string): {
19
+ taskCount: number;
20
+ inputTokens: number;
21
+ outputTokens: number;
22
+ cachedInputTokens: number;
23
+ costUsd: number;
24
+ agentIds: string[];
25
+ };
26
+ findTopLevelTasks(threadId: string, workspaceId?: string): TaskRow[];
27
+ findAllTasks(threadId: string, workspaceId?: string): TaskRow[];
28
+ findTaskById(threadId: string, taskId: string, workspaceId?: string): {
29
+ task: TaskRow;
30
+ children: TaskRow[];
31
+ } | undefined;
32
+ batchFetchTasks(threadIds: string[], workspaceId?: string): Map<string, TaskRow[]>;
33
+ updateThreadTitle(threadId: string, title: string, workspaceId?: string): void;
34
+ upsertThread(threadId: string, opts: {
35
+ platform: string;
36
+ workspaceId?: string;
37
+ title?: string;
38
+ titleLocked?: boolean;
39
+ }): void;
40
+ ensureThread(threadId: string, platform: string, workspaceId?: string): void;
41
+ saveUserMessage(threadId: string, text: string, opts?: {
42
+ platform?: string;
43
+ model?: string;
44
+ }): void;
45
+ saveAssistantMessage(threadId: string, text: string, opts?: {
46
+ platform?: string;
47
+ model?: string;
48
+ inputTokens?: number;
49
+ outputTokens?: number;
50
+ cachedInputTokens?: number;
51
+ }): void;
52
+ updateThread(threadId: string, patch: {
53
+ title?: string;
54
+ titleLocked?: boolean;
55
+ }): void;
56
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { tool_calls } from '../schema/index.js';
3
+ export type ToolCallRow = typeof tool_calls.$inferSelect;
4
+ export type NewToolCall = typeof tool_calls.$inferInsert;
5
+ export declare class ToolCallRepository extends BaseSqliteRepository {
6
+ private readonly dbPath?;
7
+ constructor(opts?: {
8
+ dbPath?: string;
9
+ dbRoot?: string;
10
+ });
11
+ resolveDbPath(): string;
12
+ private openHandle;
13
+ insertToolCall(opts: NewToolCall): void;
14
+ findByTaskId(taskId: string): ToolCallRow[];
15
+ aggregateByName(taskId: string): {
16
+ toolName: string;
17
+ count: number;
18
+ }[];
19
+ }
@@ -0,0 +1,64 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import type { DrizzleDb } from './db.js';
3
+ import type { Workspace } from '../schema/index.js';
4
+ export type ProjectRow = Workspace;
5
+ export interface ThreadRow {
6
+ id: string;
7
+ workspace_id: string | null;
8
+ platform: string;
9
+ title: string | null;
10
+ first_message: string | null;
11
+ last_message: string | null;
12
+ message_count: number;
13
+ created_at: string;
14
+ updated_at: string;
15
+ metadata: string | null;
16
+ }
17
+ export interface ThreadWithAgentRow extends ThreadRow {
18
+ agent_id: string | null;
19
+ }
20
+ export declare class WorkspaceRepository extends BaseSqliteRepository {
21
+ private readonly dbRoot?;
22
+ constructor(opts?: {
23
+ dbRoot?: string;
24
+ });
25
+ resolveDbPath(): string;
26
+ private openHandle;
27
+ resolveSlug(db: DrizzleDb, workspaceId: string, workspacePath: string): string;
28
+ ensureRow(db: DrizzleDb, opts: {
29
+ id: string;
30
+ slug: string;
31
+ name: string;
32
+ workspacePath: string;
33
+ }): void;
34
+ registerWorkspace(workspacePath: string): {
35
+ id: string;
36
+ slug: string;
37
+ };
38
+ listProjects(params: {
39
+ isActive?: boolean;
40
+ limit: number;
41
+ offset: number;
42
+ }): {
43
+ rows: ProjectRow[];
44
+ total: number;
45
+ };
46
+ findById(id: string): ProjectRow | undefined;
47
+ findAgentsByProject(id: string): string[];
48
+ findThreadsByProject(id: string, params: {
49
+ limit: number;
50
+ offset: number;
51
+ }): {
52
+ rows: ThreadWithAgentRow[];
53
+ total: number;
54
+ };
55
+ findBySlug(slug: string): ProjectRow | undefined;
56
+ slugExists(slug: string, excludeId?: string): boolean;
57
+ insert(id: string, slug: string, name: string, repoPath: string | null): ProjectRow;
58
+ update(id: string, updates: string[], args: (string | number | null)[]): ProjectRow;
59
+ cleanupOrphanWorkspaces(): {
60
+ softDeleted: number;
61
+ checked: number;
62
+ };
63
+ delete(id: string): void;
64
+ }
@@ -0,0 +1,7 @@
1
+ export * from './workspaces.js';
2
+ export * from './tasks.js';
3
+ export * from './threads.js';
4
+ export * from './spans.js';
5
+ export * from './tool-calls.js';
6
+ export * from './thread-boxes.js';
7
+ export * from './request-logs.js';
@@ -0,0 +1,309 @@
1
+ export declare const request_logs: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "request_logs";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: "id";
7
+ tableName: "request_logs";
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
+ path: import("drizzle-orm/sqlite-core").SQLiteColumn<{
25
+ name: "path";
26
+ tableName: "request_logs";
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
+ method: import("drizzle-orm/sqlite-core").SQLiteColumn<{
44
+ name: "method";
45
+ tableName: "request_logs";
46
+ dataType: "string";
47
+ columnType: "SQLiteText";
48
+ data: string;
49
+ driverParam: string;
50
+ notNull: true;
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
+ status_code: import("drizzle-orm/sqlite-core").SQLiteColumn<{
63
+ name: "status_code";
64
+ tableName: "request_logs";
65
+ dataType: "number";
66
+ columnType: "SQLiteInteger";
67
+ data: number;
68
+ driverParam: number;
69
+ notNull: true;
70
+ hasDefault: false;
71
+ isPrimaryKey: false;
72
+ isAutoincrement: false;
73
+ hasRuntimeDefault: false;
74
+ enumValues: undefined;
75
+ baseColumn: never;
76
+ identity: undefined;
77
+ generated: undefined;
78
+ }, {}, {}>;
79
+ duration_ms: import("drizzle-orm/sqlite-core").SQLiteColumn<{
80
+ name: "duration_ms";
81
+ tableName: "request_logs";
82
+ dataType: "number";
83
+ columnType: "SQLiteInteger";
84
+ data: number;
85
+ driverParam: number;
86
+ notNull: true;
87
+ hasDefault: false;
88
+ isPrimaryKey: false;
89
+ isAutoincrement: false;
90
+ hasRuntimeDefault: false;
91
+ enumValues: undefined;
92
+ baseColumn: never;
93
+ identity: undefined;
94
+ generated: undefined;
95
+ }, {}, {}>;
96
+ ip: import("drizzle-orm/sqlite-core").SQLiteColumn<{
97
+ name: "ip";
98
+ tableName: "request_logs";
99
+ dataType: "string";
100
+ columnType: "SQLiteText";
101
+ data: string;
102
+ driverParam: string;
103
+ notNull: false;
104
+ hasDefault: false;
105
+ isPrimaryKey: false;
106
+ isAutoincrement: false;
107
+ hasRuntimeDefault: false;
108
+ enumValues: [string, ...string[]];
109
+ baseColumn: never;
110
+ identity: undefined;
111
+ generated: undefined;
112
+ }, {}, {
113
+ length: number | undefined;
114
+ }>;
115
+ request_headers: import("drizzle-orm/sqlite-core").SQLiteColumn<{
116
+ name: "request_headers";
117
+ tableName: "request_logs";
118
+ dataType: "string";
119
+ columnType: "SQLiteText";
120
+ data: string;
121
+ driverParam: string;
122
+ notNull: false;
123
+ hasDefault: false;
124
+ isPrimaryKey: false;
125
+ isAutoincrement: false;
126
+ hasRuntimeDefault: false;
127
+ enumValues: [string, ...string[]];
128
+ baseColumn: never;
129
+ identity: undefined;
130
+ generated: undefined;
131
+ }, {}, {
132
+ length: number | undefined;
133
+ }>;
134
+ response_headers: import("drizzle-orm/sqlite-core").SQLiteColumn<{
135
+ name: "response_headers";
136
+ tableName: "request_logs";
137
+ dataType: "string";
138
+ columnType: "SQLiteText";
139
+ data: string;
140
+ driverParam: string;
141
+ notNull: false;
142
+ hasDefault: false;
143
+ isPrimaryKey: false;
144
+ isAutoincrement: false;
145
+ hasRuntimeDefault: false;
146
+ enumValues: [string, ...string[]];
147
+ baseColumn: never;
148
+ identity: undefined;
149
+ generated: undefined;
150
+ }, {}, {
151
+ length: number | undefined;
152
+ }>;
153
+ request_body: import("drizzle-orm/sqlite-core").SQLiteColumn<{
154
+ name: "request_body";
155
+ tableName: "request_logs";
156
+ dataType: "string";
157
+ columnType: "SQLiteText";
158
+ data: string;
159
+ driverParam: string;
160
+ notNull: false;
161
+ hasDefault: false;
162
+ isPrimaryKey: false;
163
+ isAutoincrement: false;
164
+ hasRuntimeDefault: false;
165
+ enumValues: [string, ...string[]];
166
+ baseColumn: never;
167
+ identity: undefined;
168
+ generated: undefined;
169
+ }, {}, {
170
+ length: number | undefined;
171
+ }>;
172
+ response_body: import("drizzle-orm/sqlite-core").SQLiteColumn<{
173
+ name: "response_body";
174
+ tableName: "request_logs";
175
+ dataType: "string";
176
+ columnType: "SQLiteText";
177
+ data: string;
178
+ driverParam: string;
179
+ notNull: false;
180
+ hasDefault: false;
181
+ isPrimaryKey: false;
182
+ isAutoincrement: false;
183
+ hasRuntimeDefault: false;
184
+ enumValues: [string, ...string[]];
185
+ baseColumn: never;
186
+ identity: undefined;
187
+ generated: undefined;
188
+ }, {}, {
189
+ length: number | undefined;
190
+ }>;
191
+ query: import("drizzle-orm/sqlite-core").SQLiteColumn<{
192
+ name: "query";
193
+ tableName: "request_logs";
194
+ dataType: "string";
195
+ columnType: "SQLiteText";
196
+ data: string;
197
+ driverParam: string;
198
+ notNull: false;
199
+ hasDefault: false;
200
+ isPrimaryKey: false;
201
+ isAutoincrement: false;
202
+ hasRuntimeDefault: false;
203
+ enumValues: [string, ...string[]];
204
+ baseColumn: never;
205
+ identity: undefined;
206
+ generated: undefined;
207
+ }, {}, {
208
+ length: number | undefined;
209
+ }>;
210
+ user_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
211
+ name: "user_id";
212
+ tableName: "request_logs";
213
+ dataType: "string";
214
+ columnType: "SQLiteText";
215
+ data: string;
216
+ driverParam: string;
217
+ notNull: false;
218
+ hasDefault: false;
219
+ isPrimaryKey: false;
220
+ isAutoincrement: false;
221
+ hasRuntimeDefault: false;
222
+ enumValues: [string, ...string[]];
223
+ baseColumn: never;
224
+ identity: undefined;
225
+ generated: undefined;
226
+ }, {}, {
227
+ length: number | undefined;
228
+ }>;
229
+ project_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
230
+ name: "project_id";
231
+ tableName: "request_logs";
232
+ dataType: "string";
233
+ columnType: "SQLiteText";
234
+ data: string;
235
+ driverParam: string;
236
+ notNull: false;
237
+ hasDefault: false;
238
+ isPrimaryKey: false;
239
+ isAutoincrement: false;
240
+ hasRuntimeDefault: false;
241
+ enumValues: [string, ...string[]];
242
+ baseColumn: never;
243
+ identity: undefined;
244
+ generated: undefined;
245
+ }, {}, {
246
+ length: number | undefined;
247
+ }>;
248
+ partition_key: import("drizzle-orm/sqlite-core").SQLiteColumn<{
249
+ name: "partition_key";
250
+ tableName: "request_logs";
251
+ dataType: "string";
252
+ columnType: "SQLiteText";
253
+ data: string;
254
+ driverParam: string;
255
+ notNull: true;
256
+ hasDefault: false;
257
+ isPrimaryKey: false;
258
+ isAutoincrement: false;
259
+ hasRuntimeDefault: false;
260
+ enumValues: [string, ...string[]];
261
+ baseColumn: never;
262
+ identity: undefined;
263
+ generated: undefined;
264
+ }, {}, {
265
+ length: number | undefined;
266
+ }>;
267
+ timestamp: import("drizzle-orm/sqlite-core").SQLiteColumn<{
268
+ name: "timestamp";
269
+ tableName: "request_logs";
270
+ dataType: "string";
271
+ columnType: "SQLiteText";
272
+ data: string;
273
+ driverParam: string;
274
+ notNull: true;
275
+ hasDefault: true;
276
+ isPrimaryKey: false;
277
+ isAutoincrement: false;
278
+ hasRuntimeDefault: false;
279
+ enumValues: [string, ...string[]];
280
+ baseColumn: never;
281
+ identity: undefined;
282
+ generated: undefined;
283
+ }, {}, {
284
+ length: number | undefined;
285
+ }>;
286
+ metadata: import("drizzle-orm/sqlite-core").SQLiteColumn<{
287
+ name: "metadata";
288
+ tableName: "request_logs";
289
+ dataType: "string";
290
+ columnType: "SQLiteText";
291
+ data: string;
292
+ driverParam: string;
293
+ notNull: false;
294
+ hasDefault: false;
295
+ isPrimaryKey: false;
296
+ isAutoincrement: false;
297
+ hasRuntimeDefault: false;
298
+ enumValues: [string, ...string[]];
299
+ baseColumn: never;
300
+ identity: undefined;
301
+ generated: undefined;
302
+ }, {}, {
303
+ length: number | undefined;
304
+ }>;
305
+ };
306
+ dialect: "sqlite";
307
+ }>;
308
+ export type RequestLog = typeof request_logs.$inferSelect;
309
+ export type NewRequestLog = typeof request_logs.$inferInsert;