@superatomai/sdk-node 0.0.42-mds → 0.0.43-mds

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/index.d.mts CHANGED
@@ -777,6 +777,14 @@ declare const ToolSchema: z.ZodObject<{
777
777
  description: string;
778
778
  }[];
779
779
  }>>;
780
+ /** Cache policy. `false` = never cache (live data, write ops). Mirrors HTTP `Cache-Control: no-store`. */
781
+ cache: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodObject<{
782
+ ttlMs: z.ZodOptional<z.ZodNumber>;
783
+ }, "strip", z.ZodTypeAny, {
784
+ ttlMs?: number | undefined;
785
+ }, {
786
+ ttlMs?: number | undefined;
787
+ }>]>>;
780
788
  }, "strip", z.ZodTypeAny, {
781
789
  id: string;
782
790
  params: Record<string, string>;
@@ -793,6 +801,9 @@ declare const ToolSchema: z.ZodObject<{
793
801
  description: string;
794
802
  }[];
795
803
  } | undefined;
804
+ cache?: false | {
805
+ ttlMs?: number | undefined;
806
+ } | undefined;
796
807
  }, {
797
808
  id: string;
798
809
  params: Record<string, string>;
@@ -809,6 +820,9 @@ declare const ToolSchema: z.ZodObject<{
809
820
  description: string;
810
821
  }[];
811
822
  } | undefined;
823
+ cache?: false | {
824
+ ttlMs?: number | undefined;
825
+ } | undefined;
812
826
  }>;
813
827
  type Tool$1 = z.infer<typeof ToolSchema>;
814
828
  type CollectionOperation = 'getMany' | 'getOne' | 'query' | 'mutation' | 'updateOne' | 'deleteOne' | 'createOne';
package/dist/index.d.ts CHANGED
@@ -777,6 +777,14 @@ declare const ToolSchema: z.ZodObject<{
777
777
  description: string;
778
778
  }[];
779
779
  }>>;
780
+ /** Cache policy. `false` = never cache (live data, write ops). Mirrors HTTP `Cache-Control: no-store`. */
781
+ cache: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodObject<{
782
+ ttlMs: z.ZodOptional<z.ZodNumber>;
783
+ }, "strip", z.ZodTypeAny, {
784
+ ttlMs?: number | undefined;
785
+ }, {
786
+ ttlMs?: number | undefined;
787
+ }>]>>;
780
788
  }, "strip", z.ZodTypeAny, {
781
789
  id: string;
782
790
  params: Record<string, string>;
@@ -793,6 +801,9 @@ declare const ToolSchema: z.ZodObject<{
793
801
  description: string;
794
802
  }[];
795
803
  } | undefined;
804
+ cache?: false | {
805
+ ttlMs?: number | undefined;
806
+ } | undefined;
796
807
  }, {
797
808
  id: string;
798
809
  params: Record<string, string>;
@@ -809,6 +820,9 @@ declare const ToolSchema: z.ZodObject<{
809
820
  description: string;
810
821
  }[];
811
822
  } | undefined;
823
+ cache?: false | {
824
+ ttlMs?: number | undefined;
825
+ } | undefined;
812
826
  }>;
813
827
  type Tool$1 = z.infer<typeof ToolSchema>;
814
828
  type CollectionOperation = 'getMany' | 'getOne' | 'query' | 'mutation' | 'updateOne' | 'deleteOne' | 'createOne';
package/dist/index.js CHANGED
@@ -420,8 +420,10 @@ var ToolSchema = import_zod3.z.object({
420
420
  fullSchema: import_zod3.z.string().optional(),
421
421
  params: import_zod3.z.record(import_zod3.z.string()),
422
422
  fn: import_zod3.z.function().args(import_zod3.z.any()).returns(import_zod3.z.any()),
423
- outputSchema: OutputSchema.optional()
423
+ outputSchema: OutputSchema.optional(),
424
424
  // Optional: describes the data structure returned by this tool
425
+ /** Cache policy. `false` = never cache (live data, write ops). Mirrors HTTP `Cache-Control: no-store`. */
426
+ cache: import_zod3.z.union([import_zod3.z.literal(false), import_zod3.z.object({ ttlMs: import_zod3.z.number().optional() })]).optional()
425
427
  });
426
428
  var UserQueryFiltersSchema = import_zod3.z.object({
427
429
  username: import_zod3.z.string().optional(),
@@ -2081,6 +2083,21 @@ function formatResultAsString(formattedResult) {
2081
2083
  return JSON.stringify(formattedResult, null, 2);
2082
2084
  }
2083
2085
 
2086
+ // src/utils/cache-key.ts
2087
+ function stableStringify(value) {
2088
+ if (value === null || typeof value !== "object") {
2089
+ return JSON.stringify(value);
2090
+ }
2091
+ if (Array.isArray(value)) {
2092
+ return "[" + value.map(stableStringify).join(",") + "]";
2093
+ }
2094
+ const keys = Object.keys(value).sort();
2095
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(value[k])).join(",") + "}";
2096
+ }
2097
+ function buildDirectToolCacheKey(toolId, parameters) {
2098
+ return `et-direct:${toolId}:${stableStringify(parameters || {})}`;
2099
+ }
2100
+
2084
2101
  // src/handlers/data-request.ts
2085
2102
  function getQueryCacheKey(query) {
2086
2103
  if (typeof query === "string") {
@@ -2094,16 +2111,6 @@ function getQueryCacheKey(query) {
2094
2111
  }
2095
2112
  return "";
2096
2113
  }
2097
- function stableStringify(value) {
2098
- if (value === null || typeof value !== "object") {
2099
- return JSON.stringify(value);
2100
- }
2101
- if (Array.isArray(value)) {
2102
- return "[" + value.map(stableStringify).join(",") + "]";
2103
- }
2104
- const keys = Object.keys(value).sort();
2105
- return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(value[k])).join(",") + "}";
2106
- }
2107
2114
  function getCacheKey(collection, op, params, tools) {
2108
2115
  if (collection === "database" && op === "execute" && params?.sql) {
2109
2116
  return getQueryCacheKey(params.sql);
@@ -14580,17 +14587,45 @@ function formatComponentsForPrompt(components) {
14580
14587
  Props Structure: ${propsPreview}`;
14581
14588
  }).join("\n\n");
14582
14589
  }
14590
+ function classifyTool(tool) {
14591
+ if (tool.toolType === "direct") return "direct";
14592
+ if (tool.id.endsWith("_query")) return "sql";
14593
+ if (tool.id.endsWith("_call")) return "rest";
14594
+ if (tool.id.endsWith("_graphql")) return "graphql";
14595
+ return "direct";
14596
+ }
14583
14597
  function formatToolsForPrompt(tools) {
14584
14598
  if (!tools || tools.length === 0) {
14585
14599
  return "No external tools available.";
14586
14600
  }
14587
- return tools.map((tool, idx) => {
14601
+ const directTools = [];
14602
+ const sourceTools = [];
14603
+ for (const t of tools) {
14604
+ (classifyTool(t) === "direct" ? directTools : sourceTools).push(t);
14605
+ }
14606
+ const renderTool = (tool, idx, label) => {
14588
14607
  const paramsStr = Object.entries(tool.params || {}).map(([key, type]) => `${key}: ${type}`).join(", ");
14589
- return `${idx + 1}. ID: ${tool.id}
14608
+ return `${idx + 1}. [${label}] ID: ${tool.id}
14590
14609
  Name: ${tool.name}
14591
14610
  Description: ${tool.description}
14592
14611
  Parameters: { ${paramsStr} }`;
14593
- }).join("\n\n");
14612
+ };
14613
+ const sections = [];
14614
+ if (directTools.length > 0) {
14615
+ const body = directTools.map((t, i) => renderTool(t, i, "DIRECT \u2014 PREFER")).join("\n\n");
14616
+ sections.push(`### Direct Tools (try these first \u2014 they answer most questions without SQL)
14617
+ ${body}`);
14618
+ }
14619
+ if (sourceTools.length > 0) {
14620
+ const body = sourceTools.map((t, i) => {
14621
+ const kind = classifyTool(t);
14622
+ const label = kind === "sql" ? "SQL" : kind === "rest" ? "REST" : "GRAPHQL";
14623
+ return renderTool(t, i, label);
14624
+ }).join("\n\n");
14625
+ sections.push(`### Source Tools (fallback \u2014 use only when no direct tool fits)
14626
+ ${body}`);
14627
+ }
14628
+ return sections.join("\n\n");
14594
14629
  }
14595
14630
  function formatExistingComponentsForPrompt(existingComponents) {
14596
14631
  if (!existingComponents || existingComponents.length === 0) {
@@ -15005,6 +15040,18 @@ Fixed SQL query:`;
15005
15040
  logger.info(`[DASH_COMP_REQ] Replaced direct query with queryId: ${queryId}`);
15006
15041
  }
15007
15042
  finalComponent = { ...finalComponent, props };
15043
+ const ext = finalComponent.props?.externalTool;
15044
+ if (ext?.toolId && !ext?.parameters?.sql) {
15045
+ const matchedTool = tools?.find((t) => t.id === ext.toolId);
15046
+ if (matchedTool && matchedTool.cache !== false) {
15047
+ const match = executedTools.find((t) => t.id === ext.toolId);
15048
+ if (match) {
15049
+ const cacheKey = buildDirectToolCacheKey(ext.toolId, ext.parameters);
15050
+ queryCache.set(cacheKey, { success: true, data: match.result });
15051
+ logger.info(`[DASH_COMP_REQ] Pre-populated et-direct cache for ${ext.toolId}`);
15052
+ }
15053
+ }
15054
+ }
15008
15055
  if (parsedResult.props.query) {
15009
15056
  logger.info(`[DASH_COMP_REQ] Data source: Database query`);
15010
15057
  }
@@ -15176,7 +15223,35 @@ async function createFilterWithLLM(prompt, components, existingComponents, anthr
15176
15223
  const updatedComponents = result.updatedComponents || [];
15177
15224
  for (const comp of updatedComponents) {
15178
15225
  const extTool = comp.props?.externalTool;
15179
- if (!extTool?.parameters?.sql || !extTool?.toolId) continue;
15226
+ if (!extTool?.toolId) continue;
15227
+ const isDirectTool = !extTool?.parameters?.sql;
15228
+ if (isDirectTool) {
15229
+ const directTool = tools?.find((t) => t.id === extTool.toolId);
15230
+ if (!directTool) {
15231
+ logger.warn(`[DASH_COMP_REQ:FILTER] direct tool ${extTool.toolId} not found in tool registry`);
15232
+ continue;
15233
+ }
15234
+ const declared = new Set(Object.keys(directTool.params || {}));
15235
+ const sentKeys = Object.keys(extTool.parameters || {});
15236
+ const unknown = sentKeys.filter((k) => !declared.has(k));
15237
+ if (unknown.length > 0) {
15238
+ logger.warn(`[DASH_COMP_REQ:FILTER] dropping unknown params on ${extTool.toolId}: ${unknown.join(", ")}`);
15239
+ unknown.forEach((k) => delete extTool.parameters[k]);
15240
+ }
15241
+ if (directTool.cache !== false) {
15242
+ try {
15243
+ const directResult = await directTool.fn(extTool.parameters || {});
15244
+ const cacheKey2 = buildDirectToolCacheKey(extTool.toolId, extTool.parameters);
15245
+ queryCache.set(cacheKey2, { success: true, data: directResult });
15246
+ logger.info(`[DASH_COMP_REQ:FILTER] direct tool ${extTool.toolId} validated and cached for component: ${comp.id}`);
15247
+ } catch (err) {
15248
+ const errMsg = err instanceof Error ? err.message : String(err);
15249
+ logger.warn(`[DASH_COMP_REQ:FILTER] direct tool validation failed for ${extTool.toolId} on component ${comp.id}: ${errMsg}`);
15250
+ }
15251
+ }
15252
+ continue;
15253
+ }
15254
+ if (!extTool?.parameters?.sql) continue;
15180
15255
  let sql = extTool.parameters.sql;
15181
15256
  const defaultParams = extTool.parameters.params || {};
15182
15257
  const toolId = extTool.toolId;