@anuma/sdk 6.39.0 → 6.39.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.
@@ -1177,15 +1177,17 @@ Build ONLY when the user gives an explicit instruction to build, create, generat
1177
1177
 
1178
1178
  Once the user HAS given an explicit build instruction, you are in App Builder mode: you produce polished, production-quality React apps that feel designed \u2014 not generic.
1179
1179
 
1180
- DESIGN: on the initial build, before writing code, briefly state (2-3 sentences) what you want this app to feel like \u2014 name the specific fonts, the palette in hex, and one signature detail. Be concrete: "Fraunces display + Inter body + JetBrains Mono metadata, terracotta #b75432 accent on bone #f3efe6, paper-grain texture via inline SVG noise" is the kind of specificity that anchors the build. Default to nothing: don't pick "safe modern productivity" unless the brief literally asks for utilitarian. On later turns, state a design brief only when the change is visual (a restyle, new theme, or new UI); for a logic, data, or behavior-only change, skip the brief and just make the change.
1180
+ DESIGN: on the initial build, before writing code, briefly state (2-3 sentences) what you want this app to feel like \u2014 name the specific fonts, the palette in hex, and one signature detail. Be concrete: "Fraunces display + Inter body + JetBrains Mono metadata, terracotta #b75432 accent on bone #f3efe6, paper-grain texture via inline SVG noise" is the kind of specificity that anchors the build. Default to nothing: don't pick "safe modern productivity" unless the brief literally asks for utilitarian. On later turns, state a design brief only when the change is visual (a restyle, new theme, or new UI); for a text, logic, data, or behavior-only change, skip the brief and just make the change.
1181
+
1182
+ EDIT SCOPE: Change only the files and lines required by the current user request. A title rename is a text edit, not a design change. Preserve styles, dependencies, and unrelated logic on text edits. Design feedback does not authorize unrelated edits.
1181
1183
 
1182
1184
  WORKFLOW:
1183
1185
  1. NEVER output code as text or markdown. ALWAYS use tools.
1184
1186
  2. Initial build: state your design brief, then create_file with a "files" array writing ALL files in one call. The preview renders automatically.
1185
1187
  3. patch_file requires read_file for that path earlier in the conversation (or create_file in the same conversation, which counts). read_file output is numbered "42: <text>" \u2014 the prefix is display-only; never copy it into "find". Each "find" must match exactly one location \u2014 include 2-3 lines of surrounding context. Pass multiple patches per call to change distinct locations.
1186
1188
  4. Prefer patch_file for changes to existing files \u2014 surgical, reviewable, preserves surrounding code. Reserve create_file overwrites for substantial restructuring. Inserts: find the line before, replace with that line + the new line. Deletes: empty replace.
1187
- 5. After substantial changes, call critique_design first (taste, hierarchy, distinctiveness, weakest decision) and then audit_design (mechanical: tokens, focus states, aria-labels, alt, heading order). Patch what each surfaces. critique catches taste issues no checklist would; audit catches mechanics you'd miss. Run both; act on both.
1188
- 6. Before declaring done, call verify_app. The host's preview runtime reports whether your app actually mounted and surfaces any errors it captured \u2014 hallucinated imports, syntax the bundler rejected, undefined components, runtime crashes. If \`rendered\` is false or \`errors\` is non-empty, fix every error before the next message. If the response includes a \`note\` that verify_app isn't wired in this host, skip \u2014 audit + critique are your feedback in that case.
1189
+ 5. On the initial build, when adding new UI, or after user-requested design changes, call critique_design first and then audit_design. Critique checks taste, hierarchy, and distinctiveness. Audit checks tokens, focus states, aria-labels, alt text, and heading order. Patch only issues within the current user request. For text, logic, or data edits, skip both design tools.
1190
+ 6. Before declaring done, call verify_app. The host's preview runtime reports whether your app actually mounted and surfaces any errors it captured \u2014 hallucinated imports, syntax the bundler rejected, undefined components, runtime crashes. If \`rendered\` is false or \`errors\` is non-empty, fix every error before the next message. If the response includes a \`note\` that verify_app isn't wired in this host, skip runtime verification. An unavailable runtime verifier does not authorize design changes. Use audit_design and critique_design only for the initial build, adding new UI, or user-requested design changes.
1189
1191
  7. Keep responses to a sentence or two. Exception: when responding to critique_design, write a substantive paragraph per rubric question.
1190
1192
 
1191
1193
  STRUCTURE:
@@ -1529,12 +1531,13 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
1529
1531
  if (!cache) return true;
1530
1532
  return Date.now() - cache.timestamp > expirationMs;
1531
1533
  }
1532
- function buildCacheEntry(tools, checksum) {
1534
+ function buildCacheEntry(tools, checksum, etag) {
1533
1535
  return {
1534
1536
  tools,
1535
1537
  timestamp: Date.now(),
1536
1538
  version: CACHE_VERSION,
1537
- ...checksum && { checksum }
1539
+ ...checksum && { checksum },
1540
+ ...etag && { etag }
1538
1541
  };
1539
1542
  }
1540
1543
  function writeLocalStorageCache(entry) {
@@ -1569,19 +1572,36 @@ function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
1569
1572
  const cachedChecksum = getToolsChecksum(cache);
1570
1573
  return cachedChecksum instanceof Promise ? cachedChecksum.then(decide) : decide(cachedChecksum);
1571
1574
  }
1572
- async function fetchServerToolsFromApi(baseUrl, token) {
1573
- const response = await fetch(`${baseUrl}/api/v1/tools`, {
1575
+ async function fetchServerToolsFromApi(baseUrl, authHeaders, etag) {
1576
+ const request = (validator) => fetch(`${baseUrl}/api/v1/tools`, {
1574
1577
  method: "GET",
1575
1578
  headers: {
1576
- Authorization: `Bearer ${token}`,
1577
- "Content-Type": "application/json"
1579
+ ...authHeaders,
1580
+ "Content-Type": "application/json",
1581
+ ...validator && { "If-None-Match": validator }
1578
1582
  }
1579
1583
  });
1584
+ let response;
1585
+ try {
1586
+ response = await request(etag);
1587
+ } catch (error) {
1588
+ if (!etag || !(error instanceof TypeError)) throw error;
1589
+ etag = void 0;
1590
+ response = await request();
1591
+ }
1592
+ if (etag && response.status === 304) {
1593
+ return { notModified: true };
1594
+ }
1580
1595
  if (!response.ok) {
1581
1596
  throw new Error(`Failed to fetch server tools: ${response.status}`);
1582
1597
  }
1583
1598
  const data = await response.json();
1584
- return convertServerToolsResponse(data);
1599
+ const responseEtag = response.headers?.get("ETag") ?? void 0;
1600
+ return {
1601
+ notModified: false,
1602
+ ...convertServerToolsResponse(data),
1603
+ ...responseEtag && { etag: responseEtag }
1604
+ };
1585
1605
  }
1586
1606
  async function getServerTools(options) {
1587
1607
  const {
@@ -1613,34 +1633,30 @@ async function getServerTools(options) {
1613
1633
  try {
1614
1634
  const { BASE_URL: BASE_URL2 } = await Promise.resolve().then(() => (init_clientConfig(), clientConfig_exports));
1615
1635
  const effectiveBaseUrl = baseUrl ?? BASE_URL2;
1636
+ const validator = cached && !forceRefresh ? cached.etag : void 0;
1637
+ let authHeaders;
1616
1638
  if (apiKey) {
1617
- const response = await fetch(`${effectiveBaseUrl}/api/v1/tools`, {
1618
- method: "GET",
1619
- headers: {
1620
- "X-API-Key": apiKey,
1621
- "Content-Type": "application/json"
1622
- }
1623
- });
1624
- if (!response.ok) {
1625
- throw new Error(`Failed to fetch server tools: ${response.status}`);
1639
+ authHeaders = { "X-API-Key": apiKey };
1640
+ } else {
1641
+ if (!getToken) {
1642
+ getLogger().warn("[serverTools] No auth method available for fetching tools");
1643
+ return cached?.tools ?? [];
1626
1644
  }
1627
- const data = await response.json();
1628
- const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
1629
- await persistCache(buildCacheEntry(tools2, checksum2));
1630
- return tools2;
1631
- }
1632
- if (!getToken) {
1633
- getLogger().warn("[serverTools] No auth method available for fetching tools");
1634
- return cached?.tools ?? [];
1645
+ const token = await getToken();
1646
+ if (!token) {
1647
+ getLogger().warn("[serverTools] No auth token available for fetching tools");
1648
+ return cached?.tools ?? [];
1649
+ }
1650
+ authHeaders = { Authorization: `Bearer ${token}` };
1635
1651
  }
1636
- const token = await getToken();
1637
- if (!token) {
1638
- getLogger().warn("[serverTools] No auth token available for fetching tools");
1639
- return cached?.tools ?? [];
1652
+ const result = await fetchServerToolsFromApi(effectiveBaseUrl, authHeaders, validator);
1653
+ if (result.notModified) {
1654
+ const confirmed = cached;
1655
+ await persistCache({ ...confirmed, timestamp: Date.now() });
1656
+ return confirmed.tools;
1640
1657
  }
1641
- const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
1642
- await persistCache(buildCacheEntry(tools, checksum));
1643
- return tools;
1658
+ await persistCache(buildCacheEntry(result.tools, result.checksum, result.etag));
1659
+ return result.tools;
1644
1660
  } catch (error) {
1645
1661
  getLogger().error("[serverTools] Failed to fetch server tools:", error);
1646
1662
  if (cached?.tools) {
@@ -141,6 +141,8 @@ interface CachedServerTools {
141
141
  version: string;
142
142
  /** Checksum from the server for cache invalidation */
143
143
  checksum?: string;
144
+ /** ETag from the server. The next refresh sends it in an If-None-Match header. */
145
+ etag?: string;
144
146
  }
145
147
  /**
146
148
  * Pluggable persistence for the fetched server-tools list.
@@ -257,7 +259,9 @@ declare function shouldRefreshTools(responseChecksum: string | undefined, cache:
257
259
  * Flow:
258
260
  * 1. Check the cache backend (localStorage by default; override via `cache`)
259
261
  * 2. If cache valid and not force refresh, return cached tools
260
- * 3. Otherwise, fetch from API, cache, and return
262
+ * 3. Otherwise, fetch from API, cache, and return. When the cache holds an ETag,
263
+ * the request sends If-None-Match. On 304 the cached tools stay and only the
264
+ * stored timestamp changes.
261
265
  * 4. On fetch failure, return cached tools if available (stale-while-error)
262
266
  */
263
267
  declare function getServerTools(options: ServerToolsOptions): Promise<ServerTool[]>;
@@ -141,6 +141,8 @@ interface CachedServerTools {
141
141
  version: string;
142
142
  /** Checksum from the server for cache invalidation */
143
143
  checksum?: string;
144
+ /** ETag from the server. The next refresh sends it in an If-None-Match header. */
145
+ etag?: string;
144
146
  }
145
147
  /**
146
148
  * Pluggable persistence for the fetched server-tools list.
@@ -257,7 +259,9 @@ declare function shouldRefreshTools(responseChecksum: string | undefined, cache:
257
259
  * Flow:
258
260
  * 1. Check the cache backend (localStorage by default; override via `cache`)
259
261
  * 2. If cache valid and not force refresh, return cached tools
260
- * 3. Otherwise, fetch from API, cache, and return
262
+ * 3. Otherwise, fetch from API, cache, and return. When the cache holds an ETag,
263
+ * the request sends If-None-Match. On 304 the cached tools stay and only the
264
+ * stored timestamp changes.
261
265
  * 4. On fetch failure, return cached tools if available (stale-while-error)
262
266
  */
263
267
  declare function getServerTools(options: ServerToolsOptions): Promise<ServerTool[]>;
@@ -1055,15 +1055,17 @@ Build ONLY when the user gives an explicit instruction to build, create, generat
1055
1055
 
1056
1056
  Once the user HAS given an explicit build instruction, you are in App Builder mode: you produce polished, production-quality React apps that feel designed \u2014 not generic.
1057
1057
 
1058
- DESIGN: on the initial build, before writing code, briefly state (2-3 sentences) what you want this app to feel like \u2014 name the specific fonts, the palette in hex, and one signature detail. Be concrete: "Fraunces display + Inter body + JetBrains Mono metadata, terracotta #b75432 accent on bone #f3efe6, paper-grain texture via inline SVG noise" is the kind of specificity that anchors the build. Default to nothing: don't pick "safe modern productivity" unless the brief literally asks for utilitarian. On later turns, state a design brief only when the change is visual (a restyle, new theme, or new UI); for a logic, data, or behavior-only change, skip the brief and just make the change.
1058
+ DESIGN: on the initial build, before writing code, briefly state (2-3 sentences) what you want this app to feel like \u2014 name the specific fonts, the palette in hex, and one signature detail. Be concrete: "Fraunces display + Inter body + JetBrains Mono metadata, terracotta #b75432 accent on bone #f3efe6, paper-grain texture via inline SVG noise" is the kind of specificity that anchors the build. Default to nothing: don't pick "safe modern productivity" unless the brief literally asks for utilitarian. On later turns, state a design brief only when the change is visual (a restyle, new theme, or new UI); for a text, logic, data, or behavior-only change, skip the brief and just make the change.
1059
+
1060
+ EDIT SCOPE: Change only the files and lines required by the current user request. A title rename is a text edit, not a design change. Preserve styles, dependencies, and unrelated logic on text edits. Design feedback does not authorize unrelated edits.
1059
1061
 
1060
1062
  WORKFLOW:
1061
1063
  1. NEVER output code as text or markdown. ALWAYS use tools.
1062
1064
  2. Initial build: state your design brief, then create_file with a "files" array writing ALL files in one call. The preview renders automatically.
1063
1065
  3. patch_file requires read_file for that path earlier in the conversation (or create_file in the same conversation, which counts). read_file output is numbered "42: <text>" \u2014 the prefix is display-only; never copy it into "find". Each "find" must match exactly one location \u2014 include 2-3 lines of surrounding context. Pass multiple patches per call to change distinct locations.
1064
1066
  4. Prefer patch_file for changes to existing files \u2014 surgical, reviewable, preserves surrounding code. Reserve create_file overwrites for substantial restructuring. Inserts: find the line before, replace with that line + the new line. Deletes: empty replace.
1065
- 5. After substantial changes, call critique_design first (taste, hierarchy, distinctiveness, weakest decision) and then audit_design (mechanical: tokens, focus states, aria-labels, alt, heading order). Patch what each surfaces. critique catches taste issues no checklist would; audit catches mechanics you'd miss. Run both; act on both.
1066
- 6. Before declaring done, call verify_app. The host's preview runtime reports whether your app actually mounted and surfaces any errors it captured \u2014 hallucinated imports, syntax the bundler rejected, undefined components, runtime crashes. If \`rendered\` is false or \`errors\` is non-empty, fix every error before the next message. If the response includes a \`note\` that verify_app isn't wired in this host, skip \u2014 audit + critique are your feedback in that case.
1067
+ 5. On the initial build, when adding new UI, or after user-requested design changes, call critique_design first and then audit_design. Critique checks taste, hierarchy, and distinctiveness. Audit checks tokens, focus states, aria-labels, alt text, and heading order. Patch only issues within the current user request. For text, logic, or data edits, skip both design tools.
1068
+ 6. Before declaring done, call verify_app. The host's preview runtime reports whether your app actually mounted and surfaces any errors it captured \u2014 hallucinated imports, syntax the bundler rejected, undefined components, runtime crashes. If \`rendered\` is false or \`errors\` is non-empty, fix every error before the next message. If the response includes a \`note\` that verify_app isn't wired in this host, skip runtime verification. An unavailable runtime verifier does not authorize design changes. Use audit_design and critique_design only for the initial build, adding new UI, or user-requested design changes.
1067
1069
  7. Keep responses to a sentence or two. Exception: when responding to critique_design, write a substantive paragraph per rubric question.
1068
1070
 
1069
1071
  STRUCTURE:
@@ -1407,12 +1409,13 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
1407
1409
  if (!cache) return true;
1408
1410
  return Date.now() - cache.timestamp > expirationMs;
1409
1411
  }
1410
- function buildCacheEntry(tools, checksum) {
1412
+ function buildCacheEntry(tools, checksum, etag) {
1411
1413
  return {
1412
1414
  tools,
1413
1415
  timestamp: Date.now(),
1414
1416
  version: CACHE_VERSION,
1415
- ...checksum && { checksum }
1417
+ ...checksum && { checksum },
1418
+ ...etag && { etag }
1416
1419
  };
1417
1420
  }
1418
1421
  function writeLocalStorageCache(entry) {
@@ -1447,19 +1450,36 @@ function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
1447
1450
  const cachedChecksum = getToolsChecksum(cache);
1448
1451
  return cachedChecksum instanceof Promise ? cachedChecksum.then(decide) : decide(cachedChecksum);
1449
1452
  }
1450
- async function fetchServerToolsFromApi(baseUrl, token) {
1451
- const response = await fetch(`${baseUrl}/api/v1/tools`, {
1453
+ async function fetchServerToolsFromApi(baseUrl, authHeaders, etag) {
1454
+ const request = (validator) => fetch(`${baseUrl}/api/v1/tools`, {
1452
1455
  method: "GET",
1453
1456
  headers: {
1454
- Authorization: `Bearer ${token}`,
1455
- "Content-Type": "application/json"
1457
+ ...authHeaders,
1458
+ "Content-Type": "application/json",
1459
+ ...validator && { "If-None-Match": validator }
1456
1460
  }
1457
1461
  });
1462
+ let response;
1463
+ try {
1464
+ response = await request(etag);
1465
+ } catch (error) {
1466
+ if (!etag || !(error instanceof TypeError)) throw error;
1467
+ etag = void 0;
1468
+ response = await request();
1469
+ }
1470
+ if (etag && response.status === 304) {
1471
+ return { notModified: true };
1472
+ }
1458
1473
  if (!response.ok) {
1459
1474
  throw new Error(`Failed to fetch server tools: ${response.status}`);
1460
1475
  }
1461
1476
  const data = await response.json();
1462
- return convertServerToolsResponse(data);
1477
+ const responseEtag = response.headers?.get("ETag") ?? void 0;
1478
+ return {
1479
+ notModified: false,
1480
+ ...convertServerToolsResponse(data),
1481
+ ...responseEtag && { etag: responseEtag }
1482
+ };
1463
1483
  }
1464
1484
  async function getServerTools(options) {
1465
1485
  const {
@@ -1491,34 +1511,30 @@ async function getServerTools(options) {
1491
1511
  try {
1492
1512
  const { BASE_URL: BASE_URL2 } = await import("./clientConfig-WITO4T6L.mjs");
1493
1513
  const effectiveBaseUrl = baseUrl ?? BASE_URL2;
1514
+ const validator = cached && !forceRefresh ? cached.etag : void 0;
1515
+ let authHeaders;
1494
1516
  if (apiKey) {
1495
- const response = await fetch(`${effectiveBaseUrl}/api/v1/tools`, {
1496
- method: "GET",
1497
- headers: {
1498
- "X-API-Key": apiKey,
1499
- "Content-Type": "application/json"
1500
- }
1501
- });
1502
- if (!response.ok) {
1503
- throw new Error(`Failed to fetch server tools: ${response.status}`);
1517
+ authHeaders = { "X-API-Key": apiKey };
1518
+ } else {
1519
+ if (!getToken) {
1520
+ getLogger().warn("[serverTools] No auth method available for fetching tools");
1521
+ return cached?.tools ?? [];
1504
1522
  }
1505
- const data = await response.json();
1506
- const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
1507
- await persistCache(buildCacheEntry(tools2, checksum2));
1508
- return tools2;
1509
- }
1510
- if (!getToken) {
1511
- getLogger().warn("[serverTools] No auth method available for fetching tools");
1512
- return cached?.tools ?? [];
1523
+ const token = await getToken();
1524
+ if (!token) {
1525
+ getLogger().warn("[serverTools] No auth token available for fetching tools");
1526
+ return cached?.tools ?? [];
1527
+ }
1528
+ authHeaders = { Authorization: `Bearer ${token}` };
1513
1529
  }
1514
- const token = await getToken();
1515
- if (!token) {
1516
- getLogger().warn("[serverTools] No auth token available for fetching tools");
1517
- return cached?.tools ?? [];
1530
+ const result = await fetchServerToolsFromApi(effectiveBaseUrl, authHeaders, validator);
1531
+ if (result.notModified) {
1532
+ const confirmed = cached;
1533
+ await persistCache({ ...confirmed, timestamp: Date.now() });
1534
+ return confirmed.tools;
1518
1535
  }
1519
- const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
1520
- await persistCache(buildCacheEntry(tools, checksum));
1521
- return tools;
1536
+ await persistCache(buildCacheEntry(result.tools, result.checksum, result.etag));
1537
+ return result.tools;
1522
1538
  } catch (error) {
1523
1539
  getLogger().error("[serverTools] Failed to fetch server tools:", error);
1524
1540
  if (cached?.tools) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.39.0",
3
+ "version": "6.39.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",