@agent-native/core 0.58.1 → 0.58.3

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.
Files changed (61) hide show
  1. package/dist/agent/engine/translate-ai-sdk.d.ts.map +1 -1
  2. package/dist/agent/engine/translate-ai-sdk.js +1 -0
  3. package/dist/agent/engine/translate-ai-sdk.js.map +1 -1
  4. package/dist/agent/production-agent.d.ts +2 -0
  5. package/dist/agent/production-agent.d.ts.map +1 -1
  6. package/dist/agent/production-agent.js +114 -19
  7. package/dist/agent/production-agent.js.map +1 -1
  8. package/dist/agent/thread-data-builder.d.ts.map +1 -1
  9. package/dist/agent/thread-data-builder.js +10 -2
  10. package/dist/agent/thread-data-builder.js.map +1 -1
  11. package/dist/agent/tool-error-redaction.d.ts +4 -0
  12. package/dist/agent/tool-error-redaction.d.ts.map +1 -0
  13. package/dist/agent/tool-error-redaction.js +43 -0
  14. package/dist/agent/tool-error-redaction.js.map +1 -0
  15. package/dist/agent/types.d.ts +23 -6
  16. package/dist/agent/types.d.ts.map +1 -1
  17. package/dist/agent/types.js.map +1 -1
  18. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  19. package/dist/client/agent-chat-adapter.js +29 -5
  20. package/dist/client/agent-chat-adapter.js.map +1 -1
  21. package/dist/client/chat/attachment-adapters.d.ts.map +1 -1
  22. package/dist/client/chat/attachment-adapters.js +29 -4
  23. package/dist/client/chat/attachment-adapters.js.map +1 -1
  24. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  25. package/dist/client/composer/PromptComposer.js +5 -1
  26. package/dist/client/composer/PromptComposer.js.map +1 -1
  27. package/dist/client/composer/attachment-accept.d.ts +2 -0
  28. package/dist/client/composer/attachment-accept.d.ts.map +1 -1
  29. package/dist/client/composer/attachment-accept.js +30 -1
  30. package/dist/client/composer/attachment-accept.js.map +1 -1
  31. package/dist/data-widgets/index.d.ts +5 -5
  32. package/dist/file-upload/pre-upload-attachments.d.ts +2 -0
  33. package/dist/file-upload/pre-upload-attachments.d.ts.map +1 -1
  34. package/dist/file-upload/pre-upload-attachments.js +66 -9
  35. package/dist/file-upload/pre-upload-attachments.js.map +1 -1
  36. package/dist/scripts/db/tool-schemas.d.ts +3 -0
  37. package/dist/scripts/db/tool-schemas.d.ts.map +1 -0
  38. package/dist/scripts/db/tool-schemas.js +27 -0
  39. package/dist/scripts/db/tool-schemas.js.map +1 -0
  40. package/dist/scripts/dev/index.d.ts.map +1 -1
  41. package/dist/scripts/dev/index.js +2 -22
  42. package/dist/scripts/dev/index.js.map +1 -1
  43. package/dist/scripts/parse-args.js +1 -1
  44. package/dist/scripts/parse-args.js.map +1 -1
  45. package/dist/scripts/runner.js +1 -1
  46. package/dist/scripts/runner.js.map +1 -1
  47. package/dist/server/agent-chat-plugin.d.ts +16 -0
  48. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  49. package/dist/server/agent-chat-plugin.js +69 -27
  50. package/dist/server/agent-chat-plugin.js.map +1 -1
  51. package/dist/server/cli-capture.d.ts.map +1 -1
  52. package/dist/server/cli-capture.js +2 -1
  53. package/dist/server/cli-capture.js.map +1 -1
  54. package/dist/server/prompts/framework-core-compact.d.ts.map +1 -1
  55. package/dist/server/prompts/framework-core-compact.js +2 -1
  56. package/dist/server/prompts/framework-core-compact.js.map +1 -1
  57. package/dist/server/prompts/framework-core.d.ts.map +1 -1
  58. package/dist/server/prompts/framework-core.js +1 -0
  59. package/dist/server/prompts/framework-core.js.map +1 -1
  60. package/docs/content/native-chat-ui.md +12 -0
  61. package/package.json +2 -1
@@ -1,6 +1,7 @@
1
1
  import { runWithRequestContext, getRequestOrgId, getRequestUserEmail, getRequestRunContext, ensureRequestRunContext, } from "./request-context.js";
2
2
  import { getSetting, putSetting } from "../settings/store.js";
3
3
  import { createDbAdminAgentTools } from "../db-admin/agent-tools.js";
4
+ import { dbExecToolParameters } from "../scripts/db/tool-schemas.js";
4
5
  import { getH3App, markDefaultPluginProvided, trackPluginInit, } from "./framework-request-handler.js";
5
6
  import { createProductionAgentHandler, actionsToEngineTools, getActiveRunForThreadAsync, abortRun, subscribeToRun, } from "../agent/production-agent.js";
6
7
  import { runAgentLoopDirectWithSoftTimeout } from "../agent/run-loop-with-resume.js";
@@ -33,6 +34,8 @@ import { updateTaskStatusMessage } from "../a2a/task-store.js";
33
34
  import { collectFinalResponseTextFromAgentEvents } from "../a2a/response-text.js";
34
35
  import { buildRuntimeContextPrompt } from "../agent/runtime-context.js";
35
36
  import { buildFrameworkCore, buildFrameworkCoreCompact, FIRST_SESSION_PERSONALIZATION, getModelFamilyOverlay, } from "./prompts/index.js";
37
+ import { ACTION_CHAT_UI_DATA_WIDGET_RENDERER } from "../action-ui.js";
38
+ import { dataWidgetResultSchema } from "../data-widgets/index.js";
36
39
  // Lazy fs — loaded via dynamic import() on first use.
37
40
  // This avoids require() which bundlers convert to createRequire(import.meta.url)
38
41
  // that crashes on CF Workers where import.meta.url is undefined.
@@ -643,6 +646,58 @@ function createUrlTools() {
643
646
  },
644
647
  };
645
648
  }
649
+ function createDataWidgetActionEntries() {
650
+ return {
651
+ "render-data-widget": {
652
+ readOnly: true,
653
+ parallelSafe: true,
654
+ chatUI: {
655
+ renderer: ACTION_CHAT_UI_DATA_WIDGET_RENDERER,
656
+ title: "Data widget",
657
+ description: "Render a validated native data table or chart in chat.",
658
+ },
659
+ tool: {
660
+ description: "Render a native Agent-Native chat data widget from compact, real data you already retrieved or the user provided. Use this for in-chat tables, charts, graphs, trends, and compact reports when no domain-specific action already returns a native widget. Never fabricate rows or metrics just to make a chart.",
661
+ parameters: {
662
+ type: "object",
663
+ properties: {
664
+ widget: {
665
+ type: "string",
666
+ enum: ["data-table", "data-chart", "data-insights"],
667
+ description: "Widget kind. Use data-chart for a chart, data-table for a table, or data-insights for a combined summary/chart/table card.",
668
+ },
669
+ widgetId: {
670
+ type: "string",
671
+ description: "Optional stable widget identifier.",
672
+ },
673
+ title: {
674
+ type: "string",
675
+ description: "Optional widget title.",
676
+ },
677
+ summary: {
678
+ type: "object",
679
+ description: "Optional scalar summary values for data-insights cards.",
680
+ },
681
+ display: {
682
+ type: "object",
683
+ description: "Optional display metadata: title, description, primaryAction.",
684
+ },
685
+ table: {
686
+ type: "object",
687
+ description: "For data-table/data-insights: { title?, columns: [{ key, label, align? }], rows, totalRows?, sampledRows?, truncated? }.",
688
+ },
689
+ chartSeries: {
690
+ type: "object",
691
+ description: "For data-chart/data-insights: { type: 'bar'|'line'|'area', title?, xKey, series: [{ key, label, color? }], data, sampled? }.",
692
+ },
693
+ },
694
+ required: ["widget"],
695
+ },
696
+ },
697
+ run: async (args) => dataWidgetResultSchema.parse(args),
698
+ },
699
+ };
700
+ }
646
701
  /**
647
702
  * Creates db-* tools (db-query, db-exec, db-patch, db-schema) as native tools.
648
703
  * These let the agent read and write the app's own SQL database. Scoping to
@@ -702,28 +757,7 @@ async function createDbScriptEntries() {
702
757
  }, queryMod.default, { readOnly: true }),
703
758
  "db-exec": wrapCliScript({
704
759
  description: "Write to the app's own SQL database ONLY. Runs INSERT / UPDATE / DELETE / REPLACE against the app's internal tables. For multiple related writes, pass `statements` so they run sequentially in one transaction instead of issuing several db-exec calls. Writes are auto-scoped to the current user/org, and `owner_email` / `org_id` are auto-injected on INSERT. Schema changes (CREATE/ALTER/DROP) are blocked. Never use this to backfill missing data for a read/analysis request or to create/modify users, members, roles, permissions, admin flags, or ownership; use a dedicated app action or reviewed code. IMPORTANT: This tool CANNOT write to external data sources like BigQuery, HubSpot, etc. For external services, use the appropriate template action.",
705
- parameters: {
706
- type: "object",
707
- properties: {
708
- sql: {
709
- type: "string",
710
- description: "Single INSERT / UPDATE / DELETE / REPLACE statement. Use parameterized placeholders (?) where possible.",
711
- },
712
- args: {
713
- type: "string",
714
- description: 'Optional JSON array of positional bind args for `sql`. Example: \'["published","form-123"]\'',
715
- },
716
- statements: {
717
- type: "string",
718
- description: 'Optional JSON array of write statements to execute in one transaction. Prefer this over multiple db-exec calls. Example: \'[{"sql":"INSERT INTO notes (id,title) VALUES (?,?)","args":["n1","One"]},{"sql":"UPDATE counters SET value = value + 1 WHERE key = ?","args":["notes"]}]\'',
719
- },
720
- format: {
721
- type: "string",
722
- description: 'Output format: "json" or "text" (default: text)',
723
- enum: ["json", "text"],
724
- },
725
- },
726
- },
760
+ parameters: dbExecToolParameters(),
727
761
  }, execMod.default),
728
762
  "db-patch": wrapCliScript({
729
763
  description: "Surgical patch on a large text/JSON column in the app's SQL database. Two modes: (1) text find/replace via `find`/`replace`/`edits` — best for small edits to documents, slide HTML, etc. (2) structural JSON ops via `json-ops` — STRONGLY PREFERRED when the column is JSON (dashboard configs, form schemas, slide decks) because it avoids all the brace/quote/comma surgery that text find/replace requires. Use `json-ops` to set/remove values at a JSON Pointer path, or to move/insert array items — e.g. reorder dashboard panels, add a filter, rename a field. Targets exactly one row (narrow `where` by primary key). Same per-user/org scoping as db-exec.",
@@ -1951,6 +1985,8 @@ export const _agentChatPromptSectionsForTests = (() => {
1951
1985
  frameworkCore,
1952
1986
  frameworkCoreCompact,
1953
1987
  frameworkContextSections: FRAMEWORK_CONTEXT_SECTIONS,
1988
+ generateActionsPrompt,
1989
+ createDataWidgetActionEntries,
1954
1990
  };
1955
1991
  })();
1956
1992
  /**
@@ -2137,10 +2173,13 @@ function generateActionsPrompt(registry, mode = "tool") {
2137
2173
  if (!registry || Object.keys(registry).length === 0)
2138
2174
  return "";
2139
2175
  const actionEntries = Object.entries(registry);
2176
+ const nativeWidgetNote = (entry) => entry.chatUI && typeof entry.chatUI.renderer === "string"
2177
+ ? ` Native chat widget: \`${entry.chatUI.renderer}\`.`
2178
+ : "";
2140
2179
  if (mode === "tool") {
2141
2180
  const summaryLines = actionEntries.map(([name, entry]) => {
2142
2181
  const desc = compactPromptLine(entry.tool.description, MAX_ACTION_SUMMARY_DESCRIPTION_CHARS);
2143
- return `- \`${name}\` — ${desc}`;
2182
+ return `- \`${name}\` — ${desc}${nativeWidgetNote(entry)}`;
2144
2183
  });
2145
2184
  return `\n\n## Available Actions
2146
2185
 
@@ -2154,7 +2193,7 @@ ${summaryLines.join("\n")}`;
2154
2193
  const requiredFields = new Set(entry.tool.parameters?.required ?? []);
2155
2194
  // CLI mode: emit `pnpm action <name> --required <type> [--optional <type>]`
2156
2195
  if (!params || Object.keys(params).length === 0) {
2157
- return `- \`pnpm action ${name}\` — ${desc}`;
2196
+ return `- \`pnpm action ${name}\` — ${desc}${nativeWidgetNote(entry)}`;
2158
2197
  }
2159
2198
  const entries = Object.entries(params);
2160
2199
  // Required first (alphabetical), then optional (alphabetical)
@@ -2181,7 +2220,7 @@ ${summaryLines.join("\n")}`;
2181
2220
  }
2182
2221
  const cmd = ["pnpm action " + name, ...required, ...optional].join(" ");
2183
2222
  const requiredNote = requiredNames.length > 0 ? ` Required: ${requiredNames.join(", ")}.` : "";
2184
- return `- \`${cmd}\` — ${desc}.${requiredNote}`;
2223
+ return `- \`${cmd}\` — ${desc}.${requiredNote}${nativeWidgetNote(entry)}`;
2185
2224
  });
2186
2225
  return `\n\n## Available Actions
2187
2226
 
@@ -2749,10 +2788,13 @@ export function createAgentChatPlugin(options) {
2749
2788
  workspaceFilesTool = createWorkspaceFilesTool();
2750
2789
  }
2751
2790
  catch { }
2752
- let toolActions = {};
2791
+ let toolActions = createDataWidgetActionEntries();
2753
2792
  try {
2754
2793
  const { createExtensionActionEntries } = await import("../extensions/actions.js");
2755
- toolActions = createExtensionActionEntries();
2794
+ toolActions = {
2795
+ ...toolActions,
2796
+ ...createExtensionActionEntries(),
2797
+ };
2756
2798
  }
2757
2799
  catch { }
2758
2800
  let browserSessionTools = {};