@okrlinkhub/agent-factory 0.2.3 → 0.2.5

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 (42) hide show
  1. package/README.md +44 -0
  2. package/dist/client/bridge.d.ts +1 -0
  3. package/dist/client/bridge.d.ts.map +1 -1
  4. package/dist/client/bridge.js +24 -6
  5. package/dist/client/bridge.js.map +1 -1
  6. package/dist/client/index.d.ts +145 -2
  7. package/dist/client/index.d.ts.map +1 -1
  8. package/dist/client/index.js +192 -0
  9. package/dist/client/index.js.map +1 -1
  10. package/dist/component/_generated/api.d.ts +2 -0
  11. package/dist/component/_generated/api.d.ts.map +1 -1
  12. package/dist/component/_generated/api.js.map +1 -1
  13. package/dist/component/_generated/component.d.ts +456 -0
  14. package/dist/component/_generated/component.d.ts.map +1 -1
  15. package/dist/component/lib.d.ts +1 -0
  16. package/dist/component/lib.d.ts.map +1 -1
  17. package/dist/component/lib.js +1 -0
  18. package/dist/component/lib.js.map +1 -1
  19. package/dist/component/pushing.d.ts +226 -0
  20. package/dist/component/pushing.d.ts.map +1 -0
  21. package/dist/component/pushing.js +954 -0
  22. package/dist/component/pushing.js.map +1 -0
  23. package/dist/component/queue.d.ts +8 -5
  24. package/dist/component/queue.d.ts.map +1 -1
  25. package/dist/component/queue.js +28 -1
  26. package/dist/component/queue.js.map +1 -1
  27. package/dist/component/schema.d.ts +261 -8
  28. package/dist/component/schema.d.ts.map +1 -1
  29. package/dist/component/schema.js +104 -0
  30. package/dist/component/schema.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/client/bridge.test.ts +2 -0
  33. package/src/client/bridge.ts +32 -6
  34. package/src/client/index.test.ts +29 -19
  35. package/src/client/index.ts +209 -0
  36. package/src/component/_generated/api.ts +2 -0
  37. package/src/component/_generated/component.ts +448 -0
  38. package/src/component/lib.test.ts +103 -0
  39. package/src/component/lib.ts +17 -0
  40. package/src/component/pushing.ts +1111 -0
  41. package/src/component/queue.ts +45 -1
  42. package/src/component/schema.ts +138 -0
@@ -53,10 +53,12 @@ const bridgeProfileConfigValidator = v.object({
53
53
  serviceId: v.optional(v.string()),
54
54
  appKey: v.optional(v.string()),
55
55
  serviceKeySecretRef: v.optional(v.string()),
56
+ appBaseUrlMapJsonSecretRef: v.optional(v.string()),
56
57
  });
57
58
 
58
59
  const bridgeRuntimeConfigValidator = v.object({
59
60
  baseUrl: v.union(v.null(), v.string()),
61
+ appBaseUrlMapJson: v.union(v.null(), v.string()),
60
62
  serviceId: v.union(v.null(), v.string()),
61
63
  appKey: v.union(v.null(), v.string()),
62
64
  serviceKey: v.union(v.null(), v.string()),
@@ -66,6 +68,7 @@ const bridgeRuntimeConfigValidator = v.object({
66
68
  const BRIDGE_SECRET_REFS = {
67
69
  serviceKey: "agent-bridge.serviceKey",
68
70
  baseUrl: "agent-bridge.baseUrl",
71
+ baseUrlMapJson: "agent-bridge.baseUrlMapJson",
69
72
  serviceId: "agent-bridge.serviceId",
70
73
  appKey: "agent-bridge.appKey",
71
74
  } as const;
@@ -91,6 +94,31 @@ export const enqueueMessage = mutation({
91
94
  if (!profile || !profile.enabled) {
92
95
  throw new Error(`Agent profile '${args.agentKey}' not found or disabled`);
93
96
  }
97
+ const resolvedProviderUserId =
98
+ profile.providerUserId && profile.providerUserId.trim().length > 0
99
+ ? profile.providerUserId.trim()
100
+ : args.payload.providerUserId;
101
+
102
+ const providerUserIdStr =
103
+ typeof resolvedProviderUserId === "string" &&
104
+ resolvedProviderUserId.trim().length > 0
105
+ ? resolvedProviderUserId.trim()
106
+ : null;
107
+
108
+ if (providerUserIdStr === null) {
109
+ throw new Error(
110
+ `providerUserId is required but missing: profile.providerUserId=${JSON.stringify(profile.providerUserId)}, payload.providerUserId=${JSON.stringify(args.payload.providerUserId)}`,
111
+ );
112
+ }
113
+
114
+ const payload = {
115
+ ...args.payload,
116
+ providerUserId: providerUserIdStr,
117
+ metadata: {
118
+ ...(args.payload.metadata ?? {}),
119
+ providerUserId: providerUserIdStr,
120
+ },
121
+ };
94
122
 
95
123
  const existingConversation = await ctx.db
96
124
  .query("conversations")
@@ -116,7 +144,7 @@ export const enqueueMessage = mutation({
116
144
  const messageId = await ctx.db.insert("messageQueue", {
117
145
  conversationId: args.conversationId,
118
146
  agentKey: args.agentKey,
119
- payload: args.payload,
147
+ payload,
120
148
  status: "queued",
121
149
  priority,
122
150
  scheduledFor: args.scheduledFor ?? nowMs,
@@ -209,6 +237,7 @@ export const appendConversationMessages = mutation({
209
237
  export const upsertAgentProfile = mutation({
210
238
  args: {
211
239
  agentKey: v.string(),
240
+ providerUserId: v.optional(v.string()),
212
241
  version: v.string(),
213
242
  soulMd: v.string(),
214
243
  clientMd: v.optional(v.string()),
@@ -1413,10 +1442,12 @@ async function resolveBridgeRuntimeConfig(
1413
1442
  serviceId?: string;
1414
1443
  appKey?: string;
1415
1444
  serviceKeySecretRef?: string;
1445
+ appBaseUrlMapJsonSecretRef?: string;
1416
1446
  };
1417
1447
  },
1418
1448
  ): Promise<{
1419
1449
  baseUrl: string | null;
1450
+ appBaseUrlMapJson: string | null;
1420
1451
  serviceId: string | null;
1421
1452
  appKey: string | null;
1422
1453
  serviceKey: string | null;
@@ -1427,6 +1458,7 @@ async function resolveBridgeRuntimeConfig(
1427
1458
  }
1428
1459
 
1429
1460
  const configuredServiceKeySecretRef = profile.bridgeConfig.serviceKeySecretRef ?? null;
1461
+ const configuredBaseUrlMapSecretRef = profile.bridgeConfig.appBaseUrlMapJsonSecretRef ?? null;
1430
1462
  const [serviceKeySecretRef, serviceKey] = await resolveFirstActiveSecretValue(
1431
1463
  ctx,
1432
1464
  getScopedSecretRefCandidates(
@@ -1440,6 +1472,14 @@ async function resolveBridgeRuntimeConfig(
1440
1472
  ctx,
1441
1473
  getScopedSecretRefCandidates(profile.agentKey, BRIDGE_SECRET_REFS.baseUrl),
1442
1474
  );
1475
+ const [, appBaseUrlMapJsonFromSecret] = await resolveFirstActiveSecretValue(
1476
+ ctx,
1477
+ getScopedSecretRefCandidates(
1478
+ profile.agentKey,
1479
+ BRIDGE_SECRET_REFS.baseUrlMapJson,
1480
+ configuredBaseUrlMapSecretRef,
1481
+ ),
1482
+ );
1443
1483
  const [, serviceIdFromSecret] = await resolveFirstActiveSecretValue(
1444
1484
  ctx,
1445
1485
  getScopedSecretRefCandidates(profile.agentKey, BRIDGE_SECRET_REFS.serviceId),
@@ -1451,6 +1491,7 @@ async function resolveBridgeRuntimeConfig(
1451
1491
 
1452
1492
  return {
1453
1493
  baseUrl: profile.bridgeConfig.baseUrl ?? baseUrlFromSecret,
1494
+ appBaseUrlMapJson: appBaseUrlMapJsonFromSecret,
1454
1495
  serviceId: profile.bridgeConfig.serviceId ?? serviceIdFromSecret,
1455
1496
  appKey: profile.bridgeConfig.appKey ?? appKeyFromSecret,
1456
1497
  serviceKey,
@@ -1464,6 +1505,7 @@ function getBridgeSecretRefsForProfile(
1464
1505
  | {
1465
1506
  enabled: boolean;
1466
1507
  serviceKeySecretRef?: string;
1508
+ appBaseUrlMapJsonSecretRef?: string;
1467
1509
  }
1468
1510
  | undefined,
1469
1511
  ): Array<string> {
@@ -1472,6 +1514,8 @@ function getBridgeSecretRefsForProfile(
1472
1514
  }
1473
1515
  const refs: Array<string> = [
1474
1516
  bridgeConfig.serviceKeySecretRef ?? `${BRIDGE_SECRET_REFS.serviceKey}.${agentKey}`,
1517
+ bridgeConfig.appBaseUrlMapJsonSecretRef ??
1518
+ `${BRIDGE_SECRET_REFS.baseUrlMapJson}.${agentKey}`,
1475
1519
  ];
1476
1520
  return refs;
1477
1521
  }
@@ -4,6 +4,7 @@ import { v } from "convex/values";
4
4
  export default defineSchema({
5
5
  agentProfiles: defineTable({
6
6
  agentKey: v.string(),
7
+ providerUserId: v.optional(v.string()),
7
8
  version: v.string(),
8
9
  soulMd: v.string(),
9
10
  clientMd: v.optional(v.string()),
@@ -16,6 +17,7 @@ export default defineSchema({
16
17
  serviceId: v.optional(v.string()),
17
18
  appKey: v.optional(v.string()),
18
19
  serviceKeySecretRef: v.optional(v.string()),
20
+ appBaseUrlMapJsonSecretRef: v.optional(v.string()),
19
21
  }),
20
22
  ),
21
23
  enabled: v.boolean(),
@@ -227,4 +229,140 @@ export default defineSchema({
227
229
  })
228
230
  .index("by_conversationId", ["conversationId"])
229
231
  .index("by_agentKey_and_lastHydratedAt", ["agentKey", "lastHydratedAt"]),
232
+
233
+ messagePushTemplates: defineTable({
234
+ companyId: v.string(),
235
+ templateKey: v.string(),
236
+ title: v.string(),
237
+ text: v.string(),
238
+ periodicity: v.union(
239
+ v.literal("manual"),
240
+ v.literal("daily"),
241
+ v.literal("weekly"),
242
+ v.literal("monthly"),
243
+ ),
244
+ suggestedTimes: v.array(
245
+ v.union(
246
+ v.object({
247
+ kind: v.literal("daily"),
248
+ time: v.string(),
249
+ }),
250
+ v.object({
251
+ kind: v.literal("weekly"),
252
+ weekday: v.number(),
253
+ time: v.string(),
254
+ }),
255
+ v.object({
256
+ kind: v.literal("monthly"),
257
+ dayOfMonth: v.union(v.number(), v.literal("last")),
258
+ time: v.string(),
259
+ }),
260
+ ),
261
+ ),
262
+ enabled: v.boolean(),
263
+ createdBy: v.string(),
264
+ updatedBy: v.string(),
265
+ createdAt: v.number(),
266
+ updatedAt: v.number(),
267
+ })
268
+ .index("by_companyId", ["companyId"])
269
+ .index("by_companyId_and_templateKey", ["companyId", "templateKey"])
270
+ .index("by_companyId_and_enabled", ["companyId", "enabled"]),
271
+
272
+ messagePushJobs: defineTable({
273
+ companyId: v.string(),
274
+ consumerUserId: v.string(),
275
+ agentKey: v.optional(v.string()),
276
+ sourceTemplateId: v.optional(v.id("messagePushTemplates")),
277
+ title: v.string(),
278
+ text: v.string(),
279
+ periodicity: v.union(
280
+ v.literal("manual"),
281
+ v.literal("daily"),
282
+ v.literal("weekly"),
283
+ v.literal("monthly"),
284
+ ),
285
+ timezone: v.string(),
286
+ schedule: v.union(
287
+ v.object({
288
+ kind: v.literal("manual"),
289
+ }),
290
+ v.object({
291
+ kind: v.literal("daily"),
292
+ time: v.string(),
293
+ }),
294
+ v.object({
295
+ kind: v.literal("weekly"),
296
+ weekday: v.number(),
297
+ time: v.string(),
298
+ }),
299
+ v.object({
300
+ kind: v.literal("monthly"),
301
+ dayOfMonth: v.union(v.number(), v.literal("last")),
302
+ time: v.string(),
303
+ }),
304
+ ),
305
+ enabled: v.boolean(),
306
+ nextRunAt: v.optional(v.number()),
307
+ lastRunAt: v.optional(v.number()),
308
+ lastRunKey: v.optional(v.string()),
309
+ createdAt: v.number(),
310
+ updatedAt: v.number(),
311
+ })
312
+ .index("by_enabled_and_nextRunAt", ["enabled", "nextRunAt"])
313
+ .index("by_consumerUserId", ["consumerUserId"])
314
+ .index("by_consumerUserId_and_enabled", ["consumerUserId", "enabled"])
315
+ .index("by_companyId", ["companyId"])
316
+ .index("by_companyId_and_enabled", ["companyId", "enabled"])
317
+ .index("by_sourceTemplateId", ["sourceTemplateId"]),
318
+
319
+ messagePushDispatches: defineTable({
320
+ jobId: v.id("messagePushJobs"),
321
+ consumerUserId: v.string(),
322
+ runKey: v.string(),
323
+ scheduledFor: v.number(),
324
+ enqueuedMessageId: v.optional(v.id("messageQueue")),
325
+ status: v.union(
326
+ v.literal("enqueued"),
327
+ v.literal("skipped"),
328
+ v.literal("failed"),
329
+ ),
330
+ error: v.optional(v.string()),
331
+ createdAt: v.number(),
332
+ })
333
+ .index("by_jobId_and_runKey", ["jobId", "runKey"])
334
+ .index("by_consumerUserId_and_createdAt", ["consumerUserId", "createdAt"]),
335
+
336
+ messagePushBroadcasts: defineTable({
337
+ companyId: v.string(),
338
+ title: v.string(),
339
+ text: v.string(),
340
+ target: v.literal("all_active_agents"),
341
+ requestedBy: v.string(),
342
+ requestedAt: v.number(),
343
+ status: v.union(v.literal("running"), v.literal("done"), v.literal("failed")),
344
+ totalTargets: v.number(),
345
+ enqueuedCount: v.number(),
346
+ failedCount: v.number(),
347
+ completedAt: v.optional(v.number()),
348
+ })
349
+ .index("by_companyId_and_requestedAt", ["companyId", "requestedAt"])
350
+ .index("by_status", ["status"]),
351
+
352
+ messagePushBroadcastDispatches: defineTable({
353
+ broadcastId: v.id("messagePushBroadcasts"),
354
+ consumerUserId: v.string(),
355
+ agentKey: v.string(),
356
+ runKey: v.string(),
357
+ enqueuedMessageId: v.optional(v.id("messageQueue")),
358
+ status: v.union(
359
+ v.literal("enqueued"),
360
+ v.literal("skipped"),
361
+ v.literal("failed"),
362
+ ),
363
+ error: v.optional(v.string()),
364
+ createdAt: v.number(),
365
+ })
366
+ .index("by_broadcastId_and_consumerUserId", ["broadcastId", "consumerUserId"])
367
+ .index("by_broadcastId_and_createdAt", ["broadcastId", "createdAt"]),
230
368
  });