@pentatonic-ai/ai-agent-sdk 0.4.5 → 0.4.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pentatonic-ai/ai-agent-sdk",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "TES SDK — LLM observability and lifecycle tracking via Pentatonic Thing Event System. Track token usage, tool calls, and conversations. Manage things through event-sourced lifecycle stages with AI enrichment and vector search.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,10 +50,14 @@ export async function search(db, ai, query, opts = {}) {
50
50
  return textSearch(db, query, opts);
51
51
  }
52
52
 
53
- // Generate query embedding
54
- const embResult = await ai.embed(query, "query");
53
+ // Generate query embedding — fall back to text search if embedding fails
54
+ let embResult;
55
+ try {
56
+ embResult = await ai.embed(query, "query");
57
+ } catch {
58
+ return textSearch(db, query, opts);
59
+ }
55
60
  if (!embResult?.embedding) {
56
- // Fall back to text-only search
57
61
  return textSearch(db, query, opts);
58
62
  }
59
63
 
@@ -25,6 +25,14 @@ import { createMemorySystem } from "./index.js";
25
25
 
26
26
  const { Pool } = pg;
27
27
 
28
+ // Prevent unhandled rejections from killing the process
29
+ process.on("uncaughtException", (err) => {
30
+ process.stderr.write(`[memory-server] Uncaught: ${err.message}\n`);
31
+ });
32
+ process.on("unhandledRejection", (err) => {
33
+ process.stderr.write(`[memory-server] Unhandled rejection: ${err?.message || err}\n`);
34
+ });
35
+
28
36
  const CLIENT_ID = process.env.CLIENT_ID || "default";
29
37
 
30
38
  function createMemory() {
@@ -249,18 +257,33 @@ async function main() {
249
257
  res.setHeader("Content-Type", "application/json");
250
258
 
251
259
  if (url.pathname === "/search" && req.method === "POST") {
252
- const results = await memory.search(body.query || "", {
253
- clientId: CLIENT_ID,
254
- limit: body.limit || 5,
255
- minScore: body.min_score || 0.3,
256
- });
257
- res.end(JSON.stringify({ results }));
260
+ try {
261
+ // Use text search by default (fast, no external dependencies).
262
+ // Vector search available via ?mode=vector if embeddings are working.
263
+ const useVector = url.searchParams.get("mode") === "vector";
264
+ const searchFn = useVector ? memory.search : memory.textSearch;
265
+ const results = await searchFn(body.query || "", {
266
+ clientId: CLIENT_ID,
267
+ limit: body.limit || 5,
268
+ minScore: body.min_score || 0.3,
269
+ });
270
+ res.end(JSON.stringify({ results }));
271
+ } catch (err) {
272
+ process.stderr.write(`[memory-server] Search error: ${err.message}\n${err.stack}\n`);
273
+ res.end(JSON.stringify({ results: [], error: err.message }));
274
+ }
258
275
  } else if (url.pathname === "/store" && req.method === "POST") {
259
- const result = await memory.ingest(body.content || "", {
260
- clientId: CLIENT_ID,
261
- metadata: body.metadata || {},
262
- });
263
- res.end(JSON.stringify(result));
276
+ try {
277
+ const result = await memory.ingest(body.content || "", {
278
+ clientId: CLIENT_ID,
279
+ metadata: body.metadata || {},
280
+ });
281
+ res.end(JSON.stringify(result));
282
+ } catch (err) {
283
+ process.stderr.write(`[memory-server] Store error: ${err.message}\n`);
284
+ res.statusCode = 500;
285
+ res.end(JSON.stringify({ error: err.message }));
286
+ }
264
287
  } else if (url.pathname === "/health") {
265
288
  res.end(JSON.stringify({ status: "ok", client: CLIENT_ID }));
266
289
  } else {