@inkeep/agents-core 0.59.3 → 0.60.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 (84) hide show
  1. package/dist/auth/auth-schema.d.ts +108 -108
  2. package/dist/auth/auth-validation-schemas.d.ts +154 -154
  3. package/dist/auth/auth.js +2 -2
  4. package/dist/auth/permissions.d.ts +9 -9
  5. package/dist/client-exports.d.ts +2 -2
  6. package/dist/client-exports.js +2 -2
  7. package/dist/constants/context-breakdown.js +5 -0
  8. package/dist/constants/otel-attributes.d.ts +25 -1
  9. package/dist/constants/otel-attributes.js +25 -1
  10. package/dist/data-access/manage/agentFull.js +5 -5
  11. package/dist/data-access/manage/agents.d.ts +31 -31
  12. package/dist/data-access/manage/artifactComponents.d.ts +14 -14
  13. package/dist/data-access/manage/contextConfigs.d.ts +8 -8
  14. package/dist/data-access/manage/credentialReferences.js +1 -1
  15. package/dist/data-access/manage/dataComponents.d.ts +6 -6
  16. package/dist/data-access/manage/dataComponents.js +1 -1
  17. package/dist/data-access/manage/functionTools.d.ts +14 -14
  18. package/dist/data-access/manage/functionTools.js +2 -2
  19. package/dist/data-access/manage/skills.d.ts +13 -13
  20. package/dist/data-access/manage/skills.js +2 -3
  21. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
  22. package/dist/data-access/manage/subAgentExternalAgentRelations.js +2 -2
  23. package/dist/data-access/manage/subAgentRelations.d.ts +20 -20
  24. package/dist/data-access/manage/subAgentRelations.js +2 -2
  25. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
  26. package/dist/data-access/manage/subAgentTeamAgentRelations.js +2 -2
  27. package/dist/data-access/manage/subAgents.d.ts +21 -21
  28. package/dist/data-access/manage/tools.d.ts +18 -18
  29. package/dist/data-access/manage/tools.js +2 -2
  30. package/dist/data-access/manage/triggers.d.ts +2 -2
  31. package/dist/data-access/runtime/apiKeys.d.ts +16 -16
  32. package/dist/data-access/runtime/apps.d.ts +13 -10
  33. package/dist/data-access/runtime/conversations.d.ts +18 -18
  34. package/dist/data-access/runtime/conversations.js +17 -1
  35. package/dist/data-access/runtime/messages.d.ts +18 -18
  36. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
  37. package/dist/data-access/runtime/tasks.d.ts +4 -4
  38. package/dist/db/manage/manage-schema.d.ts +453 -453
  39. package/dist/db/runtime/runtime-schema.d.ts +353 -334
  40. package/dist/db/runtime/runtime-schema.js +4 -1
  41. package/dist/db/runtime/test-runtime-client.js +1 -1
  42. package/dist/dolt/advisory-lock.d.ts +7 -0
  43. package/dist/dolt/advisory-lock.js +18 -0
  44. package/dist/dolt/branches-api.d.ts +19 -9
  45. package/dist/dolt/branches-api.js +58 -29
  46. package/dist/dolt/fk-map.d.ts +5 -0
  47. package/dist/dolt/fk-map.js +34 -0
  48. package/dist/dolt/index.d.ts +8 -4
  49. package/dist/dolt/index.js +8 -4
  50. package/dist/dolt/merge.d.ts +41 -5
  51. package/dist/dolt/merge.js +161 -24
  52. package/dist/dolt/pk-map.d.ts +6 -0
  53. package/dist/dolt/pk-map.js +27 -0
  54. package/dist/dolt/ref-middleware.d.ts +2 -1
  55. package/dist/dolt/ref-middleware.js +18 -4
  56. package/dist/dolt/resolve-conflicts.d.ts +20 -0
  57. package/dist/dolt/resolve-conflicts.js +158 -0
  58. package/dist/dolt/schema-sync.js +17 -17
  59. package/dist/index.d.ts +14 -8
  60. package/dist/index.js +14 -8
  61. package/dist/types/utility.d.ts +2 -0
  62. package/dist/utils/apiKeys.js +1 -1
  63. package/dist/utils/conversations.d.ts +7 -1
  64. package/dist/utils/conversations.js +10 -1
  65. package/dist/utils/error.d.ts +51 -51
  66. package/dist/utils/index.d.ts +6 -2
  67. package/dist/utils/index.js +5 -3
  68. package/dist/utils/model-factory.js +35 -10
  69. package/dist/utils/token-estimator.d.ts +19 -0
  70. package/dist/utils/token-estimator.js +17 -0
  71. package/dist/utils/usage-cost-middleware.d.ts +13 -0
  72. package/dist/utils/usage-cost-middleware.js +60 -0
  73. package/dist/utils/usage-tracker.d.ts +2 -0
  74. package/dist/utils/usage-tracker.js +1 -0
  75. package/dist/validation/dolt-schemas.d.ts +95 -2
  76. package/dist/validation/dolt-schemas.js +54 -2
  77. package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
  78. package/dist/validation/index.d.ts +2 -2
  79. package/dist/validation/index.js +2 -2
  80. package/dist/validation/schemas.d.ts +2161 -2085
  81. package/drizzle/runtime/0025_faulty_kylun.sql +1 -0
  82. package/drizzle/runtime/meta/0025_snapshot.json +4276 -0
  83. package/drizzle/runtime/meta/_journal.json +7 -0
  84. package/package.json +2 -2
@@ -1,10 +1,12 @@
1
1
  import { __exportAll } from "../../_virtual/rolldown_runtime.js";
2
2
  import { account, deviceCode, invitation, member, organization, session, ssoProvider, user, verification } from "../../auth/auth-schema.js";
3
+ import { USAGE_GENERATION_TYPES } from "../../constants/otel-attributes.js";
3
4
  import { relations } from "drizzle-orm";
4
5
  import { boolean, foreignKey, index, integer, jsonb, pgTable, primaryKey, text, timestamp, unique, uniqueIndex, varchar } from "drizzle-orm/pg-core";
5
6
 
6
7
  //#region src/db/runtime/runtime-schema.ts
7
8
  var runtime_schema_exports = /* @__PURE__ */ __exportAll({
9
+ USAGE_GENERATION_TYPES: () => USAGE_GENERATION_TYPES,
8
10
  account: () => account,
9
11
  apiKeys: () => apiKeys,
10
12
  apps: () => apps,
@@ -150,6 +152,7 @@ const apps = pgTable("apps", {
150
152
  type: varchar("type", { length: 64 }).$type().notNull(),
151
153
  defaultProjectId: varchar("default_project_id", { length: 256 }),
152
154
  defaultAgentId: varchar("default_agent_id", { length: 256 }),
155
+ prompt: text("prompt"),
153
156
  enabled: boolean("enabled").notNull().default(true),
154
157
  config: jsonb("config").$type().notNull(),
155
158
  lastUsedAt: timestamp("last_used_at", { mode: "string" }),
@@ -822,4 +825,4 @@ const workAppSlackMcpToolAccessConfig = pgTable("work_app_slack_mcp_tool_access_
822
825
  ]);
823
826
 
824
827
  //#endregion
825
- export { account, apiKeys, apps, contextCache, conversations, conversationsRelations, datasetRun, datasetRunConversationRelations, deviceCode, evaluationResult, evaluationRun, invitation, ledgerArtifacts, ledgerArtifactsRelations, member, messages, messagesRelations, organization, projectMetadata, runtime_schema_exports, scheduledTriggerInvocations, session, ssoProvider, taskRelations, taskRelationsRelations, tasks, tasksRelations, triggerInvocations, user, userProfile, userProfileRelations, verification, workAppGitHubInstallations, workAppGitHubInstallationsRelations, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubMcpToolRepositoryAccessRelations, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess, workAppGitHubProjectRepositoryAccessRelations, workAppGitHubRepositories, workAppGitHubRepositoriesRelations, workAppSlackChannelAgentConfigs, workAppSlackMcpToolAccessConfig, workAppSlackUserMappings, workAppSlackWorkspaces };
828
+ export { USAGE_GENERATION_TYPES, account, apiKeys, apps, contextCache, conversations, conversationsRelations, datasetRun, datasetRunConversationRelations, deviceCode, evaluationResult, evaluationRun, invitation, ledgerArtifacts, ledgerArtifactsRelations, member, messages, messagesRelations, organization, projectMetadata, runtime_schema_exports, scheduledTriggerInvocations, session, ssoProvider, taskRelations, taskRelationsRelations, tasks, tasksRelations, triggerInvocations, user, userProfile, userProfileRelations, verification, workAppGitHubInstallations, workAppGitHubInstallationsRelations, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubMcpToolRepositoryAccessRelations, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess, workAppGitHubProjectRepositoryAccessRelations, workAppGitHubRepositories, workAppGitHubRepositoriesRelations, workAppSlackChannelAgentConfigs, workAppSlackMcpToolAccessConfig, workAppSlackUserMappings, workAppSlackWorkspaces };
@@ -57,7 +57,7 @@ async function closeTestRuntimeDatabase(db) {
57
57
  * This is a helper for tests that need organization records before creating projects/agents
58
58
  */
59
59
  async function createTestOrganization(db, tenantId) {
60
- const slug = tenantId.replace(/^test-tenant-/, "").substring(0, 50);
60
+ const slug = tenantId.replace(/^test-tenant-/, "");
61
61
  await db.insert(organization).values({
62
62
  id: tenantId,
63
63
  name: `Test Organization ${tenantId}`,
@@ -0,0 +1,7 @@
1
+ import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
2
+
3
+ //#region src/dolt/advisory-lock.d.ts
4
+ declare const tryAdvisoryLock: (db: AgentsManageDatabaseClient) => (prefix: string, identifier: string) => Promise<boolean>;
5
+ declare const releaseAdvisoryLock: (db: AgentsManageDatabaseClient) => (prefix: string, identifier: string) => Promise<void>;
6
+ //#endregion
7
+ export { releaseAdvisoryLock, tryAdvisoryLock };
@@ -0,0 +1,18 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { createHash } from "node:crypto";
3
+
4
+ //#region src/dolt/advisory-lock.ts
5
+ function computeLockKey(prefix, identifier) {
6
+ return createHash("sha256").update(`${prefix}${identifier}`).digest().readBigInt64BE(0);
7
+ }
8
+ const tryAdvisoryLock = (db) => async (prefix, identifier) => {
9
+ const key = computeLockKey(prefix, identifier);
10
+ return (await db.execute(sql`SELECT pg_try_advisory_lock(CAST(${key} AS bigint)) as acquired`)).rows[0]?.acquired === true;
11
+ };
12
+ const releaseAdvisoryLock = (db) => async (prefix, identifier) => {
13
+ const key = computeLockKey(prefix, identifier);
14
+ await db.execute(sql`SELECT pg_advisory_unlock(CAST(${key} AS bigint))`);
15
+ };
16
+
17
+ //#endregion
18
+ export { releaseAdvisoryLock, tryAdvisoryLock };
@@ -5,6 +5,9 @@ import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
5
5
 
6
6
  //#region src/dolt/branches-api.d.ts
7
7
  declare const MAIN_BRANCH_SUFFIX = "main";
8
+ declare class invalidBranchParamsError extends Error {
9
+ constructor(message: string);
10
+ }
8
11
  /**
9
12
  * Get the tenant-scoped main branch name
10
13
  */
@@ -13,24 +16,23 @@ declare const getTenantMainBranch: (tenantId: string) => string;
13
16
  * Check if a branch name (without tenant/project prefix) is a protected branch
14
17
  */
15
18
  declare const isProtectedBranchName: (branchName: string) => boolean;
19
+ declare const getTempBranchSuffix: (prefix: string) => string;
20
+ declare const isTempBranchName: (fullName: string) => boolean;
16
21
  type CreateBranchParams = {
17
22
  tenantId: string;
18
23
  projectId: string;
19
24
  name: string;
20
- /** Branch to create from. Defaults to tenant main branch. */
21
- from?: string;
25
+ /** Branch name to create from. Defaults to tenant main branch. */
26
+ fromBranch?: string;
27
+ /** Commit hash to create from. Mutually exclusive with fromBranch. */
28
+ fromCommit?: string;
22
29
  /**
23
30
  * Whether to sync schema on the source branch before creating.
24
31
  * This ensures the new branch starts with the latest schema from main.
25
- * Default: true
32
+ * Default: true. Ignored when fromCommit is set.
26
33
  */
27
34
  syncSchemaOnSource?: boolean;
28
35
  };
29
- type DeleteBranchParams = {
30
- tenantId: string;
31
- projectId: string;
32
- name: string;
33
- };
34
36
  type GetBranchParams = {
35
37
  tenantId: string;
36
38
  projectId: string;
@@ -79,6 +81,7 @@ type CheckoutBranchResult = {
79
81
  * @returns Function that takes checkout params and returns checkout result
80
82
  */
81
83
  declare const checkoutBranch: (db: AgentsManageDatabaseClient) => (params: CheckoutBranchParams) => Promise<CheckoutBranchResult>;
84
+ declare const syncSchemaOnBranch: (db: AgentsManageDatabaseClient) => (branchName: string) => Promise<void>;
82
85
  /**
83
86
  * Create a new branch with optional schema synchronization.
84
87
  *
@@ -88,8 +91,15 @@ declare const checkoutBranch: (db: AgentsManageDatabaseClient) => (params: Check
88
91
  *
89
92
  * By syncing schema on the source branch first, we ensure the new branch
90
93
  * starts with the latest schema, avoiding schema conflicts later.
94
+ * If you want to create a branch from a commit hash, use the fromCommit parameter.
91
95
  */
92
96
  declare const createBranch: (db: AgentsManageDatabaseClient) => (params: CreateBranchParams) => Promise<BranchInfo>;
97
+ type DeleteBranchParams = {
98
+ tenantId: string;
99
+ projectId: string;
100
+ branchName: string;
101
+ force?: boolean;
102
+ };
93
103
  /**
94
104
  * Delete a branch
95
105
  */
@@ -106,4 +116,4 @@ declare const getBranch: (db: AgentsManageDatabaseClient) => (params: GetBranchP
106
116
  declare const listBranches: (db: AgentsManageDatabaseClient) => (params: ProjectScopeConfig) => Promise<BranchInfo[]>;
107
117
  declare const listBranchesForAgent: (db: AgentsManageDatabaseClient) => (params: AgentScopeConfig) => Promise<BranchInfo[]>;
108
118
  //#endregion
109
- export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent };
119
+ export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTempBranchSuffix, getTenantMainBranch, invalidBranchParamsError, isProtectedBranchName, isTempBranchName, listBranches, listBranchesForAgent, syncSchemaOnBranch };
@@ -1,9 +1,16 @@
1
+ import { doltHashOf } from "./commit.js";
1
2
  import { SCHEMA_SOURCE_BRANCH, ensureSchemaSync, getSchemaDiff, syncSchemaFromMain } from "./schema-sync.js";
2
3
  import { doltBranch, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches } from "./branch.js";
3
4
  import { sql } from "drizzle-orm";
4
5
 
5
6
  //#region src/dolt/branches-api.ts
6
7
  const MAIN_BRANCH_SUFFIX = "main";
8
+ var invalidBranchParamsError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "invalidBranchParamsError";
12
+ }
13
+ };
7
14
  /**
8
15
  * Get the tenant-scoped main branch name
9
16
  */
@@ -14,6 +21,12 @@ const getTenantMainBranch = (tenantId) => `${tenantId}_${MAIN_BRANCH_SUFFIX}`;
14
21
  const isProtectedBranchName = (branchName) => {
15
22
  return branchName === MAIN_BRANCH_SUFFIX;
16
23
  };
24
+ const getTempBranchSuffix = (prefix) => {
25
+ return `temp-${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
26
+ };
27
+ const isTempBranchName = (fullName) => {
28
+ return /temp-[a-z-]+_\d+_[a-z0-9]+$/.test(fullName);
29
+ };
17
30
  /**
18
31
  * Checkout a branch with optional schema synchronization from main.
19
32
  *
@@ -49,6 +62,13 @@ const checkoutBranch = (db) => async (params) => {
49
62
  }
50
63
  };
51
64
  };
65
+ const syncSchemaOnBranch = (db) => async (branchName) => {
66
+ if ((await getSchemaDiff(db)(branchName)).length > 0) {
67
+ await doltCheckout(db)({ branch: branchName });
68
+ const syncResult = await syncSchemaFromMain(db)({ autoCommitPending: true });
69
+ if (syncResult.error && !syncResult.synced) throw new Error(`Failed to sync schema on source branch '${branchName}': ${syncResult.error}`);
70
+ }
71
+ };
52
72
  /**
53
73
  * Create a new branch with optional schema synchronization.
54
74
  *
@@ -58,55 +78,64 @@ const checkoutBranch = (db) => async (params) => {
58
78
  *
59
79
  * By syncing schema on the source branch first, we ensure the new branch
60
80
  * starts with the latest schema, avoiding schema conflicts later.
81
+ * If you want to create a branch from a commit hash, use the fromCommit parameter.
61
82
  */
62
83
  const createBranch = (db) => async (params) => {
63
- const { tenantId, projectId, name, from, syncSchemaOnSource = true } = params;
64
- if (!name || name.trim() === "") throw new Error("Branch name cannot be empty");
84
+ const { tenantId, projectId, name, fromBranch, fromCommit, syncSchemaOnSource = true } = params;
85
+ if (fromBranch && fromCommit) throw new invalidBranchParamsError("Cannot specify both fromBranch and fromCommit");
86
+ if (!name || name.trim() === "") throw new invalidBranchParamsError("Branch name cannot be empty");
65
87
  const fullName = doltGetBranchNamespace({
66
88
  tenantId,
67
89
  projectId,
68
90
  branchName: name
69
91
  })();
70
- if ((await doltListBranches(db)()).some((b) => b.name === fullName)) throw new Error(`Branch '${name}' already exists`);
71
- let fromFullBranchName;
72
- if (from && from !== MAIN_BRANCH_SUFFIX) fromFullBranchName = doltGetBranchNamespace({
73
- tenantId,
74
- projectId,
75
- branchName: from
76
- })();
77
- else fromFullBranchName = getTenantMainBranch(tenantId);
78
- if (syncSchemaOnSource && fromFullBranchName !== SCHEMA_SOURCE_BRANCH) {
79
- if ((await getSchemaDiff(db)(fromFullBranchName)).length > 0) {
80
- await doltCheckout(db)({ branch: fromFullBranchName });
81
- const syncResult = await syncSchemaFromMain(db)({ autoCommitPending: true });
82
- if (syncResult.error && !syncResult.synced) throw new Error(`Failed to sync schema on source branch '${fromFullBranchName}': ${syncResult.error}`);
83
- }
92
+ if ((await doltListBranches(db)()).some((b) => b.name === fullName)) throw new invalidBranchParamsError(`Branch '${name}' already exists`);
93
+ if (fromCommit) {
94
+ await doltBranch(db)({
95
+ name: fullName,
96
+ startPoint: fromCommit
97
+ });
98
+ if (syncSchemaOnSource) await syncSchemaOnBranch(db)(fullName);
99
+ } else {
100
+ let fromFullBranchName;
101
+ if (fromBranch) fromFullBranchName = doltGetBranchNamespace({
102
+ tenantId,
103
+ projectId,
104
+ branchName: fromBranch
105
+ })();
106
+ else fromFullBranchName = doltGetBranchNamespace({
107
+ tenantId,
108
+ projectId,
109
+ branchName: MAIN_BRANCH_SUFFIX
110
+ })();
111
+ if (syncSchemaOnSource && fromFullBranchName !== SCHEMA_SOURCE_BRANCH) await syncSchemaOnBranch(db)(fromFullBranchName);
112
+ await doltBranch(db)({
113
+ name: fullName,
114
+ startPoint: fromFullBranchName
115
+ });
84
116
  }
85
- await doltBranch(db)({
86
- name: fullName,
87
- startPoint: fromFullBranchName
88
- });
89
- const newBranch = (await doltListBranches(db)()).find((b) => b.name === fullName);
90
- if (!newBranch) throw new Error("Failed to create branch");
91
117
  return {
92
118
  baseName: name,
93
119
  fullName,
94
- hash: newBranch.hash
120
+ hash: await doltHashOf(db)({ revision: fullName })
95
121
  };
96
122
  };
97
123
  /**
98
124
  * Delete a branch
99
125
  */
100
126
  const deleteBranch = (db) => async (params) => {
101
- const { tenantId, projectId, name } = params;
102
- if (isProtectedBranchName(name)) throw new Error(`Cannot delete protected branch '${name}'`);
127
+ const { tenantId, projectId, branchName, force } = params;
128
+ if (isProtectedBranchName(branchName)) throw new invalidBranchParamsError(`Cannot delete protected branch '${branchName}'`);
103
129
  const fullName = doltGetBranchNamespace({
104
130
  tenantId,
105
131
  projectId,
106
- branchName: name
132
+ branchName
107
133
  })();
108
- if (!(await doltListBranches(db)()).some((b) => b.name === fullName)) throw new Error(`Branch '${name}' not found`);
109
- await doltDeleteBranch(db)({ name: fullName });
134
+ if (!(await doltListBranches(db)()).some((b) => b.name === fullName)) throw new invalidBranchParamsError(`Branch '${branchName}' not found`);
135
+ await doltDeleteBranch(db)({
136
+ name: fullName,
137
+ force
138
+ });
110
139
  };
111
140
  /**
112
141
  * Get a single branch
@@ -159,4 +188,4 @@ const listBranchesForAgent = (db) => async (params) => {
159
188
  };
160
189
 
161
190
  //#endregion
162
- export { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent };
191
+ export { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTempBranchSuffix, getTenantMainBranch, invalidBranchParamsError, isProtectedBranchName, isTempBranchName, listBranches, listBranchesForAgent, syncSchemaOnBranch };
@@ -0,0 +1,5 @@
1
+ //#region src/dolt/fk-map.d.ts
2
+ type FkDeps = Record<string, string[]>;
3
+ declare const manageFkDeps: FkDeps;
4
+ //#endregion
5
+ export { FkDeps, manageFkDeps };
@@ -0,0 +1,34 @@
1
+ import { manage_schema_exports } from "../db/manage/manage-schema.js";
2
+ import { getTableConfig } from "drizzle-orm/pg-core";
3
+
4
+ //#region src/dolt/fk-map.ts
5
+ function buildFkDepsFromSchema() {
6
+ const deps = {};
7
+ for (const value of Object.values(manage_schema_exports)) {
8
+ if (value == null || typeof value !== "object") continue;
9
+ let config;
10
+ try {
11
+ config = getTableConfig(value);
12
+ } catch {
13
+ continue;
14
+ }
15
+ if (!config?.name) continue;
16
+ const tableDeps = /* @__PURE__ */ new Set();
17
+ for (const fk of config.foreignKeys ?? []) {
18
+ const ref = fk.reference();
19
+ let refName;
20
+ try {
21
+ refName = getTableConfig(ref.foreignTable).name;
22
+ } catch {
23
+ continue;
24
+ }
25
+ if (refName && refName !== config.name) tableDeps.add(refName);
26
+ }
27
+ if (tableDeps.size > 0) deps[config.name] = [...tableDeps];
28
+ }
29
+ return deps;
30
+ }
31
+ const manageFkDeps = buildFkDepsFromSchema();
32
+
33
+ //#endregion
34
+ export { manageFkDeps };
@@ -1,10 +1,14 @@
1
+ import { releaseAdvisoryLock, tryAdvisoryLock } from "./advisory-lock.js";
1
2
  import { branchScopes, doltActiveBranch, doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches, doltRenameBranch, ensureBranchExists } from "./branch.js";
2
- import { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent } from "./branches-api.js";
3
+ import { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTempBranchSuffix, getTenantMainBranch, invalidBranchParamsError, isProtectedBranchName, isTempBranchName, listBranches, listBranchesForAgent, syncSchemaOnBranch } from "./branches-api.js";
3
4
  import { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag } from "./commit.js";
4
5
  import { doltDiff, doltDiffSummary } from "./diff.js";
5
- import { doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
6
+ import { FkDeps, manageFkDeps } from "./fk-map.js";
7
+ import { MergeConflictError, doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltPreviewMergeConflicts, doltPreviewMergeConflictsSummary, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
8
+ import { PkMap, isValidManageTable, managePkMap } from "./pk-map.js";
6
9
  import { RefType, checkoutRef, getCurrentBranchOrCommit, getProjectMainResolvedRef, getProjectScopedRef, getTenantScopedRef, isRefWritable, isValidCommitHash, resolveProjectMainRefs, resolveRef } from "./ref-helpers.js";
7
- import { RefContext, RefMiddlewareOptions, createRefMiddleware, createWriteProtectionMiddleware, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
10
+ import { RefContext, RefMiddlewareOptions, createRefMiddleware, createWriteProtectionMiddleware, isMergeRoute, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
8
11
  import { NestedRefScopeError, WithRefOptions, getCurrentRefScope, getRefScopedDb, isInRefScope, withRef } from "./ref-scope.js";
12
+ import { ResolutionValidationError, applyResolutions, computeTableInsertOrder, sortByFkDependencyOrder } from "./resolve-conflicts.js";
9
13
  import { EnsureSchemaSyncOptions, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, isLocalhostUrl, syncSchemaFromMain } from "./schema-sync.js";
10
- export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, EnsureSchemaSyncOptions, GetBranchParams, MAIN_BRANCH_SUFFIX, NestedRefScopeError, RefContext, RefMiddlewareOptions, RefType, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, WithRefOptions, areBranchesSchemaCompatible, branchScopes, checkoutBranch, checkoutRef, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, isInRefScope, isLocalhostUrl, isProtectedBranchName, isRefWritable, isValidCommitHash, listBranches, listBranchesForAgent, refMiddlewareFactory, resolveProjectMainRefs, resolveRef, syncSchemaFromMain, withRef, writeProtectionMiddlewareFactory };
14
+ export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, EnsureSchemaSyncOptions, FkDeps, GetBranchParams, MAIN_BRANCH_SUFFIX, MergeConflictError, NestedRefScopeError, PkMap, RefContext, RefMiddlewareOptions, RefType, ResolutionValidationError, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, WithRefOptions, applyResolutions, areBranchesSchemaCompatible, branchScopes, checkoutBranch, checkoutRef, computeTableInsertOrder, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltPreviewMergeConflicts, doltPreviewMergeConflictsSummary, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTempBranchSuffix, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, invalidBranchParamsError, isInRefScope, isLocalhostUrl, isMergeRoute, isProtectedBranchName, isRefWritable, isTempBranchName, isValidCommitHash, isValidManageTable, listBranches, listBranchesForAgent, manageFkDeps, managePkMap, refMiddlewareFactory, releaseAdvisoryLock, resolveProjectMainRefs, resolveRef, sortByFkDependencyOrder, syncSchemaFromMain, syncSchemaOnBranch, tryAdvisoryLock, withRef, writeProtectionMiddlewareFactory };
@@ -1,11 +1,15 @@
1
1
  import { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag } from "./commit.js";
2
- import { doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
2
+ import { isValidManageTable, managePkMap } from "./pk-map.js";
3
+ import { manageFkDeps } from "./fk-map.js";
4
+ import { ResolutionValidationError, applyResolutions, computeTableInsertOrder, sortByFkDependencyOrder } from "./resolve-conflicts.js";
5
+ import { MergeConflictError, doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltPreviewMergeConflicts, doltPreviewMergeConflictsSummary, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
3
6
  import { SCHEMA_SOURCE_BRANCH, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, isLocalhostUrl, syncSchemaFromMain } from "./schema-sync.js";
4
- import { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent } from "./branches-api.js";
7
+ import { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTempBranchSuffix, getTenantMainBranch, invalidBranchParamsError, isProtectedBranchName, isTempBranchName, listBranches, listBranchesForAgent, syncSchemaOnBranch } from "./branches-api.js";
5
8
  import { checkoutRef, getCurrentBranchOrCommit, getProjectMainResolvedRef, getProjectScopedRef, getTenantScopedRef, isRefWritable, isValidCommitHash, resolveProjectMainRefs, resolveRef } from "./ref-helpers.js";
6
9
  import { doltActiveBranch, doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches, doltRenameBranch, ensureBranchExists } from "./branch.js";
10
+ import { releaseAdvisoryLock, tryAdvisoryLock } from "./advisory-lock.js";
7
11
  import { doltDiff, doltDiffSummary } from "./diff.js";
8
- import { createRefMiddleware, createWriteProtectionMiddleware, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
12
+ import { createRefMiddleware, createWriteProtectionMiddleware, isMergeRoute, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
9
13
  import { NestedRefScopeError, getCurrentRefScope, getRefScopedDb, isInRefScope, withRef } from "./ref-scope.js";
10
14
 
11
- export { MAIN_BRANCH_SUFFIX, NestedRefScopeError, SCHEMA_SOURCE_BRANCH, areBranchesSchemaCompatible, checkoutBranch, checkoutRef, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, isInRefScope, isLocalhostUrl, isProtectedBranchName, isRefWritable, isValidCommitHash, listBranches, listBranchesForAgent, refMiddlewareFactory, resolveProjectMainRefs, resolveRef, syncSchemaFromMain, withRef, writeProtectionMiddlewareFactory };
15
+ export { MAIN_BRANCH_SUFFIX, MergeConflictError, NestedRefScopeError, ResolutionValidationError, SCHEMA_SOURCE_BRANCH, applyResolutions, areBranchesSchemaCompatible, checkoutBranch, checkoutRef, computeTableInsertOrder, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltPreviewMergeConflicts, doltPreviewMergeConflictsSummary, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTempBranchSuffix, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, invalidBranchParamsError, isInRefScope, isLocalhostUrl, isMergeRoute, isProtectedBranchName, isRefWritable, isTempBranchName, isValidCommitHash, isValidManageTable, listBranches, listBranchesForAgent, manageFkDeps, managePkMap, refMiddlewareFactory, releaseAdvisoryLock, resolveProjectMainRefs, resolveRef, sortByFkDependencyOrder, syncSchemaFromMain, syncSchemaOnBranch, tryAdvisoryLock, withRef, writeProtectionMiddlewareFactory };
@@ -1,10 +1,24 @@
1
+ import { ConflictResolution } from "../validation/dolt-schemas.js";
1
2
  import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
2
3
 
3
4
  //#region src/dolt/merge.d.ts
4
-
5
+ declare class MergeConflictError extends Error {
6
+ readonly conflictCount: number;
7
+ readonly fromBranch: string;
8
+ readonly toBranch: string;
9
+ constructor(message: string, conflictCount: number, fromBranch: string, toBranch: string);
10
+ }
5
11
  /**
6
- * Merge another branch into the current branch
7
- * Returns merge status and handles conflicts by allowing commit with conflicts
12
+ * Merge a branch into the currently checked out branch.
13
+ *
14
+ * Runs inside an explicit transaction so that conflicts and
15
+ * constraint-violations are surfaced to the caller instead of being
16
+ * auto-rolled-back by Dolt's AUTOCOMMIT mode.
17
+ *
18
+ * If conflicts arise and `resolutions` are provided, they are applied
19
+ * and the merge is committed. If conflicts arise without resolutions
20
+ * (or with insufficient resolutions), the transaction is rolled back
21
+ * and a `MergeConflictError` is thrown.
8
22
  */
9
23
  declare const doltMerge: (db: AgentsManageDatabaseClient) => (params: {
10
24
  fromBranch: string;
@@ -15,8 +29,9 @@ declare const doltMerge: (db: AgentsManageDatabaseClient) => (params: {
15
29
  name: string;
16
30
  email: string;
17
31
  };
32
+ resolutions?: ConflictResolution[];
18
33
  }) => Promise<{
19
- status: "success" | "conflicts";
34
+ status: "success";
20
35
  from: string;
21
36
  to: string;
22
37
  toHead?: string;
@@ -52,6 +67,27 @@ declare const doltTableConflicts: (db: AgentsManageDatabaseClient) => (params: {
52
67
  * Get schema conflicts
53
68
  */
54
69
  declare const doltSchemaConflicts: (db: AgentsManageDatabaseClient) => () => Promise<any[]>;
70
+ /**
71
+ * Preview merge conflicts without modifying the database (dry-run).
72
+ * Returns a summary of which tables have conflicts.
73
+ */
74
+ declare const doltPreviewMergeConflictsSummary: (db: AgentsManageDatabaseClient) => (params: {
75
+ baseBranch: string;
76
+ mergeBranch: string;
77
+ }) => Promise<{
78
+ table: string;
79
+ numDataConflicts: number;
80
+ numSchemaConflicts: number;
81
+ }[]>;
82
+ /**
83
+ * Preview detailed merge conflicts for a specific table without modifying the database (dry-run).
84
+ * Returns the same column shape as dolt_conflicts_$table.
85
+ */
86
+ declare const doltPreviewMergeConflicts: (db: AgentsManageDatabaseClient) => (params: {
87
+ baseBranch: string;
88
+ mergeBranch: string;
89
+ tableName: string;
90
+ }) => Promise<Record<string, unknown>[]>;
55
91
  /**
56
92
  * Resolve conflicts for a table using a strategy
57
93
  */
@@ -60,4 +96,4 @@ declare const doltResolveConflicts: (db: AgentsManageDatabaseClient) => (params:
60
96
  strategy: "ours" | "theirs";
61
97
  }) => Promise<void>;
62
98
  //#endregion
63
- export { doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts };
99
+ export { MergeConflictError, doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltPreviewMergeConflicts, doltPreviewMergeConflictsSummary, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts };