@convex-dev/agent 0.0.3 → 0.0.5-alpha.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 (54) hide show
  1. package/dist/commonjs/client/index.d.ts.map +1 -1
  2. package/dist/commonjs/client/index.js +33 -14
  3. package/dist/commonjs/client/index.js.map +1 -1
  4. package/dist/commonjs/component/messages.d.ts +120 -130
  5. package/dist/commonjs/component/messages.d.ts.map +1 -1
  6. package/dist/commonjs/component/messages.js +28 -61
  7. package/dist/commonjs/component/messages.js.map +1 -1
  8. package/dist/commonjs/component/schema.d.ts +4 -4
  9. package/dist/commonjs/component/schema.d.ts.map +1 -1
  10. package/dist/commonjs/component/schema.js +2 -2
  11. package/dist/commonjs/component/schema.js.map +1 -1
  12. package/dist/commonjs/shared.d.ts +1 -0
  13. package/dist/commonjs/shared.d.ts.map +1 -1
  14. package/dist/commonjs/shared.js +1 -0
  15. package/dist/commonjs/shared.js.map +1 -1
  16. package/dist/commonjs/validators.d.ts +14 -1
  17. package/dist/commonjs/validators.d.ts.map +1 -1
  18. package/dist/commonjs/validators.js +11 -1
  19. package/dist/commonjs/validators.js.map +1 -1
  20. package/dist/esm/client/index.d.ts.map +1 -1
  21. package/dist/esm/client/index.js +33 -14
  22. package/dist/esm/client/index.js.map +1 -1
  23. package/dist/esm/component/messages.d.ts +120 -130
  24. package/dist/esm/component/messages.d.ts.map +1 -1
  25. package/dist/esm/component/messages.js +28 -61
  26. package/dist/esm/component/messages.js.map +1 -1
  27. package/dist/esm/component/schema.d.ts +4 -4
  28. package/dist/esm/component/schema.d.ts.map +1 -1
  29. package/dist/esm/component/schema.js +2 -2
  30. package/dist/esm/component/schema.js.map +1 -1
  31. package/dist/esm/shared.d.ts +1 -0
  32. package/dist/esm/shared.d.ts.map +1 -1
  33. package/dist/esm/shared.js +1 -0
  34. package/dist/esm/shared.js.map +1 -1
  35. package/dist/esm/validators.d.ts +14 -1
  36. package/dist/esm/validators.d.ts.map +1 -1
  37. package/dist/esm/validators.js +11 -1
  38. package/dist/esm/validators.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/client/index.ts +51 -20
  41. package/src/component/_generated/api.d.ts +23 -24
  42. package/src/component/messages.ts +36 -66
  43. package/src/component/schema.ts +2 -2
  44. package/src/shared.ts +2 -0
  45. package/src/validators.ts +20 -2
  46. package/dist/commonjs/logging.d.ts +0 -18
  47. package/dist/commonjs/logging.d.ts.map +0 -1
  48. package/dist/commonjs/logging.js +0 -78
  49. package/dist/commonjs/logging.js.map +0 -1
  50. package/dist/esm/logging.d.ts +0 -18
  51. package/dist/esm/logging.d.ts.map +0 -1
  52. package/dist/esm/logging.js +0 -78
  53. package/dist/esm/logging.js.map +0 -1
  54. package/src/logging.ts +0 -103
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "email": "support@convex.dev",
8
8
  "url": "https://github.com/get-convex/agent/issues"
9
9
  },
10
- "version": "0.0.3",
10
+ "version": "0.0.5-alpha.0",
11
11
  "license": "Apache-2.0",
12
12
  "keywords": [
13
13
  "convex",
@@ -16,7 +16,13 @@ import type {
16
16
  ToolSet,
17
17
  Message as UIMessage,
18
18
  } from "ai";
19
- import { generateObject, generateText, streamObject, streamText } from "ai";
19
+ import {
20
+ generateObject,
21
+ generateText,
22
+ jsonSchema,
23
+ streamObject,
24
+ streamText,
25
+ } from "ai";
20
26
  import { assert } from "convex-helpers";
21
27
  import {
22
28
  ConvexToZod,
@@ -26,7 +32,7 @@ import {
26
32
  import { internalActionGeneric } from "convex/server";
27
33
  import { Infer, v, Validator } from "convex/values";
28
34
  import { z } from "zod";
29
- import { api, Mounts } from "../component/_generated/api";
35
+ import { Mounts } from "../component/_generated/api";
30
36
  import {
31
37
  validateVectorDimension,
32
38
  VectorDimension,
@@ -38,7 +44,11 @@ import {
38
44
  serializeObjectResult,
39
45
  serializeStep,
40
46
  } from "../mapping";
41
- import { DEFAULT_MESSAGE_RANGE, extractText } from "../shared";
47
+ import {
48
+ DEFAULT_MESSAGE_RANGE,
49
+ DEFAULT_RECENT_MESSAGES,
50
+ extractText,
51
+ } from "../shared";
42
52
  import {
43
53
  CallSettings,
44
54
  ProviderMetadata,
@@ -279,19 +289,25 @@ export class Agent<AgentTools extends ToolSet> {
279
289
  contextMessages.push(...searchMessages.map((m) => m.message!));
280
290
  }
281
291
  if (args.threadId) {
282
- const { messages } = await ctx.runQuery(
292
+ const { page } = await ctx.runQuery(
283
293
  this.component.messages.getThreadMessages,
284
294
  {
285
295
  threadId: args.threadId,
286
296
  isTool: args.includeToolCalls ?? false,
287
- limit: args.recentMessages,
297
+ paginationOpts: {
298
+ numItems:
299
+ args.recentMessages ??
300
+ this.options.contextOptions?.recentMessages ??
301
+ DEFAULT_RECENT_MESSAGES,
302
+ cursor: null,
303
+ },
288
304
  parentMessageId: args.parentMessageId,
289
305
  order: "desc",
290
306
  statuses: ["success"],
291
307
  }
292
308
  );
293
309
  contextMessages.push(
294
- ...messages.filter((m) => !included?.has(m._id)).map((m) => m.message!)
310
+ ...page.filter((m) => !included?.has(m._id)).map((m) => m.message!)
295
311
  );
296
312
  }
297
313
  return contextMessages;
@@ -444,7 +460,7 @@ export class Agent<AgentTools extends ToolSet> {
444
460
  const tools = wrapTools(toolCtx, this.options.tools, args.tools) as TOOLS;
445
461
  const maxSteps = args.maxSteps ?? this.options.maxSteps;
446
462
  try {
447
- const result = await generateText({
463
+ const result = (await generateText({
448
464
  model: this.options.chat,
449
465
  ...aiArgs,
450
466
  maxSteps,
@@ -461,8 +477,9 @@ export class Agent<AgentTools extends ToolSet> {
461
477
  }
462
478
  return args.onStepFinish?.(step);
463
479
  },
464
- });
465
- return { ...result, messageId };
480
+ })) as GenerateTextResult<TOOLS, OUTPUT> & GenerationOutputMetadata;
481
+ result.messageId = messageId;
482
+ return result;
466
483
  } catch (error) {
467
484
  if (threadId && messageId) {
468
485
  console.error("RollbackMessage", messageId);
@@ -530,8 +547,9 @@ export class Agent<AgentTools extends ToolSet> {
530
547
  }
531
548
  return args.onStepFinish?.(step);
532
549
  },
533
- });
534
- return { ...result, messageId };
550
+ }) as StreamTextResult<TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata;
551
+ result.messageId = messageId;
552
+ return result;
535
553
  }
536
554
 
537
555
  async saveMessagesAndFetchContext<
@@ -608,12 +626,13 @@ export class Agent<AgentTools extends ToolSet> {
608
626
  model: this.options.chat,
609
627
  ...aiArgs,
610
628
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
611
- } as any)) as GenerateObjectResult<T>;
629
+ } as any)) as GenerateObjectResult<T> & GenerationOutputMetadata;
612
630
 
613
631
  if (threadId && messageId && args.saveOutputMessages !== false) {
614
632
  await this.saveObject(ctx, { threadId, messageId, result });
615
633
  }
616
- return { ...result, messageId };
634
+ result.messageId = messageId;
635
+ return result;
617
636
  } catch (error) {
618
637
  if (threadId && messageId) {
619
638
  await ctx.runMutation(this.component.messages.rollbackMessage, {
@@ -668,8 +687,10 @@ export class Agent<AgentTools extends ToolSet> {
668
687
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
669
688
  return args.onFinish?.(result as any);
670
689
  },
671
- }) as StreamObjectResult<DeepPartial<T>, T, never>;
672
- return { ...stream, messageId };
690
+ }) as StreamObjectResult<DeepPartial<T>, T, never> &
691
+ GenerationOutputMetadata;
692
+ stream.messageId = messageId;
693
+ return stream;
673
694
  }
674
695
 
675
696
  async saveObject(
@@ -796,16 +817,26 @@ export class Agent<AgentTools extends ToolSet> {
796
817
  ...args.streamText,
797
818
  maxSteps: args.streamText.maxSteps ?? maxSteps,
798
819
  });
799
- return value.text;
820
+ await value.consumeStream();
821
+ return await value.text;
800
822
  } else if (args.generateObject) {
823
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
824
+ const { schema, ...rest } = args.generateObject as { schema?: any };
801
825
  const value = await this.generateObject(ctx, commonArgs, {
802
- ...(args.generateObject as GenerateObjectArgs<unknown>),
803
- });
826
+ ...rest,
827
+ schema: jsonSchema(schema),
828
+ } as unknown as OurObjectArgs<unknown>);
804
829
  return value.object;
805
830
  } else if (args.streamObject) {
831
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
832
+ const { schema, ...rest } = args.streamObject as { schema?: any };
806
833
  const value = await this.streamObject(ctx, commonArgs, {
807
- ...(args.streamObject as StreamObjectArgs<unknown>),
808
- });
834
+ ...rest,
835
+ schema: jsonSchema(schema),
836
+ } as unknown as OurStreamObjectArgs<unknown>);
837
+ for await (const chunk of value.fullStream) {
838
+ // no-op, just consume the stream
839
+ }
809
840
  return value.object;
810
841
  } else {
811
842
  throw new Error(
@@ -931,22 +931,6 @@ export type Mounts = {
931
931
  threadId: string;
932
932
  }>
933
933
  >;
934
- archiveThread: FunctionReference<
935
- "mutation",
936
- "public",
937
- { threadId: string },
938
- {
939
- _creationTime: number;
940
- _id: string;
941
- defaultSystemPrompt?: string;
942
- order?: number;
943
- parentThreadIds?: Array<string>;
944
- status: "active" | "archived";
945
- summary?: string;
946
- title?: string;
947
- userId?: string;
948
- }
949
- >;
950
934
  commitMessage: FunctionReference<
951
935
  "mutation",
952
936
  "public",
@@ -1035,10 +1019,16 @@ export type Mounts = {
1035
1019
  "query",
1036
1020
  "public",
1037
1021
  {
1038
- cursor?: string;
1039
1022
  isTool?: boolean;
1040
- limit?: number;
1041
1023
  order?: "asc" | "desc";
1024
+ paginationOpts?: {
1025
+ cursor: string | null;
1026
+ endCursor?: string | null;
1027
+ id?: number;
1028
+ maximumBytesRead?: number;
1029
+ maximumRowsRead?: number;
1030
+ numItems: number;
1031
+ };
1042
1032
  parentMessageId?: string;
1043
1033
  statuses?: Array<"pending" | "success" | "failed">;
1044
1034
  threadId: string;
@@ -1046,7 +1036,7 @@ export type Mounts = {
1046
1036
  {
1047
1037
  continueCursor: string;
1048
1038
  isDone: boolean;
1049
- messages: Array<{
1039
+ page: Array<{
1050
1040
  _creationTime: number;
1051
1041
  _id: string;
1052
1042
  agentName?: string;
@@ -1171,22 +1161,29 @@ export type Mounts = {
1171
1161
  tool: boolean;
1172
1162
  userId?: string;
1173
1163
  }>;
1164
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
1165
+ splitCursor?: string | null;
1174
1166
  }
1175
1167
  >;
1176
1168
  getThreadsByUserId: FunctionReference<
1177
1169
  "query",
1178
1170
  "public",
1179
1171
  {
1180
- cursor?: string | null;
1181
- limit?: number;
1182
- offset?: number;
1183
- statuses?: "active" | "archived";
1172
+ order?: "asc" | "desc";
1173
+ paginationOpts?: {
1174
+ cursor: string | null;
1175
+ endCursor?: string | null;
1176
+ id?: number;
1177
+ maximumBytesRead?: number;
1178
+ maximumRowsRead?: number;
1179
+ numItems: number;
1180
+ };
1184
1181
  userId: string;
1185
1182
  },
1186
1183
  {
1187
1184
  continueCursor: string;
1188
1185
  isDone: boolean;
1189
- threads: Array<{
1186
+ page: Array<{
1190
1187
  _creationTime: number;
1191
1188
  _id: string;
1192
1189
  defaultSystemPrompt?: string;
@@ -1197,6 +1194,8 @@ export type Mounts = {
1197
1194
  title?: string;
1198
1195
  userId?: string;
1199
1196
  }>;
1197
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
1198
+ splitCursor?: string | null;
1200
1199
  }
1201
1200
  >;
1202
1201
  rollbackMessage: FunctionReference<
@@ -3,14 +3,19 @@ import { paginator } from "convex-helpers/server/pagination";
3
3
  import { mergedStream, stream } from "convex-helpers/server/stream";
4
4
  import { nullable, partial } from "convex-helpers/validators";
5
5
  import { ObjectType } from "convex/values";
6
- import { DEFAULT_MESSAGE_RANGE, extractText, isTool } from "../shared.js";
7
6
  import {
7
+ DEFAULT_MESSAGE_RANGE,
8
+ DEFAULT_RECENT_MESSAGES,
9
+ extractText,
10
+ isTool,
11
+ } from "../shared.js";
12
+ import {
13
+ paginationResultValidator,
8
14
  vEmbeddingsWithMetadata,
9
15
  vMessageStatus,
10
16
  vMessageWithFileAndId,
11
17
  vSearchOptions,
12
18
  vStepWithMessages,
13
- vThreadStatus,
14
19
  } from "../validators.js";
15
20
  import { api, internal } from "./_generated/api.js";
16
21
  import { Doc, Id } from "./_generated/dataModel.js";
@@ -31,6 +36,7 @@ import {
31
36
  VectorTableId,
32
37
  vVectorId,
33
38
  } from "./vector/tables.js";
39
+ import { paginationOptsValidator } from "convex/server";
34
40
 
35
41
  export const getThread = query({
36
42
  args: { threadId: v.id("threads") },
@@ -43,38 +49,18 @@ export const getThread = query({
43
49
  export const getThreadsByUserId = query({
44
50
  args: {
45
51
  userId: v.string(),
46
- // Note: the other arguments cannot change from when the cursor was created.
47
- cursor: v.optional(v.union(v.string(), v.null())),
48
- limit: v.optional(v.number()),
49
- offset: v.optional(v.number()),
50
- statuses: v.optional(vThreadStatus),
52
+ order: v.optional(v.union(v.literal("asc"), v.literal("desc"))),
53
+ paginationOpts: v.optional(paginationOptsValidator),
51
54
  },
52
55
  handler: async (ctx, args) => {
53
- const status = args.statuses ?? "active";
54
56
  const threads = await paginator(ctx.db, schema)
55
57
  .query("threads")
56
- .withIndex("userId_status_order", (q) =>
57
- q
58
- .eq("userId", args.userId)
59
- .eq("status", status)
60
- .gte("order", args.offset ?? 0)
61
- )
62
- .order("desc")
63
- .paginate({
64
- numItems: args.limit ?? 100,
65
- cursor: args.cursor ?? null,
66
- });
67
- return {
68
- threads: threads.page,
69
- continueCursor: threads.continueCursor,
70
- isDone: threads.isDone,
71
- };
58
+ .withIndex("userId", (q) => q.eq("userId", args.userId))
59
+ .order(args.order ?? "desc")
60
+ .paginate(args.paginationOpts ?? { cursor: null, numItems: 100 });
61
+ return threads;
72
62
  },
73
- returns: v.object({
74
- threads: v.array(v.doc("threads")),
75
- continueCursor: v.string(),
76
- isDone: v.boolean(),
77
- }),
63
+ returns: paginationResultValidator(v.doc("threads")),
78
64
  });
79
65
 
80
66
  const vThread = schema.tables.threads.validator;
@@ -82,17 +68,8 @@ const vThread = schema.tables.threads.validator;
82
68
  export const createThread = mutation({
83
69
  args: omit(vThread.fields, ["order", "status"]),
84
70
  handler: async (ctx, args) => {
85
- const latestThread = await ctx.db
86
- .query("threads")
87
- .withIndex("userId_status_order", (q) =>
88
- q.eq("userId", args.userId).eq("status", "active")
89
- )
90
- .order("desc")
91
- .first();
92
- const order = (latestThread?.order ?? -1) + 1;
93
71
  const threadId = await ctx.db.insert("threads", {
94
72
  ...args,
95
- order,
96
73
  status: "active",
97
74
  });
98
75
  return (await ctx.db.get(threadId))!;
@@ -123,16 +100,17 @@ export const updateThread = mutation({
123
100
  returns: v.doc("threads"),
124
101
  });
125
102
 
126
- export const archiveThread = mutation({
127
- args: { threadId: v.id("threads") },
128
- handler: async (ctx, args) => {
129
- const thread = await ctx.db.get(args.threadId);
130
- assert(thread, `Thread ${args.threadId} not found`);
131
- await ctx.db.patch(args.threadId, { status: "archived" });
132
- return (await ctx.db.get(args.threadId))!;
133
- },
134
- returns: v.doc("threads"),
135
- });
103
+ // When we expose this, we need to also hide all the messages and steps
104
+ // export const archiveThread = mutation({
105
+ // args: { threadId: v.id("threads") },
106
+ // handler: async (ctx, args) => {
107
+ // const thread = await ctx.db.get(args.threadId);
108
+ // assert(thread, `Thread ${args.threadId} not found`);
109
+ // await ctx.db.patch(args.threadId, { status: "archived" });
110
+ // return (await ctx.db.get(args.threadId))!;
111
+ // },
112
+ // returns: v.doc("threads"),
113
+ // });
136
114
 
137
115
  export const deleteAllForUserId = action({
138
116
  args: { userId: v.string() },
@@ -222,7 +200,7 @@ async function deletePageForUserId(
222
200
  ): Promise<DeleteAllReturns> {
223
201
  const threads = await paginator(ctx.db, schema)
224
202
  .query("threads")
225
- .withIndex("userId_status_order", (q) => q.eq("userId", args.userId))
203
+ .withIndex("userId", (q) => q.eq("userId", args.userId))
226
204
  .order("desc")
227
205
  .paginate({
228
206
  numItems: 100,
@@ -651,9 +629,7 @@ export const getThreadMessages = query({
651
629
  threadId: v.id("threads"),
652
630
  isTool: v.optional(v.boolean()),
653
631
  order: v.optional(v.union(v.literal("asc"), v.literal("desc"))),
654
- limit: v.optional(v.number()),
655
- // Note: the other arguments cannot change from when the cursor was created.
656
- cursor: v.optional(v.string()),
632
+ paginationOpts: v.optional(paginationOptsValidator),
657
633
  statuses: v.optional(v.array(vMessageStatus)),
658
634
  parentMessageId: v.optional(v.id("messages")),
659
635
  },
@@ -684,21 +660,15 @@ export const getThreadMessages = query({
684
660
  const messages = await mergedStream(streams, [
685
661
  "order",
686
662
  "stepOrder",
687
- ]).paginate({
688
- numItems: args.limit ?? 100,
689
- cursor: args.cursor ?? null,
690
- });
691
- return {
692
- messages: messages.page,
693
- continueCursor: messages.continueCursor,
694
- isDone: messages.isDone,
695
- };
663
+ ]).paginate(
664
+ args.paginationOpts ?? {
665
+ numItems: DEFAULT_RECENT_MESSAGES,
666
+ cursor: null,
667
+ }
668
+ );
669
+ return messages;
696
670
  },
697
- returns: v.object({
698
- messages: v.array(v.doc("messages")),
699
- continueCursor: v.string(),
700
- isDone: v.boolean(),
701
- }),
671
+ returns: paginationResultValidator(v.doc("messages")),
702
672
  });
703
673
 
704
674
  export const searchMessages = action({
@@ -7,7 +7,7 @@ import vectorTables, { vVectorId } from "./vector/tables";
7
7
  export const schema = defineSchema({
8
8
  threads: defineTable({
9
9
  userId: v.optional(v.string()), // Unset for anonymous
10
- order: v.optional(v.number()), // within a domain
10
+ order: v.optional(v.number()), // DEPRECATED
11
11
  // TODO: is this bubbling up in continue?
12
12
  defaultSystemPrompt: v.optional(v.string()),
13
13
  title: v.optional(v.string()),
@@ -17,7 +17,7 @@ export const schema = defineSchema({
17
17
  // the parent thread(s). There are multiple if the thread is a merging of
18
18
  // multiple threads.
19
19
  parentThreadIds: v.optional(v.array(v.id("threads"))),
20
- }).index("userId_status_order", ["userId", "status", "order"]),
20
+ }).index("userId", ["userId"]),
21
21
  // TODO: text search on title/ summary
22
22
  messages: defineTable({
23
23
  id: v.optional(v.string()), // external id, e.g. from Vercel AI SDK
package/src/shared.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { CoreMessage } from "ai";
2
2
  import { Message } from "./validators";
3
3
 
4
+ export const DEFAULT_RECENT_MESSAGES = 100;
5
+
4
6
  export function isTool(message: Message | CoreMessage) {
5
7
  return (
6
8
  message.role === "tool" ||
package/src/validators.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Infer, ObjectType, v } from "convex/values";
1
+ import { Infer, ObjectType, v, Validator, Value } from "convex/values";
2
2
  import { vVectorDimension } from "./component/vector/tables";
3
3
 
4
4
  // const deprecated = v.optional(v.any()) as unknown as VNull<unknown, "optional">;
@@ -10,7 +10,7 @@ export type ProviderMetadata = Infer<typeof experimental_providerMetadata>;
10
10
 
11
11
  export const vThreadStatus = v.union(
12
12
  v.literal("active"),
13
- v.literal("archived")
13
+ v.literal("archived") // unused
14
14
  );
15
15
  export const vMessageStatus = v.union(
16
16
  v.literal("pending"),
@@ -391,3 +391,21 @@ export const vEmbeddingsWithMetadata = v.object({
391
391
  model: v.string(),
392
392
  });
393
393
  export type EmbeddingsWithMetadata = Infer<typeof vEmbeddingsWithMetadata>;
394
+
395
+ export function paginationResultValidator<
396
+ T extends Validator<Value, "required", string>,
397
+ >(itemValidator: T) {
398
+ return v.object({
399
+ page: v.array(itemValidator),
400
+ continueCursor: v.string(),
401
+ isDone: v.boolean(),
402
+ splitCursor: v.optional(v.union(v.string(), v.null())),
403
+ pageStatus: v.optional(
404
+ v.union(
405
+ v.literal("SplitRecommended"),
406
+ v.literal("SplitRequired"),
407
+ v.null()
408
+ )
409
+ ),
410
+ });
411
+ }
@@ -1,18 +0,0 @@
1
- import { Infer } from "convex/values";
2
- export declare const DEFAULT_LOG_LEVEL: LogLevel;
3
- export declare const logLevel: import("convex/values").VUnion<"DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"TRACE", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"REPORT", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
4
- export type LogLevel = Infer<typeof logLevel>;
5
- export type Logger = {
6
- debug: (...args: unknown[]) => void;
7
- info: (...args: unknown[]) => void;
8
- log: (...args: unknown[]) => void;
9
- warn: (...args: unknown[]) => void;
10
- error: (...args: unknown[]) => void;
11
- time: (label: string) => void;
12
- timeEnd: (label: string) => void;
13
- event: (event: string, payload: Record<string, unknown>) => void;
14
- logLevel: LogLevel;
15
- };
16
- export declare function shouldLog(config: LogLevel, level: LogLevel): boolean;
17
- export declare function createLogger(level?: LogLevel): Logger;
18
- //# sourceMappingURL=logging.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAEzC,eAAO,MAAM,iBAAiB,EAAE,QAAiB,CAAC;AAIlD,eAAO,MAAM,QAAQ,wbAOpB,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE9C,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACjE,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAUF,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,WAE1D;AAQD,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAwDrD"}
@@ -1,78 +0,0 @@
1
- import { v } from "convex/values";
2
- export const DEFAULT_LOG_LEVEL = "WARN";
3
- // NOTE: the ordering here is important! A config level of "INFO" will log
4
- // "INFO", "REPORT", "WARN",and "ERROR" events.
5
- export const logLevel = v.union(v.literal("DEBUG"), v.literal("TRACE"), v.literal("INFO"), v.literal("REPORT"), v.literal("WARN"), v.literal("ERROR"));
6
- const logLevelOrder = logLevel.members.map((l) => l.value);
7
- const logLevelByName = logLevelOrder.reduce((acc, l, i) => {
8
- acc[l] = i;
9
- return acc;
10
- }, {});
11
- export function shouldLog(config, level) {
12
- return logLevelByName[config] <= logLevelByName[level];
13
- }
14
- const DEBUG = logLevelByName["DEBUG"];
15
- const TRACE = logLevelByName["TRACE"];
16
- const INFO = logLevelByName["INFO"];
17
- const REPORT = logLevelByName["REPORT"];
18
- const WARN = logLevelByName["WARN"];
19
- const ERROR = logLevelByName["ERROR"];
20
- export function createLogger(level) {
21
- const logLevel = level ?? DEFAULT_LOG_LEVEL;
22
- const levelIndex = logLevelByName[logLevel];
23
- if (levelIndex === undefined) {
24
- throw new Error(`Invalid log level: ${logLevel}`);
25
- }
26
- return {
27
- logLevel,
28
- debug: (...args) => {
29
- if (levelIndex <= DEBUG) {
30
- console.debug(...args);
31
- }
32
- },
33
- log: (...args) => {
34
- if (levelIndex <= INFO) {
35
- console.log(...args);
36
- }
37
- },
38
- info: (...args) => {
39
- if (levelIndex <= INFO) {
40
- console.info(...args);
41
- }
42
- },
43
- warn: (...args) => {
44
- if (levelIndex <= WARN) {
45
- console.warn(...args);
46
- }
47
- },
48
- error: (...args) => {
49
- if (levelIndex <= ERROR) {
50
- console.error(...args);
51
- }
52
- },
53
- time: (label) => {
54
- if (levelIndex <= TRACE) {
55
- console.time(label);
56
- }
57
- },
58
- timeEnd: (label) => {
59
- if (levelIndex <= TRACE) {
60
- console.timeEnd(label);
61
- }
62
- },
63
- event: (event, payload) => {
64
- const fullPayload = {
65
- component: "workflow",
66
- event,
67
- ...payload,
68
- };
69
- if (levelIndex === REPORT && event === "report") {
70
- console.info(JSON.stringify(fullPayload));
71
- }
72
- else if (levelIndex <= INFO) {
73
- console.info(JSON.stringify(fullPayload));
74
- }
75
- },
76
- };
77
- }
78
- //# sourceMappingURL=logging.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAS,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAa,MAAM,CAAC;AAElD,0EAA0E;AAC1E,+CAA+C;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAC7B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAClB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAClB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EACjB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EACjB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CACnB,CAAC;AAeF,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC3D,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CACzC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACZ,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,CAAC;AACb,CAAC,EAC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EVEL: LogLevel;
3
- export declare const logLevel: import("convex/values").VUnion<"DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"TRACE", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"REPORT", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
4
- export type LogLevel = Infer<typeof logLevel>;
5
- export type Logger = {
6
- debug: (...args: unknown[]) => void;
7
- info: (...args: unknown[]) => void;
8
- log: (...args: unknown[]) => void;
9
- warn: (...args: unknown[]) => void;
10
- error: (...args: unknown[]) => void;
11
- time: (label: string) => void;
12
- timeEnd: (label: string) => void;
13
- event: (event: string, payload: Record<string, unknown>) => void;
14
- logLevel: LogLevel;
15
- };
16
- export declare function shouldLog(config: LogLevel, level: LogLevel): boolean;
17
- export declare function createLogger(level?: LogLevel): Logger;
18
- //# sourceMappingURL=logging.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAEzC,eAAO,MAAM,iBAAiB,EAAE,QAAiB,CAAC;AAIlD,eAAO,MAAM,QAAQ,wbAOpB,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE9C,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACjE,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAUF,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,WAE1D;AAQD,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAwDrD"}