@anuma/sdk 11.0.1 → 11.2.0

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.
@@ -2346,9 +2346,9 @@ function createDisplayTool(options, config) {
2346
2346
  description: config.description,
2347
2347
  arguments: config.parameters
2348
2348
  },
2349
- executor: async (args) => {
2349
+ executor: async (args, _signal, execution) => {
2350
2350
  const result = await Promise.resolve(config.execute(args));
2351
- const context = options.getContext();
2351
+ const context = execution?.detached ? null : options.getContext();
2352
2352
  if (context) {
2353
2353
  const interactionId = generateInteractionId(config.displayType);
2354
2354
  const replacesInteractionId = config.getReplacesInteractionId?.(args);
@@ -2363,11 +2363,22 @@ function createDisplayTool(options, config) {
2363
2363
  }
2364
2364
  return result;
2365
2365
  },
2366
- skipContinuation: true
2366
+ skipContinuation: true,
2367
+ detachedClass: "render"
2367
2368
  };
2368
2369
  }
2369
2370
 
2370
2371
  // src/tools/chart.ts
2372
+ var VALUE_FORMATS = ["number", "currency", "percent"];
2373
+ var CURRENCY_CODE = /^[A-Z]{3}$/;
2374
+ function toValueFormat(value) {
2375
+ return VALUE_FORMATS.find((format) => format === value);
2376
+ }
2377
+ function toCurrencyCode(value) {
2378
+ if (typeof value !== "string") return void 0;
2379
+ const code = value.trim().toUpperCase();
2380
+ return CURRENCY_CODE.test(code) ? code : void 0;
2381
+ }
2371
2382
  var NUMERIC_STRING = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;
2372
2383
  var THOUSANDS_GROUPED = /^[-+]?\d{1,3}(?:,\d{3})+(?:\.\d*)?$/;
2373
2384
  function toNumber(value) {
@@ -2384,7 +2395,7 @@ function toNumber(value) {
2384
2395
  function createChartTool(options) {
2385
2396
  return createDisplayTool(options, {
2386
2397
  name: "display_chart",
2387
- description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory.',
2398
+ description: 'Render a bar, line, area, or pie chart inline \u2014 visualize data, plot a trend over time, or graph a comparison. Use whenever the user asks to chart, plot, graph, or visualize numbers (sales, prices, temperatures, metrics). You MUST pass the actual numeric values in the "data" array \u2014 they are never inferred. Do not chart price or market history (crypto, stocks, market caps) unless those values came from a tool result or a cited source earlier in this conversation; never fill a price series from memory. Set valueFormat to "currency" for prices and money, or "percent" for percentage values.',
2388
2399
  parameters: {
2389
2400
  type: "object",
2390
2401
  properties: {
@@ -2418,6 +2429,15 @@ function createChartTool(options) {
2418
2429
  type: "object",
2419
2430
  additionalProperties: { type: "string" },
2420
2431
  description: "Optional color overrides. Map of dataKey to CSS color value (e.g. { 'revenue': '#2563eb' }). If omitted, uses theme chart colors."
2432
+ },
2433
+ valueFormat: {
2434
+ type: "string",
2435
+ enum: ["number", "currency", "percent"],
2436
+ description: 'How to display the values on the axis, tooltip and headline. "currency" for prices and money (set currency too), "percent" when values are already percentages (3.2 means 3.2%). Defaults to "number".'
2437
+ },
2438
+ currency: {
2439
+ type: "string",
2440
+ description: 'ISO 4217 currency code used when valueFormat is "currency", e.g. "USD" or "EUR". Defaults to USD.'
2421
2441
  }
2422
2442
  },
2423
2443
  required: ["chartType", "data", "dataKeys"]
@@ -2469,7 +2489,9 @@ function createChartTool(options) {
2469
2489
  data: points,
2470
2490
  dataKeys,
2471
2491
  xAxisKey: args.xAxisKey,
2472
- colors: args.colors
2492
+ colors: args.colors,
2493
+ valueFormat: toValueFormat(args.valueFormat),
2494
+ currency: toCurrencyCode(args.currency)
2473
2495
  };
2474
2496
  }
2475
2497
  });
@@ -5,7 +5,13 @@ type LlmapiChatCompletionTool = {
5
5
  /**
6
6
  * Tool executor function type
7
7
  */
8
- type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
8
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal, context?: ToolExecutionContext) => Promise<unknown> | unknown;
9
+ /** How the portal treats a call to this device tool while the device is away. */
10
+ type DetachedToolClass = "render" | "deferred";
11
+ /** Context for one executor run; `detached` marks a call from an answer finished while the device was away. */
12
+ type ToolExecutionContext = {
13
+ detached?: boolean;
14
+ };
9
15
  /**
10
16
  * Tool configuration with optional executor
11
17
  */
@@ -75,6 +81,8 @@ type ToolConfig = LlmapiChatCompletionTool & {
75
81
  * files from IndexedDB that `create_file` writes.
76
82
  */
77
83
  dependsOn?: string[];
84
+ /** How the portal handles a call to this tool while the device is away; unset tools pause the turn. */
85
+ detachedClass?: DetachedToolClass;
78
86
  };
79
87
 
80
88
  /** Tool parameters schema */
@@ -5,7 +5,13 @@ type LlmapiChatCompletionTool = {
5
5
  /**
6
6
  * Tool executor function type
7
7
  */
8
- type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal) => Promise<unknown> | unknown;
8
+ type ToolExecutor = (args: Record<string, unknown>, signal?: AbortSignal, context?: ToolExecutionContext) => Promise<unknown> | unknown;
9
+ /** How the portal treats a call to this device tool while the device is away. */
10
+ type DetachedToolClass = "render" | "deferred";
11
+ /** Context for one executor run; `detached` marks a call from an answer finished while the device was away. */
12
+ type ToolExecutionContext = {
13
+ detached?: boolean;
14
+ };
9
15
  /**
10
16
  * Tool configuration with optional executor
11
17
  */
@@ -75,6 +81,8 @@ type ToolConfig = LlmapiChatCompletionTool & {
75
81
  * files from IndexedDB that `create_file` writes.
76
82
  */
77
83
  dependsOn?: string[];
84
+ /** How the portal handles a call to this tool while the device is away; unset tools pause the turn. */
85
+ detachedClass?: DetachedToolClass;
78
86
  };
79
87
 
80
88
  /** Tool parameters schema */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "11.0.1",
3
+ "version": "11.2.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",