@anuma/sdk 6.38.0 → 6.39.1

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.mjs CHANGED
@@ -3056,15 +3056,17 @@ Build ONLY when the user gives an explicit instruction to build, create, generat
3056
3056
 
3057
3057
  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.
3058
3058
 
3059
- 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.
3059
+ 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.
3060
+
3061
+ 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.
3060
3062
 
3061
3063
  WORKFLOW:
3062
3064
  1. NEVER output code as text or markdown. ALWAYS use tools.
3063
3065
  2. Initial build: state your design brief, then create_file with a "files" array writing ALL files in one call. The preview renders automatically.
3064
3066
  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.
3065
3067
  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.
3066
- 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.
3067
- 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.
3068
+ 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.
3069
+ 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.
3068
3070
  7. Keep responses to a sentence or two. Exception: when responding to critique_design, write a substantive paragraph per rubric question.
3069
3071
 
3070
3072
  STRUCTURE:
@@ -3227,12 +3229,13 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
3227
3229
  if (!cache) return true;
3228
3230
  return Date.now() - cache.timestamp > expirationMs;
3229
3231
  }
3230
- function buildCacheEntry(tools, checksum) {
3232
+ function buildCacheEntry(tools, checksum, etag) {
3231
3233
  return {
3232
3234
  tools,
3233
3235
  timestamp: Date.now(),
3234
3236
  version: CACHE_VERSION,
3235
- ...checksum && { checksum }
3237
+ ...checksum && { checksum },
3238
+ ...etag && { etag }
3236
3239
  };
3237
3240
  }
3238
3241
  function writeLocalStorageCache(entry) {
@@ -3252,19 +3255,36 @@ var localStorageToolsCache = {
3252
3255
  set: writeLocalStorageCache,
3253
3256
  clear: removeLocalStorageCache
3254
3257
  };
3255
- async function fetchServerToolsFromApi(baseUrl, token) {
3256
- const response = await fetch(`${baseUrl}/api/v1/tools`, {
3258
+ async function fetchServerToolsFromApi(baseUrl, authHeaders, etag) {
3259
+ const request = (validator) => fetch(`${baseUrl}/api/v1/tools`, {
3257
3260
  method: "GET",
3258
3261
  headers: {
3259
- Authorization: `Bearer ${token}`,
3260
- "Content-Type": "application/json"
3262
+ ...authHeaders,
3263
+ "Content-Type": "application/json",
3264
+ ...validator && { "If-None-Match": validator }
3261
3265
  }
3262
3266
  });
3267
+ let response;
3268
+ try {
3269
+ response = await request(etag);
3270
+ } catch (error) {
3271
+ if (!etag || !(error instanceof TypeError)) throw error;
3272
+ etag = void 0;
3273
+ response = await request();
3274
+ }
3275
+ if (etag && response.status === 304) {
3276
+ return { notModified: true };
3277
+ }
3263
3278
  if (!response.ok) {
3264
3279
  throw new Error(`Failed to fetch server tools: ${response.status}`);
3265
3280
  }
3266
3281
  const data = await response.json();
3267
- return convertServerToolsResponse(data);
3282
+ const responseEtag = response.headers?.get("ETag") ?? void 0;
3283
+ return {
3284
+ notModified: false,
3285
+ ...convertServerToolsResponse(data),
3286
+ ...responseEtag && { etag: responseEtag }
3287
+ };
3268
3288
  }
3269
3289
  async function getServerTools(options) {
3270
3290
  const {
@@ -3296,34 +3316,30 @@ async function getServerTools(options) {
3296
3316
  try {
3297
3317
  const { BASE_URL: BASE_URL2 } = await import("./clientConfig-WITO4T6L.mjs");
3298
3318
  const effectiveBaseUrl = baseUrl ?? BASE_URL2;
3319
+ const validator = cached && !forceRefresh ? cached.etag : void 0;
3320
+ let authHeaders;
3299
3321
  if (apiKey) {
3300
- const response = await fetch(`${effectiveBaseUrl}/api/v1/tools`, {
3301
- method: "GET",
3302
- headers: {
3303
- "X-API-Key": apiKey,
3304
- "Content-Type": "application/json"
3305
- }
3306
- });
3307
- if (!response.ok) {
3308
- throw new Error(`Failed to fetch server tools: ${response.status}`);
3322
+ authHeaders = { "X-API-Key": apiKey };
3323
+ } else {
3324
+ if (!getToken) {
3325
+ getLogger().warn("[serverTools] No auth method available for fetching tools");
3326
+ return cached?.tools ?? [];
3309
3327
  }
3310
- const data = await response.json();
3311
- const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
3312
- await persistCache(buildCacheEntry(tools2, checksum2));
3313
- return tools2;
3314
- }
3315
- if (!getToken) {
3316
- getLogger().warn("[serverTools] No auth method available for fetching tools");
3317
- return cached?.tools ?? [];
3328
+ const token = await getToken();
3329
+ if (!token) {
3330
+ getLogger().warn("[serverTools] No auth token available for fetching tools");
3331
+ return cached?.tools ?? [];
3332
+ }
3333
+ authHeaders = { Authorization: `Bearer ${token}` };
3318
3334
  }
3319
- const token = await getToken();
3320
- if (!token) {
3321
- getLogger().warn("[serverTools] No auth token available for fetching tools");
3322
- return cached?.tools ?? [];
3335
+ const result = await fetchServerToolsFromApi(effectiveBaseUrl, authHeaders, validator);
3336
+ if (result.notModified) {
3337
+ const confirmed = cached;
3338
+ await persistCache({ ...confirmed, timestamp: Date.now() });
3339
+ return confirmed.tools;
3323
3340
  }
3324
- const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
3325
- await persistCache(buildCacheEntry(tools, checksum));
3326
- return tools;
3341
+ await persistCache(buildCacheEntry(result.tools, result.checksum, result.etag));
3342
+ return result.tools;
3327
3343
  } catch (error) {
3328
3344
  getLogger().error("[serverTools] Failed to fetch server tools:", error);
3329
3345
  if (cached?.tools) {