@kalera/munin-sdk 1.0.0 → 1.0.2

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @kalera/munin-sdk@1.0.0 build /home/runner/work/munin-for-agents/munin-for-agents/packages/ts-sdk
2
+ > @kalera/munin-sdk@1.0.2 build /home/runner/work/munin-for-agents/munin-for-agents/packages/ts-sdk
3
3
  > tsc -p tsconfig.json
4
4
 
package/dist/client.d.ts CHANGED
@@ -5,12 +5,18 @@ export declare class MuninClient {
5
5
  private readonly timeoutMs;
6
6
  private readonly fetchImpl;
7
7
  private capabilitiesCache?;
8
- constructor(config: MuninClientConfig);
8
+ constructor(config?: MuninClientConfig);
9
9
  capabilities(forceRefresh?: boolean): Promise<MuninCapabilities>;
10
10
  invoke<TPayload extends Record<string, unknown>, TData = unknown>(projectId: string, action: MuninAction, payload: TPayload, options?: {
11
11
  requestId?: string;
12
12
  ensureCapability?: boolean;
13
13
  }): Promise<MuninResponse<TData>>;
14
+ /**
15
+ * Cleans up raw Munin response for LLM context efficiency.
16
+ * Removes dense vector arrays and formats GraphRAG objects into readable structures.
17
+ */
18
+ private formatLlmResponse;
19
+ private formatGraph;
14
20
  store(projectId: string, payload: Record<string, unknown>): Promise<MuninResponse<unknown>>;
15
21
  retrieve(projectId: string, payload: Record<string, unknown>): Promise<MuninResponse<unknown>>;
16
22
  search(projectId: string, payload: Record<string, unknown>): Promise<MuninResponse<unknown>>;
package/dist/client.js CHANGED
@@ -8,10 +8,10 @@ export class MuninClient {
8
8
  fetchImpl;
9
9
  capabilitiesCache;
10
10
  constructor(config) {
11
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
12
- this.apiKey = config.apiKey;
13
- this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
14
- this.fetchImpl = config.fetchImpl ?? fetch;
11
+ this.baseUrl = (config?.baseUrl || "https://munin.kalera.dev").replace(/\/$/, "");
12
+ this.apiKey = config?.apiKey;
13
+ this.timeoutMs = config?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
14
+ this.fetchImpl = config?.fetchImpl ?? fetch;
15
15
  }
16
16
  async capabilities(forceRefresh = false) {
17
17
  if (this.capabilitiesCache && !forceRefresh) {
@@ -67,7 +67,56 @@ export class MuninClient {
67
67
  message: `Unexpected failure invoking action '${action}'`,
68
68
  });
69
69
  }
70
- return body;
70
+ return this.formatLlmResponse(body);
71
+ }
72
+ /**
73
+ * Cleans up raw Munin response for LLM context efficiency.
74
+ * Removes dense vector arrays and formats GraphRAG objects into readable structures.
75
+ */
76
+ formatLlmResponse(rawRes) {
77
+ if (!rawRes || !rawRes.data)
78
+ return rawRes;
79
+ const data = rawRes.data;
80
+ // Clean single memory retrieve
81
+ if (data.key && data.content) {
82
+ if (data.embedding)
83
+ delete data.embedding;
84
+ if (data.knowledge_graph) {
85
+ data.knowledge_graph = this.formatGraph(data.knowledge_graph);
86
+ }
87
+ }
88
+ // Clean search/list/recent results
89
+ if (Array.isArray(data.results)) {
90
+ data.results = data.results.map((mem) => {
91
+ if (mem.embedding)
92
+ delete mem.embedding;
93
+ return mem;
94
+ });
95
+ }
96
+ // Clean graph in search
97
+ if (data.knowledge_graph) {
98
+ data.knowledge_graph = this.formatGraph(data.knowledge_graph);
99
+ }
100
+ return rawRes;
101
+ }
102
+ formatGraph(kg) {
103
+ if (!kg)
104
+ return kg;
105
+ const entities = (kg.entities || []).map((e) => {
106
+ if (e.embedding)
107
+ delete e.embedding;
108
+ return `${e.name} (${e.type}): ${e.description}`;
109
+ });
110
+ const relationships = (kg.relationships || []).map((r) => {
111
+ if (r.embedding)
112
+ delete r.embedding;
113
+ return `${r.source} -[${r.relation}]-> ${r.target}`;
114
+ });
115
+ return {
116
+ summary: "GraphRAG knowledge formatted for readability",
117
+ entities,
118
+ relationships
119
+ };
71
120
  }
72
121
  async store(projectId, payload) {
73
122
  return this.invoke(projectId, "store", payload, { ensureCapability: true });
package/dist/types.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface MuninResponse<TData = unknown> {
37
37
  requestId?: string;
38
38
  }
39
39
  export interface MuninClientConfig {
40
- baseUrl: string;
40
+ baseUrl?: string;
41
41
  apiKey?: string;
42
42
  timeoutMs?: number;
43
43
  fetchImpl?: typeof fetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kalera/munin-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -20,11 +20,11 @@ export class MuninClient {
20
20
  private readonly fetchImpl: typeof fetch;
21
21
  private capabilitiesCache?: MuninCapabilities;
22
22
 
23
- constructor(config: MuninClientConfig) {
24
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
25
- this.apiKey = config.apiKey;
26
- this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
27
- this.fetchImpl = config.fetchImpl ?? fetch;
23
+ constructor(config?: MuninClientConfig) {
24
+ this.baseUrl = (config?.baseUrl || "https://munin.kalera.dev").replace(/\/$/, "");
25
+ this.apiKey = config?.apiKey;
26
+ this.timeoutMs = config?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
27
+ this.fetchImpl = config?.fetchImpl ?? fetch;
28
28
  }
29
29
 
30
30
  async capabilities(forceRefresh = false): Promise<MuninCapabilities> {
@@ -104,7 +104,60 @@ export class MuninClient {
104
104
  );
105
105
  }
106
106
 
107
- return body;
107
+ return this.formatLlmResponse(body);
108
+ }
109
+
110
+ /**
111
+ * Cleans up raw Munin response for LLM context efficiency.
112
+ * Removes dense vector arrays and formats GraphRAG objects into readable structures.
113
+ */
114
+ private formatLlmResponse(rawRes: any): any {
115
+ if (!rawRes || !rawRes.data) return rawRes;
116
+
117
+ const data = rawRes.data;
118
+
119
+ // Clean single memory retrieve
120
+ if (data.key && data.content) {
121
+ if (data.embedding) delete data.embedding;
122
+ if (data.knowledge_graph) {
123
+ data.knowledge_graph = this.formatGraph(data.knowledge_graph);
124
+ }
125
+ }
126
+
127
+ // Clean search/list/recent results
128
+ if (Array.isArray(data.results)) {
129
+ data.results = data.results.map((mem: any) => {
130
+ if (mem.embedding) delete mem.embedding;
131
+ return mem;
132
+ });
133
+ }
134
+
135
+ // Clean graph in search
136
+ if (data.knowledge_graph) {
137
+ data.knowledge_graph = this.formatGraph(data.knowledge_graph);
138
+ }
139
+
140
+ return rawRes;
141
+ }
142
+
143
+ private formatGraph(kg: any): any {
144
+ if (!kg) return kg;
145
+
146
+ const entities = (kg.entities || []).map((e: any) => {
147
+ if (e.embedding) delete e.embedding;
148
+ return `${e.name} (${e.type}): ${e.description}`;
149
+ });
150
+
151
+ const relationships = (kg.relationships || []).map((r: any) => {
152
+ if (r.embedding) delete r.embedding;
153
+ return `${r.source} -[${r.relation}]-> ${r.target}`;
154
+ });
155
+
156
+ return {
157
+ summary: "GraphRAG knowledge formatted for readability",
158
+ entities,
159
+ relationships
160
+ };
108
161
  }
109
162
 
110
163
  async store(projectId: string, payload: Record<string, unknown>) {
package/src/types.ts CHANGED
@@ -55,7 +55,7 @@ export interface MuninResponse<TData = unknown> {
55
55
  }
56
56
 
57
57
  export interface MuninClientConfig {
58
- baseUrl: string;
58
+ baseUrl?: string;
59
59
  apiKey?: string;
60
60
  timeoutMs?: number;
61
61
  fetchImpl?: typeof fetch;