@inkeep/agents-core 0.47.5 → 0.48.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 (78) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/auth-schema.d.ts +83 -83
  3. package/dist/auth/auth-validation-schemas.d.ts +148 -148
  4. package/dist/auth/auth.d.ts +58 -58
  5. package/dist/auth/permissions.d.ts +13 -13
  6. package/dist/client-exports.d.ts +13 -2
  7. package/dist/client-exports.js +5 -4
  8. package/dist/data-access/index.d.ts +6 -1
  9. package/dist/data-access/index.js +6 -1
  10. package/dist/data-access/manage/agentFull.js +154 -1
  11. package/dist/data-access/manage/agents.d.ts +4 -4
  12. package/dist/data-access/manage/agents.js +56 -4
  13. package/dist/data-access/manage/artifactComponents.d.ts +41 -5
  14. package/dist/data-access/manage/dataComponents.d.ts +2 -2
  15. package/dist/data-access/manage/functionTools.d.ts +3 -3
  16. package/dist/data-access/manage/projectFull.js +97 -0
  17. package/dist/data-access/manage/scheduledTriggers.d.ts +80 -0
  18. package/dist/data-access/manage/scheduledTriggers.js +76 -0
  19. package/dist/data-access/manage/scheduledWorkflows.d.ts +29 -0
  20. package/dist/data-access/manage/scheduledWorkflows.js +32 -0
  21. package/dist/data-access/manage/skills.d.ts +109 -0
  22. package/dist/data-access/manage/skills.js +122 -0
  23. package/dist/data-access/manage/subAgentRelations.d.ts +6 -6
  24. package/dist/data-access/manage/tools.d.ts +4 -4
  25. package/dist/data-access/runtime/conversations.d.ts +11 -11
  26. package/dist/data-access/runtime/messages.d.ts +9 -9
  27. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +233 -0
  28. package/dist/data-access/runtime/scheduledTriggerInvocations.js +226 -0
  29. package/dist/data-access/runtime/tasks.d.ts +4 -4
  30. package/dist/data-access/runtime/workAppSlack.d.ts +55 -0
  31. package/dist/data-access/runtime/workAppSlack.js +146 -0
  32. package/dist/db/manage/manage-schema.d.ts +1436 -506
  33. package/dist/db/manage/manage-schema.js +240 -15
  34. package/dist/db/runtime/runtime-schema.d.ts +1244 -242
  35. package/dist/db/runtime/runtime-schema.js +108 -3
  36. package/dist/index.d.ts +15 -6
  37. package/dist/index.js +13 -5
  38. package/dist/types/entities.d.ts +15 -2
  39. package/dist/types/index.d.ts +2 -2
  40. package/dist/utils/index.d.ts +5 -2
  41. package/dist/utils/index.js +5 -2
  42. package/dist/utils/slack-link-token.d.ts +57 -0
  43. package/dist/utils/slack-link-token.js +112 -0
  44. package/dist/utils/slack-user-token.d.ts +65 -0
  45. package/dist/utils/slack-user-token.js +129 -0
  46. package/dist/utils/sse-parser.d.ts +35 -0
  47. package/dist/utils/sse-parser.js +71 -0
  48. package/dist/utils/tracer-factory.d.ts +11 -2
  49. package/dist/utils/tracer-factory.js +24 -5
  50. package/dist/utils/tracer.d.ts +2 -2
  51. package/dist/utils/tracer.js +2 -2
  52. package/dist/utils/trigger-auth.d.ts +1 -1
  53. package/dist/validation/dolt-schemas.d.ts +1 -1
  54. package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
  55. package/dist/validation/extend-schemas.d.ts +34 -0
  56. package/dist/validation/extend-schemas.js +33 -0
  57. package/dist/validation/index.d.ts +2 -2
  58. package/dist/validation/index.js +2 -2
  59. package/dist/validation/json-schemas.d.ts +28 -0
  60. package/dist/validation/json-schemas.js +56 -0
  61. package/dist/validation/schemas.d.ts +5719 -2429
  62. package/dist/validation/schemas.js +159 -38
  63. package/dist/validation/stream-event-schemas.d.ts +0 -2
  64. package/dist/validation/stream-event-schemas.js +1 -2
  65. package/drizzle/manage/0007_nice_lilandra.sql +3 -0
  66. package/drizzle/manage/0008_friendly_mentallo.sql +32 -0
  67. package/drizzle/manage/0009_chilly_old_lace.sql +39 -0
  68. package/drizzle/manage/meta/0007_snapshot.json +3148 -0
  69. package/drizzle/manage/meta/0008_snapshot.json +3391 -0
  70. package/drizzle/manage/meta/0009_snapshot.json +3670 -0
  71. package/drizzle/manage/meta/_journal.json +21 -0
  72. package/drizzle/runtime/0012_greedy_hulk.sql +84 -0
  73. package/drizzle/runtime/0013_huge_white_queen.sql +19 -0
  74. package/drizzle/runtime/meta/0007_snapshot.json +1 -1
  75. package/drizzle/runtime/meta/0012_snapshot.json +3622 -0
  76. package/drizzle/runtime/meta/0013_snapshot.json +3746 -0
  77. package/drizzle/runtime/meta/_journal.json +14 -0
  78. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { getLogger } from "../../utils/logger.js";
2
2
  import { deleteExternalAgent, listExternalAgents, upsertExternalAgent } from "./externalAgents.js";
3
3
  import { deleteFunction, listFunctions, upsertFunction } from "./functions.js";
4
+ import { listSkills, upsertSkill } from "./skills.js";
4
5
  import { deleteCredentialReference, listCredentialReferences, upsertCredentialReference } from "./credentialReferences.js";
5
6
  import { deleteTool, listTools, upsertTool } from "./tools.js";
6
7
  import { listAgents } from "./agents.js";
@@ -42,6 +43,37 @@ const createFullProjectServerSide = (db, logger = defaultLogger) => async (param
42
43
  logger.info({ projectId: typed.id }, "Creating project metadata");
43
44
  await createProject(db)(projectPayload);
44
45
  logger.info({ projectId: typed.id }, "Project metadata created successfully");
46
+ if (typed.skills && Object.keys(typed.skills).length) {
47
+ logger.info({
48
+ projectId: typed.id,
49
+ count: Object.keys(typed.skills).length
50
+ }, "Creating project skills");
51
+ const skillPromises = Object.entries(typed.skills).map(async ([skillId, skill]) => {
52
+ try {
53
+ await upsertSkill(db)({
54
+ ...skill,
55
+ tenantId,
56
+ projectId: typed.id
57
+ });
58
+ logger.info({
59
+ projectId: typed.id,
60
+ skillId
61
+ }, "Skill processed");
62
+ } catch (error) {
63
+ logger.error({
64
+ projectId: typed.id,
65
+ skillId,
66
+ error
67
+ }, "Failed to create skill");
68
+ throw error;
69
+ }
70
+ });
71
+ await Promise.all(skillPromises);
72
+ logger.info({
73
+ projectId: typed.id,
74
+ count: Object.keys(typed.skills).length
75
+ }, "All project skills created successfully");
76
+ }
45
77
  if (typed.credentialReferences && Object.keys(typed.credentialReferences).length > 0) {
46
78
  logger.info({
47
79
  projectId: typed.id,
@@ -395,6 +427,37 @@ const updateFullProjectServerSide = (db, logger = defaultLogger) => async (param
395
427
  data: projectUpdatePayload
396
428
  });
397
429
  logger.info({ projectId: typed.id }, "Project metadata updated successfully");
430
+ if (typed.skills && Object.keys(typed.skills).length) {
431
+ logger.info({
432
+ projectId: typed.id,
433
+ count: Object.keys(typed.skills).length
434
+ }, "Updating project skills");
435
+ const skillPromises = Object.entries(typed.skills).map(async ([skillId, skill]) => {
436
+ try {
437
+ await upsertSkill(db)({
438
+ ...skill,
439
+ tenantId,
440
+ projectId: typed.id
441
+ });
442
+ logger.info({
443
+ projectId: typed.id,
444
+ skillId
445
+ }, "Skill processed");
446
+ } catch (error) {
447
+ logger.error({
448
+ projectId: typed.id,
449
+ skillId,
450
+ error
451
+ }, "Failed to update skill");
452
+ throw error;
453
+ }
454
+ });
455
+ await Promise.all(skillPromises);
456
+ logger.info({
457
+ projectId: typed.id,
458
+ count: Object.keys(typed.skills).length
459
+ }, "All project skills updated successfully");
460
+ }
398
461
  if (typed.credentialReferences && Object.keys(typed.credentialReferences).length > 0) {
399
462
  logger.info({
400
463
  projectId: typed.id,
@@ -1009,6 +1072,39 @@ const getFullProjectInternal = (db, logger = defaultLogger) => async (params) =>
1009
1072
  error
1010
1073
  }, "Failed to retrieve functions for project");
1011
1074
  }
1075
+ const projectSkills = {};
1076
+ try {
1077
+ const skillsList = await listSkills(db)({
1078
+ scopes: {
1079
+ tenantId,
1080
+ projectId
1081
+ },
1082
+ pagination: {
1083
+ page: 1,
1084
+ limit: 1e3
1085
+ }
1086
+ });
1087
+ for (const skill of skillsList.data) projectSkills[skill.id] = {
1088
+ id: skill.id,
1089
+ name: skill.name,
1090
+ description: skill.description,
1091
+ content: skill.content,
1092
+ metadata: skill.metadata,
1093
+ createdAt: skill.createdAt,
1094
+ updatedAt: skill.updatedAt
1095
+ };
1096
+ logger.info({
1097
+ tenantId,
1098
+ projectId,
1099
+ skillCount: Object.keys(projectSkills).length
1100
+ }, "Skills retrieved for project");
1101
+ } catch (error) {
1102
+ logger.warn({
1103
+ tenantId,
1104
+ projectId,
1105
+ error
1106
+ }, "Failed to retrieve skills for project");
1107
+ }
1012
1108
  const agents = {};
1013
1109
  if (agentList.length > 0) {
1014
1110
  const getAgentFn = includeRelationIds ? getFullAgentWithRelationIds : getFullAgent;
@@ -1071,6 +1167,7 @@ const getFullProjectInternal = (db, logger = defaultLogger) => async (params) =>
1071
1167
  credentialReferences: Object.keys(projectCredentialReferences).length > 0 ? projectCredentialReferences : null,
1072
1168
  statusUpdates: null,
1073
1169
  functionTools: null,
1170
+ skills: Object.keys(projectSkills).length > 0 ? projectSkills : void 0,
1074
1171
  createdAt: project.createdAt,
1075
1172
  updatedAt: project.updatedAt
1076
1173
  };
@@ -0,0 +1,80 @@
1
+ import { AgentScopeConfig, PaginationConfig } from "../../types/utility.js";
2
+ import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
3
+ import { ScheduledTrigger, ScheduledTriggerInsert, ScheduledTriggerUpdate } from "../../validation/schemas.js";
4
+
5
+ //#region src/data-access/manage/scheduledTriggers.d.ts
6
+
7
+ /**
8
+ * Get a scheduled trigger by ID (agent-scoped)
9
+ */
10
+ declare const getScheduledTriggerById: (db: AgentsManageDatabaseClient) => (params: {
11
+ scopes: AgentScopeConfig;
12
+ scheduledTriggerId: string;
13
+ }) => Promise<ScheduledTrigger | undefined>;
14
+ /**
15
+ * List scheduled triggers for an agent with pagination
16
+ */
17
+ declare const listScheduledTriggersPaginated: (db: AgentsManageDatabaseClient) => (params: {
18
+ scopes: AgentScopeConfig;
19
+ pagination?: PaginationConfig;
20
+ }) => Promise<{
21
+ data: {
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ enabled: boolean;
25
+ cronExpression: string | null;
26
+ cronTimezone: string | null;
27
+ runAt: string | null;
28
+ payload: Record<string, unknown> | null;
29
+ messageTemplate: string | null;
30
+ maxRetries: number;
31
+ retryDelaySeconds: number;
32
+ timeoutSeconds: number;
33
+ name: string;
34
+ description: string | null;
35
+ agentId: string;
36
+ projectId: string;
37
+ tenantId: string;
38
+ id: string;
39
+ }[];
40
+ pagination: {
41
+ page: number;
42
+ limit: number;
43
+ total: number;
44
+ pages: number;
45
+ };
46
+ }>;
47
+ /**
48
+ * Create a new scheduled trigger (agent-scoped)
49
+ */
50
+ declare const createScheduledTrigger: (db: AgentsManageDatabaseClient) => (params: ScheduledTriggerInsert) => Promise<ScheduledTrigger>;
51
+ /**
52
+ * Update a scheduled trigger (agent-scoped)
53
+ */
54
+ declare const updateScheduledTrigger: (db: AgentsManageDatabaseClient) => (params: {
55
+ scopes: AgentScopeConfig;
56
+ scheduledTriggerId: string;
57
+ data: ScheduledTriggerUpdate;
58
+ }) => Promise<ScheduledTrigger>;
59
+ /**
60
+ * Delete a scheduled trigger (agent-scoped)
61
+ */
62
+ declare const deleteScheduledTrigger: (db: AgentsManageDatabaseClient) => (params: {
63
+ scopes: AgentScopeConfig;
64
+ scheduledTriggerId: string;
65
+ }) => Promise<void>;
66
+ /**
67
+ * Upsert a scheduled trigger (create if it doesn't exist, update if it does)
68
+ */
69
+ declare const upsertScheduledTrigger: (db: AgentsManageDatabaseClient) => (params: {
70
+ scopes: AgentScopeConfig;
71
+ data: ScheduledTriggerInsert;
72
+ }) => Promise<ScheduledTrigger>;
73
+ /**
74
+ * List all scheduled triggers for an agent (non-paginated, used by agentFull)
75
+ */
76
+ declare const listScheduledTriggers: (db: AgentsManageDatabaseClient) => (params: {
77
+ scopes: AgentScopeConfig;
78
+ }) => Promise<ScheduledTrigger[]>;
79
+ //#endregion
80
+ export { createScheduledTrigger, deleteScheduledTrigger, getScheduledTriggerById, listScheduledTriggers, listScheduledTriggersPaginated, updateScheduledTrigger, upsertScheduledTrigger };
@@ -0,0 +1,76 @@
1
+ import { scheduledTriggers } from "../../db/manage/manage-schema.js";
2
+ import { and, count, desc, eq } from "drizzle-orm";
3
+
4
+ //#region src/data-access/manage/scheduledTriggers.ts
5
+ /**
6
+ * Get a scheduled trigger by ID (agent-scoped)
7
+ */
8
+ const getScheduledTriggerById = (db) => async (params) => {
9
+ const { scopes, scheduledTriggerId } = params;
10
+ return await db.query.scheduledTriggers.findFirst({ where: and(eq(scheduledTriggers.tenantId, scopes.tenantId), eq(scheduledTriggers.projectId, scopes.projectId), eq(scheduledTriggers.agentId, scopes.agentId), eq(scheduledTriggers.id, scheduledTriggerId)) });
11
+ };
12
+ /**
13
+ * List scheduled triggers for an agent with pagination
14
+ */
15
+ const listScheduledTriggersPaginated = (db) => async (params) => {
16
+ const page = params.pagination?.page || 1;
17
+ const limit = Math.min(params.pagination?.limit || 10, 100);
18
+ const offset = (page - 1) * limit;
19
+ const whereClause = and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId));
20
+ const [data, totalResult] = await Promise.all([db.select().from(scheduledTriggers).where(whereClause).limit(limit).offset(offset).orderBy(desc(scheduledTriggers.createdAt)), db.select({ count: count() }).from(scheduledTriggers).where(whereClause)]);
21
+ const total = totalResult[0]?.count || 0;
22
+ return {
23
+ data,
24
+ pagination: {
25
+ page,
26
+ limit,
27
+ total,
28
+ pages: Math.ceil(total / limit)
29
+ }
30
+ };
31
+ };
32
+ /**
33
+ * Create a new scheduled trigger (agent-scoped)
34
+ */
35
+ const createScheduledTrigger = (db) => async (params) => {
36
+ return (await db.insert(scheduledTriggers).values(params).returning())[0];
37
+ };
38
+ /**
39
+ * Update a scheduled trigger (agent-scoped)
40
+ */
41
+ const updateScheduledTrigger = (db) => async (params) => {
42
+ const updateData = {
43
+ ...params.data,
44
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
45
+ };
46
+ return (await db.update(scheduledTriggers).set(updateData).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId))).returning())[0];
47
+ };
48
+ /**
49
+ * Delete a scheduled trigger (agent-scoped)
50
+ */
51
+ const deleteScheduledTrigger = (db) => async (params) => {
52
+ await db.delete(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId), eq(scheduledTriggers.id, params.scheduledTriggerId)));
53
+ };
54
+ /**
55
+ * Upsert a scheduled trigger (create if it doesn't exist, update if it does)
56
+ */
57
+ const upsertScheduledTrigger = (db) => async (params) => {
58
+ if (await getScheduledTriggerById(db)({
59
+ scopes: params.scopes,
60
+ scheduledTriggerId: params.data.id
61
+ })) return await updateScheduledTrigger(db)({
62
+ scopes: params.scopes,
63
+ scheduledTriggerId: params.data.id,
64
+ data: params.data
65
+ });
66
+ return await createScheduledTrigger(db)(params.data);
67
+ };
68
+ /**
69
+ * List all scheduled triggers for an agent (non-paginated, used by agentFull)
70
+ */
71
+ const listScheduledTriggers = (db) => async (params) => {
72
+ return await db.select().from(scheduledTriggers).where(and(eq(scheduledTriggers.tenantId, params.scopes.tenantId), eq(scheduledTriggers.projectId, params.scopes.projectId), eq(scheduledTriggers.agentId, params.scopes.agentId)));
73
+ };
74
+
75
+ //#endregion
76
+ export { createScheduledTrigger, deleteScheduledTrigger, getScheduledTriggerById, listScheduledTriggers, listScheduledTriggersPaginated, updateScheduledTrigger, upsertScheduledTrigger };
@@ -0,0 +1,29 @@
1
+ import { AgentScopeConfig } from "../../types/utility.js";
2
+ import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
3
+ import { ScheduledWorkflow, ScheduledWorkflowInsert } from "../../validation/schemas.js";
4
+
5
+ //#region src/data-access/manage/scheduledWorkflows.d.ts
6
+
7
+ /**
8
+ * Get a scheduled workflow by trigger ID (agent-scoped)
9
+ */
10
+ declare const getScheduledWorkflowByTriggerId: (db: AgentsManageDatabaseClient) => (params: {
11
+ scopes: AgentScopeConfig;
12
+ scheduledTriggerId: string;
13
+ }) => Promise<ScheduledWorkflow | undefined>;
14
+ /**
15
+ * Create a new scheduled workflow (agent-scoped)
16
+ */
17
+ declare const createScheduledWorkflow: (db: AgentsManageDatabaseClient) => (params: ScheduledWorkflowInsert) => Promise<ScheduledWorkflow>;
18
+ /**
19
+ * Update workflow run ID and/or status for a scheduled workflow
20
+ * Used when a workflow is started/restarted/cancelled
21
+ */
22
+ declare const updateScheduledWorkflowRunId: (db: AgentsManageDatabaseClient) => (params: {
23
+ scopes: AgentScopeConfig;
24
+ scheduledWorkflowId: string;
25
+ workflowRunId: string | null;
26
+ status?: "running" | "completed" | "cancelled" | "failed";
27
+ }) => Promise<ScheduledWorkflow>;
28
+ //#endregion
29
+ export { createScheduledWorkflow, getScheduledWorkflowByTriggerId, updateScheduledWorkflowRunId };
@@ -0,0 +1,32 @@
1
+ import { scheduledWorkflows } from "../../db/manage/manage-schema.js";
2
+ import { and, eq } from "drizzle-orm";
3
+
4
+ //#region src/data-access/manage/scheduledWorkflows.ts
5
+ /**
6
+ * Get a scheduled workflow by trigger ID (agent-scoped)
7
+ */
8
+ const getScheduledWorkflowByTriggerId = (db) => async (params) => {
9
+ const { scopes, scheduledTriggerId } = params;
10
+ return await db.query.scheduledWorkflows.findFirst({ where: and(eq(scheduledWorkflows.tenantId, scopes.tenantId), eq(scheduledWorkflows.projectId, scopes.projectId), eq(scheduledWorkflows.agentId, scopes.agentId), eq(scheduledWorkflows.scheduledTriggerId, scheduledTriggerId)) });
11
+ };
12
+ /**
13
+ * Create a new scheduled workflow (agent-scoped)
14
+ */
15
+ const createScheduledWorkflow = (db) => async (params) => {
16
+ return (await db.insert(scheduledWorkflows).values(params).returning())[0];
17
+ };
18
+ /**
19
+ * Update workflow run ID and/or status for a scheduled workflow
20
+ * Used when a workflow is started/restarted/cancelled
21
+ */
22
+ const updateScheduledWorkflowRunId = (db) => async (params) => {
23
+ const updateData = {
24
+ workflowRunId: params.workflowRunId,
25
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
26
+ };
27
+ if (params.status) updateData.status = params.status;
28
+ return (await db.update(scheduledWorkflows).set(updateData).where(and(eq(scheduledWorkflows.tenantId, params.scopes.tenantId), eq(scheduledWorkflows.projectId, params.scopes.projectId), eq(scheduledWorkflows.agentId, params.scopes.agentId), eq(scheduledWorkflows.id, params.scheduledWorkflowId))).returning())[0];
29
+ };
30
+
31
+ //#endregion
32
+ export { createScheduledWorkflow, getScheduledWorkflowByTriggerId, updateScheduledWorkflowRunId };
@@ -0,0 +1,109 @@
1
+ import { AgentScopeConfig, PaginationConfig, ProjectScopeConfig, SubAgentScopeConfig } from "../../types/utility.js";
2
+ import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
3
+ import { SkillInsert, SkillUpdate, SubAgentSkillWithIndex } from "../../types/entities.js";
4
+
5
+ //#region src/data-access/manage/skills.d.ts
6
+ declare const getSkillById: (db: AgentsManageDatabaseClient) => (params: {
7
+ scopes: ProjectScopeConfig;
8
+ skillId: string;
9
+ }) => Promise<{
10
+ id: string;
11
+ name: string;
12
+ description: string;
13
+ tenantId: string;
14
+ projectId: string;
15
+ createdAt: string;
16
+ updatedAt: string;
17
+ metadata: Record<string, string> | null;
18
+ content: string;
19
+ } | null>;
20
+ declare const listSkills: (db: AgentsManageDatabaseClient) => (params: {
21
+ scopes: ProjectScopeConfig;
22
+ pagination?: PaginationConfig;
23
+ }) => Promise<{
24
+ data: {
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ id: string;
28
+ name: string;
29
+ description: string;
30
+ content: string;
31
+ metadata: Record<string, string> | null;
32
+ projectId: string;
33
+ tenantId: string;
34
+ }[];
35
+ pagination: {
36
+ page: number;
37
+ limit: number;
38
+ total: number;
39
+ pages: number;
40
+ };
41
+ }>;
42
+ declare const createSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
43
+ id: string;
44
+ name: string;
45
+ description: string;
46
+ tenantId: string;
47
+ projectId: string;
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ metadata: Record<string, string> | null;
51
+ content: string;
52
+ }>;
53
+ declare const upsertSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
54
+ id: string;
55
+ name: string;
56
+ description: string;
57
+ tenantId: string;
58
+ projectId: string;
59
+ createdAt: string;
60
+ updatedAt: string;
61
+ metadata: Record<string, string> | null;
62
+ content: string;
63
+ }>;
64
+ declare const updateSkill: (db: AgentsManageDatabaseClient) => (params: {
65
+ scopes: ProjectScopeConfig;
66
+ skillId: string;
67
+ data: SkillUpdate;
68
+ }) => Promise<{
69
+ createdAt: string;
70
+ updatedAt: string;
71
+ id: string;
72
+ name: string;
73
+ description: string;
74
+ content: string;
75
+ metadata: Record<string, string> | null;
76
+ projectId: string;
77
+ tenantId: string;
78
+ }>;
79
+ declare const deleteSkill: (db: AgentsManageDatabaseClient) => (params: {
80
+ scopes: ProjectScopeConfig;
81
+ skillId: string;
82
+ }) => Promise<boolean>;
83
+ declare const getSkillsForSubAgents: (db: AgentsManageDatabaseClient) => (params: {
84
+ scopes: AgentScopeConfig;
85
+ subAgentIds: string[];
86
+ }) => Promise<SubAgentSkillWithIndex[]>;
87
+ declare const upsertSubAgentSkill: (db: AgentsManageDatabaseClient) => (params: {
88
+ scopes: SubAgentScopeConfig;
89
+ skillId: string;
90
+ index: number;
91
+ alwaysLoaded?: boolean;
92
+ }) => Promise<{
93
+ id: string;
94
+ tenantId: string;
95
+ projectId: string;
96
+ agentId: string;
97
+ createdAt: string;
98
+ updatedAt: string;
99
+ index: number;
100
+ alwaysLoaded: boolean;
101
+ subAgentId: string;
102
+ skillId: string;
103
+ }>;
104
+ declare const deleteSubAgentSkill: (db: AgentsManageDatabaseClient) => (params: {
105
+ scopes: AgentScopeConfig;
106
+ subAgentSkillId: string;
107
+ }) => Promise<boolean>;
108
+ //#endregion
109
+ export { createSkill, deleteSkill, deleteSubAgentSkill, getSkillById, getSkillsForSubAgents, listSkills, updateSkill, upsertSkill, upsertSubAgentSkill };
@@ -0,0 +1,122 @@
1
+ import { skills, subAgentSkills } from "../../db/manage/manage-schema.js";
2
+ import { getLogger } from "../../utils/logger.js";
3
+ import { generateId } from "../../utils/conversations.js";
4
+ import "../../index.js";
5
+ import { and, asc, count, desc, eq, inArray } from "drizzle-orm";
6
+
7
+ //#region src/data-access/manage/skills.ts
8
+ const logger = getLogger("skills-dal");
9
+ const getSkillById = (db) => async (params) => {
10
+ return await db.query.skills.findFirst({ where: and(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId)) }) ?? null;
11
+ };
12
+ const listSkills = (db) => async (params) => {
13
+ const page = params.pagination?.page || 1;
14
+ const limit = Math.min(params.pagination?.limit || 10, 100);
15
+ const offset = (page - 1) * limit;
16
+ const whereClause = and(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId));
17
+ const [data, totalResult] = await Promise.all([db.select().from(skills).where(whereClause).limit(limit).offset(offset).orderBy(desc(skills.createdAt)), db.select({ count: count() }).from(skills).where(whereClause)]);
18
+ const total = totalResult[0]?.count || 0;
19
+ return {
20
+ data,
21
+ pagination: {
22
+ page,
23
+ limit,
24
+ total,
25
+ pages: Math.ceil(total / limit)
26
+ }
27
+ };
28
+ };
29
+ const createSkill = (db) => async (data) => {
30
+ const now = (/* @__PURE__ */ new Date()).toISOString();
31
+ const insertData = {
32
+ ...data,
33
+ id: data.name,
34
+ createdAt: now,
35
+ updatedAt: now
36
+ };
37
+ const [result] = await db.insert(skills).values(insertData).returning();
38
+ return result;
39
+ };
40
+ const upsertSkill = (db) => async (data) => {
41
+ const now = (/* @__PURE__ */ new Date()).toISOString();
42
+ const baseData = {
43
+ ...data,
44
+ id: data.name
45
+ };
46
+ if (await db.query.skills.findFirst({ where: and(eq(skills.tenantId, baseData.tenantId), eq(skills.projectId, baseData.projectId), eq(skills.id, baseData.id)) })) {
47
+ const [result$1] = await db.update(skills).set({
48
+ name: baseData.name,
49
+ description: baseData.description,
50
+ content: baseData.content,
51
+ metadata: baseData.metadata,
52
+ updatedAt: now
53
+ }).where(and(eq(skills.tenantId, baseData.tenantId), eq(skills.projectId, baseData.projectId), eq(skills.id, baseData.id))).returning();
54
+ logger.info({ skillId: baseData.id }, "Updated skill");
55
+ return result$1;
56
+ }
57
+ const insertData = {
58
+ ...baseData,
59
+ createdAt: now,
60
+ updatedAt: now
61
+ };
62
+ const [result] = await db.insert(skills).values(insertData).returning();
63
+ logger.info({ skillId: baseData.id }, "Created skill");
64
+ return result;
65
+ };
66
+ const updateSkill = (db) => async (params) => {
67
+ const { tenantId: _, projectId: _2, ...data } = params.data;
68
+ const updateData = {
69
+ ...data,
70
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
71
+ };
72
+ const [result] = await db.update(skills).set(updateData).where(and(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId))).returning();
73
+ return result ?? null;
74
+ };
75
+ const deleteSkill = (db) => async (params) => {
76
+ return (await db.delete(skills).where(and(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId))).returning()).length > 0;
77
+ };
78
+ const getSkillsForSubAgents = (db) => async (params) => {
79
+ if (!params.subAgentIds.length) return [];
80
+ return await db.select({
81
+ subAgentSkillId: subAgentSkills.id,
82
+ subAgentId: subAgentSkills.subAgentId,
83
+ index: subAgentSkills.index,
84
+ alwaysLoaded: subAgentSkills.alwaysLoaded,
85
+ id: skills.id,
86
+ name: skills.name,
87
+ description: skills.description,
88
+ content: skills.content,
89
+ metadata: skills.metadata,
90
+ createdAt: skills.createdAt,
91
+ updatedAt: skills.updatedAt
92
+ }).from(subAgentSkills).innerJoin(skills, and(eq(subAgentSkills.skillId, skills.id), eq(subAgentSkills.tenantId, skills.tenantId), eq(subAgentSkills.projectId, skills.projectId))).where(and(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), inArray(subAgentSkills.subAgentId, params.subAgentIds))).orderBy(asc(subAgentSkills.index), asc(subAgentSkills.createdAt));
93
+ };
94
+ const upsertSubAgentSkill = (db) => async (params) => {
95
+ const now = (/* @__PURE__ */ new Date()).toISOString();
96
+ const existing = await db.query.subAgentSkills.findFirst({ where: and(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), eq(subAgentSkills.subAgentId, params.scopes.subAgentId), eq(subAgentSkills.skillId, params.skillId)) });
97
+ if (existing) {
98
+ const [result$1] = await db.update(subAgentSkills).set({
99
+ index: params.index,
100
+ alwaysLoaded: params.alwaysLoaded ?? existing.alwaysLoaded,
101
+ updatedAt: now
102
+ }).where(eq(subAgentSkills.id, existing.id)).returning();
103
+ return result$1;
104
+ }
105
+ const insertData = {
106
+ ...params.scopes,
107
+ id: generateId(),
108
+ skillId: params.skillId,
109
+ index: params.index,
110
+ alwaysLoaded: params.alwaysLoaded ?? false,
111
+ createdAt: now,
112
+ updatedAt: now
113
+ };
114
+ const [result] = await db.insert(subAgentSkills).values(insertData).returning();
115
+ return result;
116
+ };
117
+ const deleteSubAgentSkill = (db) => async (params) => {
118
+ return (await db.delete(subAgentSkills).where(and(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), eq(subAgentSkills.id, params.subAgentSkillId))).returning()).length > 0;
119
+ };
120
+
121
+ //#endregion
122
+ export { createSkill, deleteSkill, deleteSubAgentSkill, getSkillById, getSkillsForSubAgents, listSkills, updateSkill, upsertSkill, upsertSubAgentSkill };
@@ -14,9 +14,9 @@ declare const getAgentRelationById: (db: AgentsManageDatabaseClient) => (params:
14
14
  agentId: string;
15
15
  createdAt: string;
16
16
  updatedAt: string;
17
+ relationType: string | null;
17
18
  sourceSubAgentId: string;
18
19
  targetSubAgentId: string | null;
19
- relationType: string | null;
20
20
  } | undefined>;
21
21
  declare const listAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
22
22
  scopes: AgentScopeConfig;
@@ -49,9 +49,9 @@ declare const getAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
49
49
  agentId: string;
50
50
  createdAt: string;
51
51
  updatedAt: string;
52
+ relationType: string | null;
52
53
  sourceSubAgentId: string;
53
54
  targetSubAgentId: string | null;
54
- relationType: string | null;
55
55
  }[]>;
56
56
  declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
57
57
  scopes: AgentScopeConfig;
@@ -62,9 +62,9 @@ declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (par
62
62
  agentId: string;
63
63
  createdAt: string;
64
64
  updatedAt: string;
65
+ relationType: string | null;
65
66
  sourceSubAgentId: string;
66
67
  targetSubAgentId: string | null;
67
- relationType: string | null;
68
68
  }[]>;
69
69
  declare const getAgentRelationsBySource: (db: AgentsManageDatabaseClient) => (params: {
70
70
  scopes: AgentScopeConfig;
@@ -131,9 +131,9 @@ declare const createSubAgentRelation: (db: AgentsManageDatabaseClient) => (param
131
131
  agentId: string;
132
132
  createdAt: string;
133
133
  updatedAt: string;
134
+ relationType: string | null;
134
135
  sourceSubAgentId: string;
135
136
  targetSubAgentId: string | null;
136
- relationType: string | null;
137
137
  }>;
138
138
  /**
139
139
  * Check if sub-agent relation exists by agent, source, target, and relation type
@@ -150,9 +150,9 @@ declare const getAgentRelationByParams: (db: AgentsManageDatabaseClient) => (par
150
150
  agentId: string;
151
151
  createdAt: string;
152
152
  updatedAt: string;
153
+ relationType: string | null;
153
154
  sourceSubAgentId: string;
154
155
  targetSubAgentId: string | null;
155
- relationType: string | null;
156
156
  } | undefined>;
157
157
  /**
158
158
  * Upsert agent relation (create if it doesn't exist, no-op if it does)
@@ -164,9 +164,9 @@ declare const upsertSubAgentRelation: (db: AgentsManageDatabaseClient) => (param
164
164
  agentId: string;
165
165
  createdAt: string;
166
166
  updatedAt: string;
167
+ relationType: string | null;
167
168
  sourceSubAgentId: string;
168
169
  targetSubAgentId: string | null;
169
- relationType: string | null;
170
170
  }>;
171
171
  declare const updateAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
172
172
  scopes: AgentScopeConfig;
@@ -51,8 +51,6 @@ declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
51
51
  data: {
52
52
  createdAt: string;
53
53
  updatedAt: string;
54
- name: string;
55
- description: string | null;
56
54
  config: {
57
55
  type: "mcp";
58
56
  mcp: ToolMcpConfig;
@@ -64,6 +62,8 @@ declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
64
62
  capabilities: ToolServerCapabilities | null;
65
63
  lastError: string | null;
66
64
  isWorkApp: boolean;
65
+ name: string;
66
+ description: string | null;
67
67
  projectId: string;
68
68
  tenantId: string;
69
69
  id: string;
@@ -102,8 +102,6 @@ declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
102
102
  }) => Promise<{
103
103
  createdAt: string;
104
104
  updatedAt: string;
105
- name: string;
106
- description: string | null;
107
105
  config: {
108
106
  type: "mcp";
109
107
  mcp: ToolMcpConfig;
@@ -115,6 +113,8 @@ declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
115
113
  capabilities: ToolServerCapabilities | null;
116
114
  lastError: string | null;
117
115
  isWorkApp: boolean;
116
+ name: string;
117
+ description: string | null;
118
118
  projectId: string;
119
119
  tenantId: string;
120
120
  id: string;