@kwirthmagnify/kwirth-common-ai 0.5.27 → 0.5.29
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/back.d.ts +96 -0
- package/dist/back.js +189 -10
- package/package.json +1 -1
package/dist/back.d.ts
CHANGED
|
@@ -7,12 +7,19 @@ export declare const loadModels: (providers: ILlmProvider[], log: IBackChannelOb
|
|
|
7
7
|
export { generateText, Output, stepCountIs, tool } from 'ai';
|
|
8
8
|
export { z } from 'zod';
|
|
9
9
|
export declare const zodFromExample: (example: Record<string, unknown>) => z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
10
|
+
export interface ISourceRepoCred {
|
|
11
|
+
host: string;
|
|
12
|
+
type: 'github' | 'gitlab';
|
|
13
|
+
token: string;
|
|
14
|
+
apiBaseUrl?: string;
|
|
15
|
+
}
|
|
10
16
|
export interface IToolContext {
|
|
11
17
|
origin: string;
|
|
12
18
|
nodes: Map<string, any>;
|
|
13
19
|
clusterInfo: any;
|
|
14
20
|
clusterMetrics: any[];
|
|
15
21
|
clusterEvents?: any[];
|
|
22
|
+
sourceRepos?: ISourceRepoCred[];
|
|
16
23
|
trace: (toolName: string, args: Record<string, unknown>) => void;
|
|
17
24
|
}
|
|
18
25
|
export declare enum EToolEffect {
|
|
@@ -369,6 +376,10 @@ export declare const tools: {
|
|
|
369
376
|
reason: any;
|
|
370
377
|
message: any;
|
|
371
378
|
controlledBy: any;
|
|
379
|
+
source: {
|
|
380
|
+
repo: any;
|
|
381
|
+
revision: any;
|
|
382
|
+
} | undefined;
|
|
372
383
|
conditions: any;
|
|
373
384
|
containers: any;
|
|
374
385
|
initContainers: any;
|
|
@@ -387,6 +398,7 @@ export declare const tools: {
|
|
|
387
398
|
reason?: undefined;
|
|
388
399
|
message?: undefined;
|
|
389
400
|
controlledBy?: undefined;
|
|
401
|
+
source?: undefined;
|
|
390
402
|
conditions?: undefined;
|
|
391
403
|
containers?: undefined;
|
|
392
404
|
initContainers?: undefined;
|
|
@@ -416,6 +428,90 @@ export declare const tools: {
|
|
|
416
428
|
revisionCount?: undefined;
|
|
417
429
|
revisions?: undefined;
|
|
418
430
|
}>;
|
|
431
|
+
readonly get_configmap: import("ai").Tool<{
|
|
432
|
+
namespace: string;
|
|
433
|
+
name: string;
|
|
434
|
+
}, {
|
|
435
|
+
name: string;
|
|
436
|
+
namespace: string;
|
|
437
|
+
resourceVersion: any;
|
|
438
|
+
lastModified: string | undefined;
|
|
439
|
+
data: any;
|
|
440
|
+
binaryDataKeys: string[];
|
|
441
|
+
error?: undefined;
|
|
442
|
+
} | {
|
|
443
|
+
error: any;
|
|
444
|
+
name?: undefined;
|
|
445
|
+
namespace?: undefined;
|
|
446
|
+
resourceVersion?: undefined;
|
|
447
|
+
lastModified?: undefined;
|
|
448
|
+
data?: undefined;
|
|
449
|
+
binaryDataKeys?: undefined;
|
|
450
|
+
}>;
|
|
451
|
+
readonly get_secret: import("ai").Tool<{
|
|
452
|
+
namespace: string;
|
|
453
|
+
name: string;
|
|
454
|
+
}, {
|
|
455
|
+
name: string;
|
|
456
|
+
namespace: string;
|
|
457
|
+
type: any;
|
|
458
|
+
resourceVersion: any;
|
|
459
|
+
lastModified: string | undefined;
|
|
460
|
+
keys: string[];
|
|
461
|
+
error?: undefined;
|
|
462
|
+
} | {
|
|
463
|
+
error: any;
|
|
464
|
+
name?: undefined;
|
|
465
|
+
namespace?: undefined;
|
|
466
|
+
type?: undefined;
|
|
467
|
+
resourceVersion?: undefined;
|
|
468
|
+
lastModified?: undefined;
|
|
469
|
+
keys?: undefined;
|
|
470
|
+
}>;
|
|
471
|
+
readonly get_workload_config_refs: import("ai").Tool<{
|
|
472
|
+
namespace: string;
|
|
473
|
+
name: string;
|
|
474
|
+
}, {
|
|
475
|
+
deployment: string;
|
|
476
|
+
namespace: string;
|
|
477
|
+
refs: ({
|
|
478
|
+
resourceVersion: any;
|
|
479
|
+
lastModified: string | undefined;
|
|
480
|
+
kind: string;
|
|
481
|
+
name: string;
|
|
482
|
+
via: string[];
|
|
483
|
+
} | {
|
|
484
|
+
error: any;
|
|
485
|
+
kind: string;
|
|
486
|
+
name: string;
|
|
487
|
+
via: string[];
|
|
488
|
+
})[];
|
|
489
|
+
error?: undefined;
|
|
490
|
+
} | {
|
|
491
|
+
error: any;
|
|
492
|
+
deployment?: undefined;
|
|
493
|
+
namespace?: undefined;
|
|
494
|
+
refs?: undefined;
|
|
495
|
+
}>;
|
|
496
|
+
readonly get_source_file: import("ai").Tool<{
|
|
497
|
+
repo: string;
|
|
498
|
+
ref: string;
|
|
499
|
+
path: string;
|
|
500
|
+
}, {
|
|
501
|
+
repo: string;
|
|
502
|
+
ref: string;
|
|
503
|
+
path: string;
|
|
504
|
+
truncated: boolean;
|
|
505
|
+
content: string;
|
|
506
|
+
error?: undefined;
|
|
507
|
+
} | {
|
|
508
|
+
error: any;
|
|
509
|
+
repo?: undefined;
|
|
510
|
+
ref?: undefined;
|
|
511
|
+
path?: undefined;
|
|
512
|
+
truncated?: undefined;
|
|
513
|
+
content?: undefined;
|
|
514
|
+
}>;
|
|
419
515
|
};
|
|
420
516
|
export declare const toolInfoList: IToolInfo[];
|
|
421
517
|
export interface IAgentRunResult {
|
package/dist/back.js
CHANGED
|
@@ -174,6 +174,37 @@ const zodFromExample = (example) => {
|
|
|
174
174
|
return zod_1.z.object(shape);
|
|
175
175
|
};
|
|
176
176
|
exports.zodFromExample = zodFromExample;
|
|
177
|
+
// Parse a repo reference (full URL or 'owner/name'; bare form assumes github.com). Owner keeps GitLab subgroups.
|
|
178
|
+
const parseRepoRef = (repo) => {
|
|
179
|
+
let host = 'github.com';
|
|
180
|
+
let pathPart = repo.trim();
|
|
181
|
+
const m = pathPart.match(/^(?:git@|https?:\/\/)?([^/:]+)[/:](.+)$/);
|
|
182
|
+
if (m && m[1].includes('.')) {
|
|
183
|
+
host = m[1];
|
|
184
|
+
pathPart = m[2];
|
|
185
|
+
}
|
|
186
|
+
const projectPath = pathPart.replace(/\.git$/, '').replace(/^\/+|\/+$/g, '');
|
|
187
|
+
return { host, projectPath };
|
|
188
|
+
};
|
|
189
|
+
// Fetch one file's raw content at a ref from GitHub or GitLab (cloud or on-prem), using the matching cred.
|
|
190
|
+
const fetchSourceFile = async (cred, projectPath, ref, path) => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
const cleanPath = path.replace(/^\/+/, '');
|
|
193
|
+
if (cred.type === 'github') {
|
|
194
|
+
const base = (_a = cred.apiBaseUrl) !== null && _a !== void 0 ? _a : 'https://api.github.com';
|
|
195
|
+
const url = `${base}/repos/${projectPath}/contents/${cleanPath.split('/').map(encodeURIComponent).join('/')}?ref=${encodeURIComponent(ref)}`;
|
|
196
|
+
const resp = await fetch(url, { headers: { Authorization: `Bearer ${cred.token}`, Accept: 'application/vnd.github.raw', 'User-Agent': 'kwirth-agora' } });
|
|
197
|
+
if (!resp.ok)
|
|
198
|
+
throw new Error(`GitHub ${resp.status} for ${projectPath}/${cleanPath}@${ref}`);
|
|
199
|
+
return await resp.text();
|
|
200
|
+
}
|
|
201
|
+
const base = (_b = cred.apiBaseUrl) !== null && _b !== void 0 ? _b : `https://${cred.host}/api/v4`;
|
|
202
|
+
const url = `${base}/projects/${encodeURIComponent(projectPath)}/repository/files/${encodeURIComponent(cleanPath)}/raw?ref=${encodeURIComponent(ref)}`;
|
|
203
|
+
const resp = await fetch(url, { headers: { 'PRIVATE-TOKEN': cred.token, 'User-Agent': 'kwirth-agora' } });
|
|
204
|
+
if (!resp.ok)
|
|
205
|
+
throw new Error(`GitLab ${resp.status} for ${projectPath}/${cleanPath}@${ref}`);
|
|
206
|
+
return await resp.text();
|
|
207
|
+
};
|
|
177
208
|
// Effect of a tool: READ (safe, informational) or WRITE (has side effects on the cluster).
|
|
178
209
|
// Dual purpose: hints the LLM, and gates authorization (Agora/readOnly filter out WRITE).
|
|
179
210
|
var EToolEffect;
|
|
@@ -230,6 +261,36 @@ const summarizeClusterEvent = (e) => {
|
|
|
230
261
|
namespace: (_d = o.metadata) === null || _d === void 0 ? void 0 : _d.namespace
|
|
231
262
|
};
|
|
232
263
|
};
|
|
264
|
+
// Best-effort "last modified" of a k8s object: the newest managedFields time (each apply stamps one),
|
|
265
|
+
// falling back to creationTimestamp. k8s keeps no explicit lastModified, so this is the closest signal to
|
|
266
|
+
// "when did this ConfigMap/Secret last change" — used to correlate a config edit with a crash.
|
|
267
|
+
const lastModifiedOf = (meta) => {
|
|
268
|
+
var _a;
|
|
269
|
+
const times = ((_a = meta === null || meta === void 0 ? void 0 : meta.managedFields) !== null && _a !== void 0 ? _a : []).map((f) => f.time).filter(Boolean);
|
|
270
|
+
return times.length ? times.sort()[times.length - 1] : meta === null || meta === void 0 ? void 0 : meta.creationTimestamp;
|
|
271
|
+
};
|
|
272
|
+
// The ConfigMap/Secret references a pod template consumes: envFrom, env.valueFrom, and volumes.
|
|
273
|
+
const configRefsOfPodSpec = (spec) => {
|
|
274
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
275
|
+
const refs = [];
|
|
276
|
+
const add = (kind, name, via) => { if (name)
|
|
277
|
+
refs.push({ kind, name, via }); };
|
|
278
|
+
for (const ct of [...((_a = spec === null || spec === void 0 ? void 0 : spec.containers) !== null && _a !== void 0 ? _a : []), ...((_b = spec === null || spec === void 0 ? void 0 : spec.initContainers) !== null && _b !== void 0 ? _b : [])]) {
|
|
279
|
+
for (const ef of (_c = ct.envFrom) !== null && _c !== void 0 ? _c : []) {
|
|
280
|
+
add('ConfigMap', (_d = ef.configMapRef) === null || _d === void 0 ? void 0 : _d.name, `envFrom(${ct.name})`);
|
|
281
|
+
add('Secret', (_e = ef.secretRef) === null || _e === void 0 ? void 0 : _e.name, `envFrom(${ct.name})`);
|
|
282
|
+
}
|
|
283
|
+
for (const e of (_f = ct.env) !== null && _f !== void 0 ? _f : []) {
|
|
284
|
+
add('ConfigMap', (_h = (_g = e.valueFrom) === null || _g === void 0 ? void 0 : _g.configMapKeyRef) === null || _h === void 0 ? void 0 : _h.name, `env ${e.name}`);
|
|
285
|
+
add('Secret', (_k = (_j = e.valueFrom) === null || _j === void 0 ? void 0 : _j.secretKeyRef) === null || _k === void 0 ? void 0 : _k.name, `env ${e.name}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const v of (_l = spec === null || spec === void 0 ? void 0 : spec.volumes) !== null && _l !== void 0 ? _l : []) {
|
|
289
|
+
add('ConfigMap', (_m = v.configMap) === null || _m === void 0 ? void 0 : _m.name, `volume ${v.name}`);
|
|
290
|
+
add('Secret', (_o = v.secret) === null || _o === void 0 ? void 0 : _o.secretName, `volume ${v.name}`);
|
|
291
|
+
}
|
|
292
|
+
return refs;
|
|
293
|
+
};
|
|
233
294
|
exports.tools = {
|
|
234
295
|
// ── CLUSTER CONFIG ───────────────────────────────────────────────────────
|
|
235
296
|
list_namespaces: (0, ai_1.tool)({
|
|
@@ -786,7 +847,7 @@ exports.tools = {
|
|
|
786
847
|
name: zod_1.z.string().describe('Name of the pod')
|
|
787
848
|
}),
|
|
788
849
|
execute: async ({ namespace, name }) => {
|
|
789
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
850
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
790
851
|
ctx().trace('describe_pod', { namespace, name });
|
|
791
852
|
try {
|
|
792
853
|
const c = ctx().clusterInfo;
|
|
@@ -813,24 +874,30 @@ exports.tools = {
|
|
|
813
874
|
const rsOwner = ((_f = (_e = rs.metadata) === null || _e === void 0 ? void 0 : _e.ownerReferences) !== null && _f !== void 0 ? _f : [])[0];
|
|
814
875
|
controlledBy = rsOwner ? { kind: rsOwner.kind, name: rsOwner.name } : { kind: 'ReplicaSet', name: podOwner.name };
|
|
815
876
|
}
|
|
816
|
-
catch (
|
|
877
|
+
catch (_r) {
|
|
817
878
|
controlledBy = { kind: 'ReplicaSet', name: podOwner.name };
|
|
818
879
|
}
|
|
819
880
|
}
|
|
820
881
|
else if (podOwner) {
|
|
821
882
|
controlledBy = { kind: podOwner.kind, name: podOwner.name }; // StatefulSet/DaemonSet/Job own pods directly
|
|
822
883
|
}
|
|
884
|
+
// Source provenance: OCI standard annotations (org.opencontainers.image.*) with a kwirth.io fallback →
|
|
885
|
+
// the repo + commit the image was built from, so the bot can read the actual source (get_source_file).
|
|
886
|
+
const ann = (_h = (_g = pod.metadata) === null || _g === void 0 ? void 0 : _g.annotations) !== null && _h !== void 0 ? _h : {};
|
|
887
|
+
const sourceRepo = (_j = ann['org.opencontainers.image.source']) !== null && _j !== void 0 ? _j : ann['kwirth.io/source-repo'];
|
|
888
|
+
const source = sourceRepo ? { repo: sourceRepo, revision: (_k = ann['org.opencontainers.image.revision']) !== null && _k !== void 0 ? _k : ann['kwirth.io/source-ref'] } : undefined;
|
|
823
889
|
return {
|
|
824
890
|
name, namespace, phase: status.phase, node: spec.nodeName, startTime: status.startTime, reason: status.reason, message: status.message,
|
|
825
891
|
controlledBy, // e.g. { kind: 'Deployment', name: 'montag-agent' } → feed to get_rollout_history
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
892
|
+
source, // { repo, revision } from image annotations → feed to get_source_file
|
|
893
|
+
conditions: ((_l = status.conditions) !== null && _l !== void 0 ? _l : []).map((c) => ({ type: c.type, status: c.status, reason: c.reason })),
|
|
894
|
+
containers: ((_m = status.containerStatuses) !== null && _m !== void 0 ? _m : []).map(containerStatus),
|
|
895
|
+
initContainers: ((_o = status.initContainerStatuses) !== null && _o !== void 0 ? _o : []).map(containerStatus),
|
|
896
|
+
spec: { containers: ((_p = spec.containers) !== null && _p !== void 0 ? _p : []).map(specContainer), restartPolicy: spec.restartPolicy }
|
|
830
897
|
};
|
|
831
898
|
}
|
|
832
899
|
catch (err) {
|
|
833
|
-
return { error: (
|
|
900
|
+
return { error: (_q = err.message) !== null && _q !== void 0 ? _q : String(err) };
|
|
834
901
|
}
|
|
835
902
|
}
|
|
836
903
|
}),
|
|
@@ -869,7 +936,7 @@ exports.tools = {
|
|
|
869
936
|
}
|
|
870
937
|
}),
|
|
871
938
|
get_rollout_history: (0, ai_1.tool)({
|
|
872
|
-
description: 'Returns the rollout history (revisions) of a Deployment via its ReplicaSets: per revision the image(s), replicas and pod-template summary (env
|
|
939
|
+
description: 'Returns the rollout history (revisions) of a Deployment via its ReplicaSets: per revision the image(s), replicas and pod-template summary (env with inline VALUES and their configMap/secret source, resources, command). Use to see WHAT CHANGED recently — a new image tag, a changed inline env value, a resource/command change — that may have broken the pods. Compare the newest revision against the previous one. NOTE: a change to a ConfigMap/Secret VALUE does NOT create a revision — use get_workload_config_refs for that.',
|
|
873
940
|
inputSchema: zod_1.z.object({
|
|
874
941
|
namespace: zod_1.z.string().describe('Namespace of the deployment'),
|
|
875
942
|
name: zod_1.z.string().describe('Name of the Deployment (the owning workload, e.g. describe_pod.controlledBy.name — NOT the pod name)')
|
|
@@ -880,7 +947,16 @@ exports.tools = {
|
|
|
880
947
|
try {
|
|
881
948
|
const rsList = await ctx().clusterInfo.appsApi.listNamespacedReplicaSet({ namespace });
|
|
882
949
|
const owned = ((_a = rsList.items) !== null && _a !== void 0 ? _a : []).filter((rs) => { var _a, _b; return ((_b = (_a = rs.metadata) === null || _a === void 0 ? void 0 : _a.ownerReferences) !== null && _b !== void 0 ? _b : []).some((o) => o.kind === 'Deployment' && o.name === name); });
|
|
883
|
-
|
|
950
|
+
// env: inline value + where a valueFrom env is sourced (so the LLM can both diff inline values
|
|
951
|
+
// across revisions AND know which vars come from a ConfigMap/Secret to check separately).
|
|
952
|
+
const envSource = (e) => {
|
|
953
|
+
var _a, _b, _c;
|
|
954
|
+
return ((_a = e.valueFrom) === null || _a === void 0 ? void 0 : _a.configMapKeyRef) ? `configMap:${e.valueFrom.configMapKeyRef.name}/${e.valueFrom.configMapKeyRef.key}`
|
|
955
|
+
: ((_b = e.valueFrom) === null || _b === void 0 ? void 0 : _b.secretKeyRef) ? `secret:${e.valueFrom.secretKeyRef.name}/${e.valueFrom.secretKeyRef.key}`
|
|
956
|
+
: ((_c = e.valueFrom) === null || _c === void 0 ? void 0 : _c.fieldRef) ? `field:${e.valueFrom.fieldRef.fieldPath}`
|
|
957
|
+
: undefined;
|
|
958
|
+
};
|
|
959
|
+
const container = (ct) => { var _a; return ({ name: ct.name, image: ct.image, command: ct.command, args: ct.args, resources: ct.resources, env: ((_a = ct.env) !== null && _a !== void 0 ? _a : []).map((e) => ({ name: e.name, value: e.value, from: envSource(e) })) }); };
|
|
884
960
|
const revisions = owned.map((rs) => {
|
|
885
961
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
886
962
|
const tmpl = (_c = (_b = (_a = rs.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.spec) !== null && _c !== void 0 ? _c : {};
|
|
@@ -902,6 +978,105 @@ exports.tools = {
|
|
|
902
978
|
}
|
|
903
979
|
}
|
|
904
980
|
}),
|
|
981
|
+
get_configmap: (0, ai_1.tool)({
|
|
982
|
+
description: 'Returns a ConfigMap\'s data (key → value) plus metadata (resourceVersion, lastModified). Use to inspect the ACTUAL config a workload consumes and to check whether it changed recently — a ConfigMap value change (same env var, different value) does NOT create a Deployment revision, so it is invisible to get_rollout_history.',
|
|
983
|
+
inputSchema: zod_1.z.object({
|
|
984
|
+
namespace: zod_1.z.string().describe('Namespace of the ConfigMap'),
|
|
985
|
+
name: zod_1.z.string().describe('Name of the ConfigMap')
|
|
986
|
+
}),
|
|
987
|
+
execute: async ({ namespace, name }) => {
|
|
988
|
+
var _a, _b, _c, _d;
|
|
989
|
+
ctx().trace('get_configmap', { namespace, name });
|
|
990
|
+
try {
|
|
991
|
+
const cm = await ctx().clusterInfo.coreApi.readNamespacedConfigMap({ name, namespace });
|
|
992
|
+
return { name, namespace, resourceVersion: (_a = cm.metadata) === null || _a === void 0 ? void 0 : _a.resourceVersion, lastModified: lastModifiedOf(cm.metadata), data: (_b = cm.data) !== null && _b !== void 0 ? _b : {}, binaryDataKeys: Object.keys((_c = cm.binaryData) !== null && _c !== void 0 ? _c : {}) };
|
|
993
|
+
}
|
|
994
|
+
catch (err) {
|
|
995
|
+
return { error: (_d = err.message) !== null && _d !== void 0 ? _d : String(err) };
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}),
|
|
999
|
+
get_secret: (0, ai_1.tool)({
|
|
1000
|
+
description: 'Returns a Secret\'s KEYS, type and metadata (resourceVersion, lastModified) — VALUES ARE REDACTED (never returned). Use to check whether a Secret a workload consumes changed recently (a value change does NOT create a Deployment revision) and which keys it holds. You cannot read the secret values.',
|
|
1001
|
+
inputSchema: zod_1.z.object({
|
|
1002
|
+
namespace: zod_1.z.string().describe('Namespace of the Secret'),
|
|
1003
|
+
name: zod_1.z.string().describe('Name of the Secret')
|
|
1004
|
+
}),
|
|
1005
|
+
execute: async ({ namespace, name }) => {
|
|
1006
|
+
var _a, _b, _c;
|
|
1007
|
+
ctx().trace('get_secret', { namespace, name });
|
|
1008
|
+
try {
|
|
1009
|
+
const s = await ctx().clusterInfo.coreApi.readNamespacedSecret({ name, namespace });
|
|
1010
|
+
return { name, namespace, type: s.type, resourceVersion: (_a = s.metadata) === null || _a === void 0 ? void 0 : _a.resourceVersion, lastModified: lastModifiedOf(s.metadata), keys: Object.keys((_b = s.data) !== null && _b !== void 0 ? _b : {}) }; // values intentionally omitted
|
|
1011
|
+
}
|
|
1012
|
+
catch (err) {
|
|
1013
|
+
return { error: (_c = err.message) !== null && _c !== void 0 ? _c : String(err) };
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}),
|
|
1017
|
+
get_workload_config_refs: (0, ai_1.tool)({
|
|
1018
|
+
description: 'Given a Deployment, lists the ConfigMaps and Secrets its pods consume (via envFrom, env valueFrom, and volumes), each with its lastModified time and resourceVersion. Use on a crash to find a config source that CHANGED WITHOUT A ROLLOUT: editing a ConfigMap/Secret value keeps the same env spec (no new revision) yet can break the pod — compare each ref\'s lastModified against when the pods started crashing, then read the changed one with get_configmap / get_secret.',
|
|
1019
|
+
inputSchema: zod_1.z.object({
|
|
1020
|
+
namespace: zod_1.z.string().describe('Namespace of the deployment'),
|
|
1021
|
+
name: zod_1.z.string().describe('Name of the Deployment (e.g. describe_pod.controlledBy.name)')
|
|
1022
|
+
}),
|
|
1023
|
+
execute: async ({ namespace, name }) => {
|
|
1024
|
+
var _a, _b, _c, _d;
|
|
1025
|
+
ctx().trace('get_workload_config_refs', { namespace, name });
|
|
1026
|
+
try {
|
|
1027
|
+
const c = ctx().clusterInfo;
|
|
1028
|
+
const dep = await c.appsApi.readNamespacedDeployment({ name, namespace });
|
|
1029
|
+
// dedupe by kind+name, merging the reasons (an object may be referenced several ways)
|
|
1030
|
+
const byKey = new Map();
|
|
1031
|
+
for (const r of configRefsOfPodSpec((_b = (_a = dep.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.spec)) {
|
|
1032
|
+
const cur = (_c = byKey.get(`${r.kind}/${r.name}`)) !== null && _c !== void 0 ? _c : { kind: r.kind, name: r.name, via: [] };
|
|
1033
|
+
if (!cur.via.includes(r.via))
|
|
1034
|
+
cur.via.push(r.via);
|
|
1035
|
+
byKey.set(`${r.kind}/${r.name}`, cur);
|
|
1036
|
+
}
|
|
1037
|
+
const refs = await Promise.all([...byKey.values()].map(async (r) => {
|
|
1038
|
+
var _a;
|
|
1039
|
+
try {
|
|
1040
|
+
const meta = (r.kind === 'ConfigMap'
|
|
1041
|
+
? await c.coreApi.readNamespacedConfigMap({ name: r.name, namespace })
|
|
1042
|
+
: await c.coreApi.readNamespacedSecret({ name: r.name, namespace })).metadata;
|
|
1043
|
+
return Object.assign(Object.assign({}, r), { resourceVersion: meta === null || meta === void 0 ? void 0 : meta.resourceVersion, lastModified: lastModifiedOf(meta) });
|
|
1044
|
+
}
|
|
1045
|
+
catch (err) {
|
|
1046
|
+
return Object.assign(Object.assign({}, r), { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) });
|
|
1047
|
+
}
|
|
1048
|
+
}));
|
|
1049
|
+
return { deployment: name, namespace, refs };
|
|
1050
|
+
}
|
|
1051
|
+
catch (err) {
|
|
1052
|
+
return { error: (_d = err.message) !== null && _d !== void 0 ? _d : String(err) };
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}),
|
|
1056
|
+
get_source_file: (0, ai_1.tool)({
|
|
1057
|
+
description: 'Fetches the contents of a single source file from a Git repository (GitHub or GitLab) at a specific ref. Use to inspect the actual source behind a crash: read the stack-trace file:line from the logs, then fetch that file at the image build revision (describe_pod.source). Call repeatedly to follow the trace across files until you find the bug.',
|
|
1058
|
+
inputSchema: zod_1.z.object({
|
|
1059
|
+
repo: zod_1.z.string().describe('Repository URL or owner/name (e.g. https://github.com/org/app or org/app) — from describe_pod.source.repo'),
|
|
1060
|
+
ref: zod_1.z.string().describe('Commit SHA, branch or tag — use the build revision (describe_pod.source.revision) so you read the code actually running'),
|
|
1061
|
+
path: zod_1.z.string().describe('File path within the repo (e.g. src/regex/loader.go)')
|
|
1062
|
+
}),
|
|
1063
|
+
execute: async ({ repo, ref, path }) => {
|
|
1064
|
+
var _a, _b;
|
|
1065
|
+
ctx().trace('get_source_file', { repo, ref, path });
|
|
1066
|
+
try {
|
|
1067
|
+
const { host, projectPath } = parseRepoRef(repo);
|
|
1068
|
+
const cred = ((_a = ctx().sourceRepos) !== null && _a !== void 0 ? _a : []).find(r => r.host === host);
|
|
1069
|
+
if (!cred)
|
|
1070
|
+
return { error: `No source-repo credentials configured for host '${host}'. Add it in Agora → Source repos.` };
|
|
1071
|
+
const text = await fetchSourceFile(cred, projectPath, ref, path);
|
|
1072
|
+
const truncated = text.length > 20000;
|
|
1073
|
+
return { repo: projectPath, ref, path, truncated, content: truncated ? text.slice(0, 20000) : text };
|
|
1074
|
+
}
|
|
1075
|
+
catch (err) {
|
|
1076
|
+
return { error: (_b = err.message) !== null && _b !== void 0 ? _b : String(err) };
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}),
|
|
905
1080
|
};
|
|
906
1081
|
exports.toolInfoList = [
|
|
907
1082
|
{ name: 'list_namespaces', effect: EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
|
|
@@ -935,7 +1110,11 @@ exports.toolInfoList = [
|
|
|
935
1110
|
{ name: 'describe_pod', effect: EToolEffect.READ, description: 'Diagnostic summary of a pod (kubectl describe pod): per-container waiting/terminated reason + exitCode (OOMKilled/CrashLoop…), restart count, probes.' },
|
|
936
1111
|
{ name: 'get_pod_yaml', effect: EToolEffect.READ, description: 'Full Pod manifest (kubectl get pod -o yaml): spec (env, volumes, resources, probes) and status.' },
|
|
937
1112
|
{ name: 'get_deployment_yaml', effect: EToolEffect.READ, description: 'Full Deployment manifest (kubectl get deployment -o yaml): pod template (image, env, resources, probes) and strategy.' },
|
|
938
|
-
{ name: 'get_rollout_history', effect: EToolEffect.READ, description: 'Rollout revisions of a Deployment (via ReplicaSets): image + template per revision, to see what changed (new image/env/resource) that may have broken the pods.' },
|
|
1113
|
+
{ name: 'get_rollout_history', effect: EToolEffect.READ, description: 'Rollout revisions of a Deployment (via ReplicaSets): image + template per revision (env with inline values + configMap/secret source), to see what changed (new image/env/resource) that may have broken the pods.' },
|
|
1114
|
+
{ name: 'get_configmap', effect: EToolEffect.READ, description: 'A ConfigMap\'s data (key→value) + lastModified. A ConfigMap value change does NOT create a rollout revision, so check it for a crash with no deployment change.' },
|
|
1115
|
+
{ name: 'get_secret', effect: EToolEffect.READ, description: 'A Secret\'s keys + type + lastModified (VALUES REDACTED). Check whether a consumed Secret changed recently (no rollout revision is created by a value change).' },
|
|
1116
|
+
{ name: 'get_workload_config_refs', effect: EToolEffect.READ, description: 'The ConfigMaps/Secrets a Deployment consumes (envFrom/valueFrom/volumes) with each one\'s lastModified — find a config source that changed WITHOUT a rollout and broke the pods.' },
|
|
1117
|
+
{ name: 'get_source_file', effect: EToolEffect.READ, description: 'Fetches a file from a Git repo (GitHub/GitLab) at a ref — inspect the source behind a crash by following the stack trace to the offending file:line.' },
|
|
939
1118
|
];
|
|
940
1119
|
// Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
|
|
941
1120
|
// (intersected with the catalog); readOnly filters out WRITE-effect tools. Pure (no LLM) → unit-testable.
|