@ai-matrx/agents 0.59.175 → 0.59.177
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/CHANGELOG.md +13 -1
- package/dist/content-transfer/index.cjs +1 -1
- package/dist/content-transfer/index.js +1 -1
- package/dist/content-transfer/react/index.cjs +1 -1
- package/dist/content-transfer/react/index.js +1 -1
- package/dist/context/react/index.cjs +64 -58
- package/dist/context/react/index.js +64 -58
- package/dist/mandates/index.cjs +4 -4
- package/dist/mandates/index.d.cts +6 -6
- package/dist/mandates/index.d.ts +6 -6
- package/dist/mandates/index.js +4 -4
- package/dist/versions/index.cjs +231 -0
- package/dist/versions/index.d.cts +158 -0
- package/dist/versions/index.d.ts +158 -0
- package/dist/versions/index.js +208 -0
- package/dist/versions/react/index.cjs +1305 -0
- package/dist/versions/react/index.d.cts +137 -0
- package/dist/versions/react/index.d.ts +137 -0
- package/dist/versions/react/index.js +1302 -0
- package/package.json +24 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// versions/constants.ts
|
|
2
|
+
var AGENT_EXCLUDE_PATHS = /* @__PURE__ */ new Set([
|
|
3
|
+
"id",
|
|
4
|
+
"userId",
|
|
5
|
+
"organizationId",
|
|
6
|
+
"taskId",
|
|
7
|
+
"createdAt",
|
|
8
|
+
"updatedAt",
|
|
9
|
+
"isVersion",
|
|
10
|
+
"parentAgentId",
|
|
11
|
+
"sourceAgentId",
|
|
12
|
+
"sourceSnapshotAt",
|
|
13
|
+
// Lineage and record bookkeeping: who made the row and which version it was
|
|
14
|
+
// copied from never change what the agent does, so a copy never "differs" here.
|
|
15
|
+
"sourceVersion",
|
|
16
|
+
"followsSource",
|
|
17
|
+
"createdBy",
|
|
18
|
+
"runCounts",
|
|
19
|
+
"isOwner",
|
|
20
|
+
"accessLevel",
|
|
21
|
+
"sharedByEmail",
|
|
22
|
+
"agentType",
|
|
23
|
+
"version",
|
|
24
|
+
"changeNote",
|
|
25
|
+
"changedAt"
|
|
26
|
+
]);
|
|
27
|
+
var AGENT_IDENTITY_KEYS = {
|
|
28
|
+
variableDefinitions: "name",
|
|
29
|
+
contextPolicies: "key",
|
|
30
|
+
customTools: "name"
|
|
31
|
+
};
|
|
32
|
+
var AGENT_DIFF_OPTIONS = {
|
|
33
|
+
excludePaths: AGENT_EXCLUDE_PATHS,
|
|
34
|
+
identityKeys: AGENT_IDENTITY_KEYS,
|
|
35
|
+
// Output-schema property order is authored behavior: model providers often
|
|
36
|
+
// emit fields in schema order, so a reorder must be visible in version diffs.
|
|
37
|
+
orderSensitiveObjectPaths: /* @__PURE__ */ new Set(["outputSchema"]),
|
|
38
|
+
// Agent configuration is executable data. `_`/`__` keys (especially
|
|
39
|
+
// output-schema `__kind`) are contract fields, never hidden metadata.
|
|
40
|
+
skipUnderscorePrefix: false
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// versions/compare.ts
|
|
44
|
+
import { computeDiff } from "@ai-matrx/diff/structural";
|
|
45
|
+
var AGENT_PROFILE_FIELDS = /* @__PURE__ */ new Set(["name", "description", "category", "tags"]);
|
|
46
|
+
var AGENT_LOCAL_STATE_FIELDS = /* @__PURE__ */ new Set([
|
|
47
|
+
"isActive",
|
|
48
|
+
"isArchived",
|
|
49
|
+
"isFavorite"
|
|
50
|
+
]);
|
|
51
|
+
function toComparableAgentRecord(agent) {
|
|
52
|
+
return Object.fromEntries(
|
|
53
|
+
Object.entries(agent).filter(([key]) => !key.startsWith("_"))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function compareAgentDefinitions(systemAgent, personalAgent) {
|
|
57
|
+
const systemRecord = toComparableAgentRecord(systemAgent);
|
|
58
|
+
const personalRecord = toComparableAgentRecord(personalAgent);
|
|
59
|
+
const diffResult = computeDiff(
|
|
60
|
+
systemRecord,
|
|
61
|
+
personalRecord,
|
|
62
|
+
AGENT_DIFF_OPTIONS
|
|
63
|
+
);
|
|
64
|
+
const changedFields = diffResult.root.filter(
|
|
65
|
+
(node) => node.changeType !== "unchanged"
|
|
66
|
+
);
|
|
67
|
+
const profileFields = changedFields.filter(
|
|
68
|
+
(node) => AGENT_PROFILE_FIELDS.has(node.key)
|
|
69
|
+
);
|
|
70
|
+
const localStateFields = changedFields.filter(
|
|
71
|
+
(node) => AGENT_LOCAL_STATE_FIELDS.has(node.key)
|
|
72
|
+
);
|
|
73
|
+
const behaviorFields = changedFields.filter(
|
|
74
|
+
(node) => !AGENT_PROFILE_FIELDS.has(node.key) && !AGENT_LOCAL_STATE_FIELDS.has(node.key)
|
|
75
|
+
);
|
|
76
|
+
return {
|
|
77
|
+
diffResult,
|
|
78
|
+
changedFields,
|
|
79
|
+
behaviorFields,
|
|
80
|
+
profileFields,
|
|
81
|
+
localStateFields,
|
|
82
|
+
behaviorMatches: behaviorFields.length === 0,
|
|
83
|
+
comparedConfigurationMatches: !diffResult.hasChanges
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// versions/promote-failure-message.ts
|
|
88
|
+
var GENERIC = "Failed to promote version";
|
|
89
|
+
function promoteFailureMessage(err) {
|
|
90
|
+
const raw = err instanceof Error ? err.message : err && typeof err === "object" && "message" in err ? String(err.message ?? "") : typeof err === "string" ? err : "";
|
|
91
|
+
const reason = raw.trim();
|
|
92
|
+
return reason ? `${GENERIC}: ${reason}` : GENERIC;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// versions/enrich.ts
|
|
96
|
+
import { computeDiff as computeDiff2 } from "@ai-matrx/diff/structural";
|
|
97
|
+
function computeVersionFetchTargets(versions) {
|
|
98
|
+
if (versions.length === 0) return [];
|
|
99
|
+
const sorted = [...versions].sort((a, b) => b.version_number - a.version_number);
|
|
100
|
+
const targets = /* @__PURE__ */ new Set();
|
|
101
|
+
for (const v of sorted.slice(0, 10)) targets.add(v.version_number);
|
|
102
|
+
if (sorted.length <= 10) return [...targets];
|
|
103
|
+
targets.add(sorted[sorted.length - 1].version_number);
|
|
104
|
+
const remaining = sorted.slice(10, -1);
|
|
105
|
+
if (remaining.length > 0) {
|
|
106
|
+
const step = Math.max(1, Math.floor(remaining.length / Math.ceil(remaining.length / 10)));
|
|
107
|
+
for (let i = 0; i < remaining.length; i += step) targets.add(remaining[i].version_number);
|
|
108
|
+
}
|
|
109
|
+
return [...targets];
|
|
110
|
+
}
|
|
111
|
+
function enrichVersions(versions, snapshotOf) {
|
|
112
|
+
const sorted = [...versions].sort((a, b) => b.version_number - a.version_number);
|
|
113
|
+
return sorted.map((v, i) => {
|
|
114
|
+
const snapshot = snapshotOf(v.version_number);
|
|
115
|
+
const prev = sorted[i + 1];
|
|
116
|
+
const prevSnapshot = prev ? snapshotOf(prev.version_number) : void 0;
|
|
117
|
+
let diffSummary;
|
|
118
|
+
if (snapshot && prevSnapshot) {
|
|
119
|
+
diffSummary = computeDiff2(
|
|
120
|
+
prevSnapshot,
|
|
121
|
+
snapshot,
|
|
122
|
+
AGENT_DIFF_OPTIONS
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return { ...v, snapshotLoaded: !!snapshot, ...diffSummary ? { diffSummary } : {} };
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
var camel = (key) => key.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
129
|
+
function snapshotToComparable(row) {
|
|
130
|
+
const out = {};
|
|
131
|
+
for (const [key, value] of Object.entries(row)) {
|
|
132
|
+
const name = key === "version_number" ? "version" : camel(key);
|
|
133
|
+
out[name] = value;
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// versions/data.ts
|
|
139
|
+
var AgentVersionsError = class extends Error {
|
|
140
|
+
code;
|
|
141
|
+
detail;
|
|
142
|
+
hint;
|
|
143
|
+
constructor(error) {
|
|
144
|
+
super(error.message || "The agent's versions could not be read and the database gave no reason.");
|
|
145
|
+
this.name = "AgentVersionsError";
|
|
146
|
+
this.code = error.code ?? null;
|
|
147
|
+
this.detail = error.details ?? null;
|
|
148
|
+
this.hint = error.hint ?? null;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
async function listAgentVersions(client, query) {
|
|
152
|
+
const { data, error } = await client.rpc("agx_get_version_history", {
|
|
153
|
+
p_agent_id: query.agentId,
|
|
154
|
+
p_limit: query.limit ?? 50,
|
|
155
|
+
p_offset: query.offset ?? 0
|
|
156
|
+
});
|
|
157
|
+
if (error) throw new AgentVersionsError(error);
|
|
158
|
+
return Array.isArray(data) ? data : [];
|
|
159
|
+
}
|
|
160
|
+
async function readAgentVersionSnapshot(client, query) {
|
|
161
|
+
const { data, error } = await client.rpc("agx_get_version_snapshot", {
|
|
162
|
+
p_agent_id: query.agentId,
|
|
163
|
+
p_version_number: query.version
|
|
164
|
+
});
|
|
165
|
+
if (error) throw new AgentVersionsError(error);
|
|
166
|
+
const raw = Array.isArray(data) ? data[0] : data;
|
|
167
|
+
return raw && typeof raw === "object" ? raw : null;
|
|
168
|
+
}
|
|
169
|
+
async function resolveAgentVersionId(client, versionId) {
|
|
170
|
+
const { data, error } = await client.schema("agent").from("definition_version").select("id, agent_id, version_number, name").eq("id", versionId).maybeSingle();
|
|
171
|
+
if (error) throw new AgentVersionsError(error);
|
|
172
|
+
if (!data) return null;
|
|
173
|
+
const row = data;
|
|
174
|
+
return { versionId: row.id, agentId: row.agent_id, versionNumber: row.version_number, agentName: row.name };
|
|
175
|
+
}
|
|
176
|
+
async function promoteAgentVersion(client, query) {
|
|
177
|
+
const { data, error } = await client.rpc("agx_promote_version", {
|
|
178
|
+
p_agent_id: query.agentId,
|
|
179
|
+
p_version_number: query.version
|
|
180
|
+
});
|
|
181
|
+
if (error) throw new AgentVersionsError(error);
|
|
182
|
+
const result = data ?? {};
|
|
183
|
+
return { ...result, success: result.success === true };
|
|
184
|
+
}
|
|
185
|
+
async function declareContractBreak(client, query) {
|
|
186
|
+
const { error } = await client.rpc("agx_declare_contract_break", {
|
|
187
|
+
p_agent_id: query.agentId,
|
|
188
|
+
p_version_number: query.version,
|
|
189
|
+
p_kind: query.kind ?? void 0
|
|
190
|
+
});
|
|
191
|
+
if (error) throw new AgentVersionsError(error);
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
AGENT_DIFF_OPTIONS,
|
|
195
|
+
AGENT_EXCLUDE_PATHS,
|
|
196
|
+
AGENT_IDENTITY_KEYS,
|
|
197
|
+
AgentVersionsError,
|
|
198
|
+
compareAgentDefinitions,
|
|
199
|
+
computeVersionFetchTargets,
|
|
200
|
+
declareContractBreak,
|
|
201
|
+
enrichVersions,
|
|
202
|
+
listAgentVersions,
|
|
203
|
+
promoteAgentVersion,
|
|
204
|
+
promoteFailureMessage,
|
|
205
|
+
readAgentVersionSnapshot,
|
|
206
|
+
resolveAgentVersionId,
|
|
207
|
+
snapshotToComparable
|
|
208
|
+
};
|