@inkeep/agents-core 0.41.2 → 0.42.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.
- package/dist/api-client/base-client.d.ts +87 -8
- package/dist/api-client/base-client.js +174 -1
- package/dist/api-client/eval-api-client.d.ts +47 -0
- package/dist/api-client/eval-api-client.js +65 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/index.js +5 -0
- package/dist/api-client/manage-api-client.d.ts +34 -0
- package/dist/api-client/manage-api-client.js +104 -0
- package/dist/auth/auth.d.ts +86 -20
- package/dist/auth/auth.js +55 -1
- package/dist/auth/authz/client.d.ts +81 -0
- package/dist/auth/authz/client.js +189 -0
- package/dist/auth/authz/config.d.ts +76 -0
- package/dist/auth/authz/config.js +76 -0
- package/dist/auth/authz/index.d.ts +5 -0
- package/dist/auth/authz/index.js +6 -0
- package/dist/auth/authz/permissions.d.ts +57 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +85 -0
- package/dist/auth/authz/sync.js +237 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +8 -3
- package/dist/client-exports.js +3 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/otel-attributes.d.ts +4 -0
- package/dist/constants/otel-attributes.js +4 -0
- package/dist/context/ContextConfig.d.ts +2 -2
- package/dist/context/ContextConfig.js +3 -3
- package/dist/context/TemplateEngine.js +0 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
- package/dist/data-access/index.d.ts +34 -26
- package/dist/data-access/index.js +34 -26
- package/dist/data-access/manage/agentFull.d.ts +36 -0
- package/dist/data-access/{agentFull.js → manage/agentFull.js} +205 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
- package/dist/data-access/{agents.js → manage/agents.js} +52 -7
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
- package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
- package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
- package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
- package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +20 -20
- package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
- package/dist/data-access/manage/evalConfig.d.ts +221 -0
- package/dist/data-access/manage/evalConfig.js +275 -0
- package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
- package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
- package/dist/data-access/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
- package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
- package/dist/data-access/{functions.js → manage/functions.js} +3 -3
- package/dist/data-access/manage/projectFull.d.ts +38 -0
- package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
- package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
- package/dist/data-access/manage/projectLifecycle.js +234 -0
- package/dist/data-access/manage/projects.d.ts +75 -0
- package/dist/data-access/{projects.js → manage/projects.js} +15 -16
- package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
- package/dist/data-access/{tools.js → manage/tools.js} +57 -35
- package/dist/data-access/manage/triggers.d.ts +80 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
- package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
- package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
- package/dist/data-access/runtime/cascade-delete.js +111 -0
- package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
- package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
- package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +68 -19
- package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
- package/dist/data-access/runtime/evalRuns.d.ts +120 -0
- package/dist/data-access/runtime/evalRuns.js +168 -0
- package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
- package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
- package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +15 -15
- package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
- package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
- package/dist/data-access/{organizations.js → runtime/organizations.js} +15 -3
- package/dist/data-access/runtime/projects.d.ts +62 -0
- package/dist/data-access/runtime/projects.js +90 -0
- package/dist/data-access/runtime/tasks.d.ts +55 -0
- package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/data-access/runtime/users.d.ts +19 -0
- package/dist/data-access/{users.js → runtime/users.js} +2 -2
- package/dist/data-access/validation.d.ts +4 -4
- package/dist/data-access/validation.js +1 -1
- package/dist/db/clean.d.ts +8 -4
- package/dist/db/clean.js +14 -105
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +7 -10
- package/dist/db/manage/dolt-cleanup.d.ts +51 -0
- package/dist/db/manage/dolt-cleanup.js +132 -0
- package/dist/db/manage/manage-client.d.ts +26 -0
- package/dist/db/manage/manage-client.js +68 -0
- package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1459 -1285
- package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
- package/dist/db/manage/test-manage-client.d.ts +27 -0
- package/dist/db/manage/test-manage-client.js +68 -0
- package/dist/db/runtime/runtime-client.d.ts +20 -0
- package/dist/db/runtime/runtime-client.js +30 -0
- package/dist/db/runtime/runtime-schema.d.ts +2834 -0
- package/dist/db/runtime/runtime-schema.js +483 -0
- package/dist/db/runtime/test-runtime-client.d.ts +27 -0
- package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
- package/dist/dolt/branch.d.ts +62 -0
- package/dist/dolt/branch.js +82 -0
- package/dist/dolt/branches-api.d.ts +108 -0
- package/dist/dolt/branches-api.js +162 -0
- package/dist/dolt/commit.d.ts +94 -0
- package/dist/dolt/commit.js +103 -0
- package/dist/dolt/diff.d.ts +27 -0
- package/dist/dolt/diff.js +21 -0
- package/dist/dolt/index.d.ts +10 -0
- package/dist/dolt/index.js +11 -0
- package/dist/dolt/merge.d.ts +63 -0
- package/dist/dolt/merge.js +81 -0
- package/dist/dolt/migrate-all-branches.d.ts +4 -0
- package/dist/dolt/migrate-all-branches.js +78 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +22 -0
- package/dist/dolt/ref-helpers.d.ts +19 -0
- package/dist/dolt/ref-helpers.js +65 -0
- package/dist/dolt/ref-middleware.d.ts +82 -0
- package/dist/dolt/ref-middleware.js +217 -0
- package/dist/dolt/ref-scope.d.ts +101 -0
- package/dist/dolt/ref-scope.js +231 -0
- package/dist/dolt/schema-sync.d.ts +134 -0
- package/dist/dolt/schema-sync.js +246 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +71 -44
- package/dist/index.js +74 -47
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +45 -4
- package/dist/utils/JsonTransformer.d.ts +44 -0
- package/dist/utils/JsonTransformer.js +112 -0
- package/dist/utils/apiKeys.d.ts +5 -1
- package/dist/utils/apiKeys.js +11 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/utils/credential-store-utils.d.ts +1 -1
- package/dist/utils/format-messages.d.ts +1 -1
- package/dist/utils/index.d.ts +7 -3
- package/dist/utils/index.js +7 -3
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/third-party-mcp-servers/composio-client.js +23 -23
- package/dist/utils/trigger-auth.d.ts +62 -0
- package/dist/utils/trigger-auth.js +125 -0
- package/dist/validation/agentFull.js +2 -4
- package/dist/validation/dolt-schemas.d.ts +49 -0
- package/dist/validation/dolt-schemas.js +44 -0
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
- package/dist/validation/drizzle-schema-helpers.js +5 -151
- package/dist/validation/index.d.ts +4 -3
- package/dist/validation/index.js +3 -2
- package/dist/validation/schemas.d.ts +17647 -4789
- package/dist/validation/schemas.js +328 -11
- package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/0002_bent_sunfire.sql +1 -0
- package/drizzle/manage/meta/0000_snapshot.json +2987 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/0002_snapshot.json +3115 -0
- package/drizzle/manage/meta/_journal.json +27 -0
- package/drizzle/runtime/0008_silly_preak.sql +127 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
- package/package.json +48 -15
- package/dist/context/ContextFetcher.d.ts +0 -73
- package/dist/context/ContextFetcher.js +0 -291
- package/dist/context/ContextResolver.d.ts +0 -60
- package/dist/context/ContextResolver.js +0 -278
- package/dist/context/context.d.ts +0 -27
- package/dist/context/context.js +0 -128
- package/dist/context/contextCache.d.ts +0 -58
- package/dist/context/contextCache.js +0 -177
- package/dist/data-access/agentFull.d.ts +0 -33
- package/dist/data-access/projectFull.d.ts +0 -32
- package/dist/data-access/projects.d.ts +0 -71
- package/dist/data-access/tasks.d.ts +0 -45
- package/dist/data-access/users.d.ts +0 -19
- package/dist/db/client.d.ts +0 -20
- package/dist/db/client.js +0 -28
- package/dist/db/test-client.d.ts +0 -31
- package/dist/middleware/contextValidation.d.ts +0 -46
- package/dist/middleware/contextValidation.js +0 -280
- package/dist/middleware/index.d.ts +0 -2
- package/dist/middleware/index.js +0 -3
- package/dist/utils/execution.d.ts +0 -22
- package/dist/utils/execution.js +0 -25
- /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
- /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
- /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
- /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
- /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
- /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
- /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
- /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
- /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { doltAddAndCommit, doltStatus } from "./commit.js";
|
|
2
|
+
import { doltAbortMerge, doltMerge } from "./merge.js";
|
|
3
|
+
import { sql } from "drizzle-orm";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
//#region src/dolt/schema-sync.ts
|
|
7
|
+
/**
|
|
8
|
+
* The branch that serves as the source of truth for schema.
|
|
9
|
+
* All other branches sync their schema from this branch.
|
|
10
|
+
*/
|
|
11
|
+
const SCHEMA_SOURCE_BRANCH = "main";
|
|
12
|
+
/**
|
|
13
|
+
* Get the currently active branch
|
|
14
|
+
*/
|
|
15
|
+
const getActiveBranch = (db) => async () => {
|
|
16
|
+
return (await db.execute(sql`SELECT active_branch() as branch`)).rows[0]?.branch;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get schema differences between the schema source branch and a target branch.
|
|
20
|
+
* Returns an empty array if schemas are identical.
|
|
21
|
+
*
|
|
22
|
+
* The comparison is done as dolt_schema_diff(targetBranch, SCHEMA_SOURCE_BRANCH),
|
|
23
|
+
* so fromCreateStatement shows the target branch's schema and toCreateStatement
|
|
24
|
+
* shows main's schema (what we want to sync to).
|
|
25
|
+
*
|
|
26
|
+
* @param targetBranch - The branch to compare against the schema source
|
|
27
|
+
* @returns Array of schema differences (one per table that differs)
|
|
28
|
+
*/
|
|
29
|
+
const getSchemaDiff = (db) => async (targetBranch) => {
|
|
30
|
+
return (await db.execute(sql.raw(`SELECT * FROM dolt_schema_diff('${targetBranch}', '${SCHEMA_SOURCE_BRANCH}')`))).rows.map((row) => ({
|
|
31
|
+
fromTableName: row.from_table_name,
|
|
32
|
+
toTableName: row.to_table_name,
|
|
33
|
+
fromCreateStatement: row.from_create_statement,
|
|
34
|
+
toCreateStatement: row.to_create_statement
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Check if a branch has schema differences from the schema source branch
|
|
39
|
+
*/
|
|
40
|
+
const hasSchemaDifferences = (db) => async (targetBranch) => {
|
|
41
|
+
return (await getSchemaDiff(db)(targetBranch)).length > 0;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Check if the current branch has uncommitted changes
|
|
45
|
+
*/
|
|
46
|
+
const hasUncommittedChanges = (db) => async () => {
|
|
47
|
+
return (await doltStatus(db)()).length > 0;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Commit any pending changes on the current branch
|
|
51
|
+
*/
|
|
52
|
+
const commitPendingChanges = (db) => async (options) => {
|
|
53
|
+
const message = options.message ?? "Auto-commit pending changes before schema sync";
|
|
54
|
+
await doltAddAndCommit(db)({
|
|
55
|
+
message,
|
|
56
|
+
author: options.author
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Advisory lock key prefix for schema sync operations.
|
|
61
|
+
* We use a fixed prefix combined with the branch name hash to create unique lock keys.
|
|
62
|
+
*/
|
|
63
|
+
const SCHEMA_SYNC_LOCK_PREFIX = "schema_sync_";
|
|
64
|
+
const getSchemaSyncLockKey = (branchName) => {
|
|
65
|
+
const lockKey = `${SCHEMA_SYNC_LOCK_PREFIX}${branchName}`;
|
|
66
|
+
return createHash("sha256").update(lockKey).digest().readBigInt64BE(0);
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Try to acquire a non-blocking advisory lock for schema sync on a branch.
|
|
70
|
+
* Uses pg_try_advisory_lock which returns immediately without waiting.
|
|
71
|
+
*
|
|
72
|
+
* @param branchName - The branch name to lock
|
|
73
|
+
* @returns true if lock was acquired, false if another session holds it
|
|
74
|
+
*/
|
|
75
|
+
const tryAcquireSchemaSyncLock = (db) => async (branchName) => {
|
|
76
|
+
const key = getSchemaSyncLockKey(branchName);
|
|
77
|
+
return (await db.execute(sql`SELECT pg_try_advisory_lock(CAST(${key} AS bigint)) as acquired`)).rows[0]?.acquired === true;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Release the advisory lock for schema sync on a branch.
|
|
81
|
+
*
|
|
82
|
+
* @param branchName - The branch name to unlock
|
|
83
|
+
*/
|
|
84
|
+
const releaseSchemaSyncLock = (db) => async (branchName) => {
|
|
85
|
+
const key = getSchemaSyncLockKey(branchName);
|
|
86
|
+
await db.execute(sql`SELECT pg_advisory_unlock(CAST(${key} AS bigint))`);
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Get the latest commit hash for the current branch
|
|
90
|
+
*/
|
|
91
|
+
const getLatestCommitHash = (db) => async () => {
|
|
92
|
+
return (await db.execute(sql`SELECT commit_hash FROM dolt_log LIMIT 1`)).rows[0]?.commit_hash;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Sync schema from the schema source branch (main) into the current branch.
|
|
96
|
+
* This performs a merge of the schema source branch into the current branch.
|
|
97
|
+
*
|
|
98
|
+
* Uses a non-blocking advisory lock to prevent duplicate syncs when multiple
|
|
99
|
+
* concurrent requests attempt to sync the same branch. If another request is
|
|
100
|
+
* already syncing, this function returns immediately with skippedDueToLock: true.
|
|
101
|
+
*
|
|
102
|
+
* Prerequisites:
|
|
103
|
+
* - Current branch must not have uncommitted changes (unless autoCommitPending is true)
|
|
104
|
+
* - Current branch must not be the schema source branch itself
|
|
105
|
+
*
|
|
106
|
+
* @param options - Sync options
|
|
107
|
+
* @returns Result of the sync operation
|
|
108
|
+
*/
|
|
109
|
+
const syncSchemaFromMain = (db) => async (options = {}) => {
|
|
110
|
+
const currentBranch = await getActiveBranch(db)();
|
|
111
|
+
if (currentBranch === SCHEMA_SOURCE_BRANCH) return {
|
|
112
|
+
synced: true,
|
|
113
|
+
hadDifferences: false,
|
|
114
|
+
error: "Cannot sync schema: already on schema source branch"
|
|
115
|
+
};
|
|
116
|
+
if (!await tryAcquireSchemaSyncLock(db)(currentBranch)) return {
|
|
117
|
+
synced: false,
|
|
118
|
+
hadDifferences: true,
|
|
119
|
+
skippedDueToLock: true
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
const differences = await getSchemaDiff(db)(currentBranch);
|
|
123
|
+
if (differences.length === 0) return {
|
|
124
|
+
synced: false,
|
|
125
|
+
hadDifferences: false
|
|
126
|
+
};
|
|
127
|
+
if (await hasUncommittedChanges(db)()) if (options.autoCommitPending) await commitPendingChanges(db)({
|
|
128
|
+
message: "Auto-commit pending changes before schema sync",
|
|
129
|
+
author: options.author
|
|
130
|
+
});
|
|
131
|
+
else return {
|
|
132
|
+
synced: false,
|
|
133
|
+
hadDifferences: true,
|
|
134
|
+
differences,
|
|
135
|
+
error: "Cannot sync schema: uncommitted changes exist. Commit changes first or set autoCommitPending: true"
|
|
136
|
+
};
|
|
137
|
+
const mergeSchemaMessage = `Synced schema from ${SCHEMA_SOURCE_BRANCH}`;
|
|
138
|
+
if ((await doltMerge(db)({
|
|
139
|
+
fromBranch: SCHEMA_SOURCE_BRANCH,
|
|
140
|
+
toBranch: currentBranch,
|
|
141
|
+
message: mergeSchemaMessage,
|
|
142
|
+
noFastForward: true,
|
|
143
|
+
author: {
|
|
144
|
+
name: "Schema Sync System",
|
|
145
|
+
email: "system@inkeep.com"
|
|
146
|
+
}
|
|
147
|
+
})).status === "conflicts") {
|
|
148
|
+
await doltAbortMerge(db)();
|
|
149
|
+
return {
|
|
150
|
+
synced: false,
|
|
151
|
+
hadDifferences: true,
|
|
152
|
+
differences,
|
|
153
|
+
error: "Schema merge produced conflicts that require manual resolution. Merge has been aborted."
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
synced: true,
|
|
158
|
+
hadDifferences: true,
|
|
159
|
+
differences,
|
|
160
|
+
mergeCommitHash: await getLatestCommitHash(db)()
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
try {
|
|
164
|
+
await doltAbortMerge(db)();
|
|
165
|
+
} catch {}
|
|
166
|
+
return {
|
|
167
|
+
synced: false,
|
|
168
|
+
hadDifferences: true,
|
|
169
|
+
error: `Schema sync failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
170
|
+
};
|
|
171
|
+
} finally {
|
|
172
|
+
try {
|
|
173
|
+
await releaseSchemaSyncLock(db)(currentBranch);
|
|
174
|
+
} catch {}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Ensure the current branch has schema in sync with the schema source branch.
|
|
179
|
+
* This is a convenience function for checking and optionally syncing schema.
|
|
180
|
+
*
|
|
181
|
+
* Use cases:
|
|
182
|
+
* - Call before write operations to ensure schema compatibility
|
|
183
|
+
* - Call before merge operations to prevent schema conflicts
|
|
184
|
+
* - Call on branch checkout to keep branches up-to-date
|
|
185
|
+
*
|
|
186
|
+
* @param options - Options for the check and optional sync
|
|
187
|
+
* @returns Result indicating current sync status
|
|
188
|
+
*/
|
|
189
|
+
const ensureSchemaSync = (db) => async (options = {}) => {
|
|
190
|
+
const currentBranch = await getActiveBranch(db)();
|
|
191
|
+
if (currentBranch === SCHEMA_SOURCE_BRANCH) return {
|
|
192
|
+
synced: false,
|
|
193
|
+
hadDifferences: false
|
|
194
|
+
};
|
|
195
|
+
const differences = await getSchemaDiff(db)(currentBranch);
|
|
196
|
+
if (differences.length === 0) return {
|
|
197
|
+
synced: false,
|
|
198
|
+
hadDifferences: false
|
|
199
|
+
};
|
|
200
|
+
if (options.autoSync) return syncSchemaFromMain(db)({
|
|
201
|
+
autoCommitPending: options.autoCommitPending,
|
|
202
|
+
commitMessage: options.commitMessage,
|
|
203
|
+
author: options.author
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
synced: false,
|
|
207
|
+
hadDifferences: true,
|
|
208
|
+
differences,
|
|
209
|
+
error: `Branch '${currentBranch}' has ${differences.length} schema difference(s) from '${SCHEMA_SOURCE_BRANCH}'. Set autoSync: true to automatically sync schema.`
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Get a human-readable summary of schema differences
|
|
214
|
+
*/
|
|
215
|
+
const formatSchemaDiffSummary = (differences) => {
|
|
216
|
+
if (differences.length === 0) return "No schema differences";
|
|
217
|
+
const lines = [`${differences.length} table(s) with schema differences:`];
|
|
218
|
+
for (const diff of differences) {
|
|
219
|
+
const tableName = diff.toTableName || diff.fromTableName;
|
|
220
|
+
let changeType;
|
|
221
|
+
if (!diff.fromCreateStatement) changeType = "added";
|
|
222
|
+
else if (!diff.toCreateStatement) changeType = "removed";
|
|
223
|
+
else changeType = "modified";
|
|
224
|
+
lines.push(` - ${tableName} (${changeType})`);
|
|
225
|
+
}
|
|
226
|
+
return lines.join("\n");
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Check if two branches have compatible schemas (both are in sync with main).
|
|
230
|
+
* Useful before merging two feature branches.
|
|
231
|
+
*
|
|
232
|
+
* @param branchA - First branch to check
|
|
233
|
+
* @param branchB - Second branch to check
|
|
234
|
+
* @returns Object indicating if both branches are schema-compatible
|
|
235
|
+
*/
|
|
236
|
+
const areBranchesSchemaCompatible = (db) => async (branchA, branchB) => {
|
|
237
|
+
const [diffA, diffB] = await Promise.all([getSchemaDiff(db)(branchA), getSchemaDiff(db)(branchB)]);
|
|
238
|
+
return {
|
|
239
|
+
compatible: diffA.length === 0 && diffB.length === 0,
|
|
240
|
+
branchADifferences: diffA,
|
|
241
|
+
branchBDifferences: diffB
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
export { SCHEMA_SOURCE_BRANCH, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, syncSchemaFromMain };
|
package/dist/env.d.ts
CHANGED
|
@@ -9,22 +9,24 @@ declare const envSchema: z.ZodObject<{
|
|
|
9
9
|
pentest: "pentest";
|
|
10
10
|
test: "test";
|
|
11
11
|
}>>;
|
|
12
|
-
|
|
12
|
+
INKEEP_AGENTS_MANAGE_DATABASE_URL: z.ZodOptional<z.ZodString>;
|
|
13
|
+
INKEEP_AGENTS_RUN_DATABASE_URL: z.ZodOptional<z.ZodString>;
|
|
13
14
|
POSTGRES_POOL_SIZE: z.ZodOptional<z.ZodString>;
|
|
14
15
|
INKEEP_AGENTS_JWT_SIGNING_SECRET: z.ZodOptional<z.ZodString>;
|
|
15
16
|
INKEEP_AGENTS_MANAGE_UI_URL: z.ZodOptional<z.ZodString>;
|
|
16
|
-
|
|
17
|
+
INKEEP_AGENTS_API_URL: z.ZodOptional<z.ZodString>;
|
|
17
18
|
BETTER_AUTH_SECRET: z.ZodOptional<z.ZodString>;
|
|
18
19
|
TRUSTED_ORIGIN: z.ZodOptional<z.ZodString>;
|
|
19
20
|
OAUTH_PROXY_PRODUCTION_URL: z.ZodOptional<z.ZodString>;
|
|
20
21
|
}, z.core.$strip>;
|
|
21
22
|
declare const env: {
|
|
22
23
|
ENVIRONMENT?: "development" | "production" | "pentest" | "test" | undefined;
|
|
23
|
-
|
|
24
|
+
INKEEP_AGENTS_MANAGE_DATABASE_URL?: string | undefined;
|
|
25
|
+
INKEEP_AGENTS_RUN_DATABASE_URL?: string | undefined;
|
|
24
26
|
POSTGRES_POOL_SIZE?: string | undefined;
|
|
25
27
|
INKEEP_AGENTS_JWT_SIGNING_SECRET?: string | undefined;
|
|
26
28
|
INKEEP_AGENTS_MANAGE_UI_URL?: string | undefined;
|
|
27
|
-
|
|
29
|
+
INKEEP_AGENTS_API_URL?: string | undefined;
|
|
28
30
|
BETTER_AUTH_SECRET?: string | undefined;
|
|
29
31
|
TRUSTED_ORIGIN?: string | undefined;
|
|
30
32
|
OAUTH_PROXY_PRODUCTION_URL?: string | undefined;
|
package/dist/env.js
CHANGED
|
@@ -38,11 +38,12 @@ const envSchema = z.object({
|
|
|
38
38
|
"pentest",
|
|
39
39
|
"test"
|
|
40
40
|
]).optional(),
|
|
41
|
-
|
|
41
|
+
INKEEP_AGENTS_MANAGE_DATABASE_URL: z.string().optional(),
|
|
42
|
+
INKEEP_AGENTS_RUN_DATABASE_URL: z.string().optional(),
|
|
42
43
|
POSTGRES_POOL_SIZE: z.string().optional(),
|
|
43
44
|
INKEEP_AGENTS_JWT_SIGNING_SECRET: z.string().min(32, "INKEEP_AGENTS_JWT_SIGNING_SECRET must be at least 32 characters").optional(),
|
|
44
45
|
INKEEP_AGENTS_MANAGE_UI_URL: z.string().optional(),
|
|
45
|
-
|
|
46
|
+
INKEEP_AGENTS_API_URL: z.string().optional(),
|
|
46
47
|
BETTER_AUTH_SECRET: z.string().optional(),
|
|
47
48
|
TRUSTED_ORIGIN: z.string().optional(),
|
|
48
49
|
OAUTH_PROXY_PRODUCTION_URL: z.string().optional()
|