@tangle-network/agent-app 0.60.262 → 0.60.264

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.
@@ -567,6 +567,24 @@ var TOOL_RESULT_LIMIT = 12e3;
567
567
  function routerFunctionName(name) {
568
568
  return name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64);
569
569
  }
570
+ var PER_TURN_CLOCKS = [
571
+ /\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}/,
572
+ /\b(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{4} \d{2}:\d{2}/,
573
+ /\b(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}/
574
+ ];
575
+ var MIN_REPEATED_CONTEXT = 24;
576
+ function perTurnPrefixBytes(prefix, perTurn = []) {
577
+ const found = PER_TURN_CLOCKS.flatMap((pattern) => prefix.match(pattern)?.[0] ?? []);
578
+ for (const value of perTurn) {
579
+ const trimmed = value.trim();
580
+ if (trimmed.length >= MIN_REPEATED_CONTEXT && prefix.includes(trimmed)) found.push(trimmed.slice(0, 80));
581
+ }
582
+ return found;
583
+ }
584
+ function underTestRunner() {
585
+ const env = globalThis.process?.env;
586
+ return Boolean(env && (env.VITEST || env.JEST_WORKER_ID || env.NODE_ENV === "test"));
587
+ }
570
588
  function composeRouterTurnPromptSections(profile, options = {}) {
571
589
  const knowledge = options.knowledge ? turnKnowledgeInstructions(options.knowledge.files, { readTool: options.knowledge.readTool }) : [];
572
590
  const names = [...options.toolNames ?? []].sort((a, b) => b.length - a.length);
@@ -574,15 +592,21 @@ function composeRouterTurnPromptSections(profile, options = {}) {
574
592
  (out, name) => out.split(name).join(routerFunctionName(name)),
575
593
  parts.filter((part) => part.trim()).join("\n\n")
576
594
  );
577
- const prefix = render([
595
+ const authored = [
578
596
  profile.prompt?.systemPrompt ?? "",
579
597
  profile.prompt?.appendSystemPrompt ?? "",
580
598
  ...profile.prompt?.instructions ?? [],
581
599
  replyLanguageInstruction(),
582
- ...options.stable ?? [],
583
- ...knowledge
584
- ]);
600
+ ...options.stable ?? []
601
+ ];
602
+ const prefix = render([...authored, ...knowledge]);
585
603
  const tail = render(options.context ?? []);
604
+ if (options.checkStablePrefix !== false && underTestRunner()) {
605
+ const perTurn = perTurnPrefixBytes(render(authored), (options.context ?? []).map((section) => render([section])));
606
+ if (perTurn.length) {
607
+ throw new Error(`composeRouterTurnPromptSections: the stable prefix carries per-turn bytes (${perTurn.map((value) => JSON.stringify(value)).join(", ")}); move them to \`context\` so the prompt cache serves the prefix, or pass \`checkStablePrefix: false\`.`);
608
+ }
609
+ }
586
610
  return { prefix, tail, text: [prefix, tail].filter(Boolean).join("\n\n") };
587
611
  }
588
612
  function composeRouterTurnPrompt(profile, options = {}) {
@@ -953,8 +977,9 @@ export {
953
977
  workspaceTurnCheckpoints,
954
978
  placeRouterTurn,
955
979
  routerFunctionName,
980
+ perTurnPrefixBytes,
956
981
  composeRouterTurnPromptSections,
957
982
  composeRouterTurnPrompt,
958
983
  runRouterTurn
959
984
  };
960
- //# sourceMappingURL=chunk-QTWTZYXC.js.map
985
+ //# sourceMappingURL=chunk-VJBFCNAU.js.map