@promptbook/browser 0.112.0-53 → 0.112.0-56

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 (149) hide show
  1. package/esm/index.es.js +3653 -280
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/src/_packages/cli.index.d.ts +10 -0
  4. package/esm/src/_packages/core.index.d.ts +12 -0
  5. package/esm/src/_packages/types.index.d.ts +8 -0
  6. package/esm/src/_packages/wizard.index.d.ts +10 -0
  7. package/esm/src/avatars/index.d.ts +1 -1
  8. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  9. package/esm/src/avatars/visuals/avatarVisualRegistry.d.ts +12 -0
  10. package/esm/src/avatars/visuals/orbAvatarVisual.d.ts +48 -0
  11. package/esm/src/avatars/visuals/orbAvatarVisual.test.d.ts +1 -0
  12. package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  13. package/esm/src/book-2.0/agent-source/parseAgentSourceWithCommitments.use.test.d.ts +1 -0
  14. package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.d.ts +9 -8
  15. package/esm/src/commitments/ACTION/ACTION.d.ts +8 -2
  16. package/esm/src/commitments/ACTION/ACTION.test.d.ts +1 -0
  17. package/esm/src/commitments/DELETE/DELETE.d.ts +7 -3
  18. package/esm/src/commitments/DELETE/DELETE.test.d.ts +1 -0
  19. package/esm/src/commitments/FORMAT/FORMAT.d.ts +10 -4
  20. package/esm/src/commitments/FORMAT/FORMAT.test.d.ts +1 -0
  21. package/esm/src/commitments/GOAL/GOAL.d.ts +4 -0
  22. package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
  23. package/esm/src/commitments/META/META.d.ts +2 -0
  24. package/esm/src/commitments/META_AVATAR/META_AVATAR.d.ts +26 -0
  25. package/esm/src/commitments/MODEL/MODEL.d.ts +4 -0
  26. package/esm/src/commitments/MODEL/MODEL.test.d.ts +1 -0
  27. package/esm/src/commitments/RULE/RULE.d.ts +4 -0
  28. package/esm/src/commitments/TEAM/TEAM.d.ts +4 -0
  29. package/esm/src/commitments/TEMPLATE/TEMPLATE.d.ts +10 -4
  30. package/esm/src/commitments/_base/BaseCommitmentDefinition.d.ts +12 -0
  31. package/esm/src/commitments/_base/CommitmentDefinition.d.ts +21 -1
  32. package/esm/src/commitments/_common/getAllCommitmentDefinitions.test.d.ts +1 -0
  33. package/esm/src/commitments/_common/getCommitmentNoticeMetadata.d.ts +51 -0
  34. package/esm/src/commitments/_common/getCommitmentNoticeMetadata.test.d.ts +1 -0
  35. package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.openClosed.test.d.ts +1 -0
  36. package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.order.test.d.ts +1 -0
  37. package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.use.test.d.ts +1 -0
  38. package/esm/src/commitments/_common/sortCommitmentDefinitions.d.ts +31 -0
  39. package/esm/src/commitments/_common/teamInternalAgentAccess.d.ts +51 -0
  40. package/esm/src/commitments/_common/toolRuntimeContext.d.ts +4 -0
  41. package/esm/src/commitments/index.d.ts +2 -2
  42. package/esm/src/commitments/index.test.d.ts +1 -0
  43. package/esm/src/llm-providers/agent/Agent.d.ts +2 -0
  44. package/esm/src/llm-providers/agent/RemoteAgent.d.ts +1 -0
  45. package/esm/src/llm-providers/agent/RemoteAgentOptions.d.ts +4 -0
  46. package/esm/src/playground/playground.d.ts +1 -0
  47. package/esm/src/transpilers/_common/BookTranspilerOptions.d.ts +20 -0
  48. package/esm/src/transpilers/_common/TranspiledTeamExport.d.ts +80 -0
  49. package/esm/src/transpilers/_common/createTranspiledTeamRuntimeSection.d.ts +55 -0
  50. package/esm/src/transpilers/_common/createZodSchemaSource.d.ts +40 -0
  51. package/esm/src/transpilers/_common/formatUsedToolFunctions.d.ts +18 -0
  52. package/esm/src/transpilers/_common/formatUsedToolFunctions.test.d.ts +1 -0
  53. package/esm/src/transpilers/_common/prepareSdkTranspilerContext.d.ts +48 -0
  54. package/esm/src/transpilers/_common/resolveClaudeModelName.d.ts +12 -0
  55. package/esm/src/transpilers/_common/transpiledTeamTranspilers.test.d.ts +1 -0
  56. package/esm/src/transpilers/agent-os/AgentOsTranspiler.d.ts +16 -0
  57. package/esm/src/transpilers/agent-os/AgentOsTranspiler.test.d.ts +1 -0
  58. package/esm/src/transpilers/agent-os/register.d.ts +12 -0
  59. package/esm/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.d.ts +16 -0
  60. package/esm/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.test.d.ts +1 -0
  61. package/esm/src/transpilers/anthropic-claude-managed/register.d.ts +12 -0
  62. package/esm/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.d.ts +16 -0
  63. package/esm/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.test.d.ts +1 -0
  64. package/esm/src/transpilers/anthropic-claude-sdk/register.d.ts +12 -0
  65. package/esm/src/transpilers/e2b/E2BTranspiler.d.ts +16 -0
  66. package/esm/src/transpilers/e2b/E2BTranspiler.test.d.ts +1 -0
  67. package/esm/src/transpilers/e2b/register.d.ts +12 -0
  68. package/esm/src/transpilers/openai-agents/OpenAiAgentsTranspiler.d.ts +16 -0
  69. package/esm/src/transpilers/openai-agents/OpenAiAgentsTranspiler.test.d.ts +1 -0
  70. package/esm/src/transpilers/openai-agents/register.d.ts +12 -0
  71. package/esm/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +15 -0
  72. package/esm/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
  73. package/esm/src/version.d.ts +1 -1
  74. package/package.json +3 -3
  75. package/umd/index.umd.js +3653 -280
  76. package/umd/index.umd.js.map +1 -1
  77. package/umd/src/_packages/cli.index.d.ts +10 -0
  78. package/umd/src/_packages/core.index.d.ts +12 -0
  79. package/umd/src/_packages/types.index.d.ts +8 -0
  80. package/umd/src/_packages/wizard.index.d.ts +10 -0
  81. package/umd/src/avatars/index.d.ts +1 -1
  82. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  83. package/umd/src/avatars/visuals/avatarVisualRegistry.d.ts +12 -0
  84. package/umd/src/avatars/visuals/orbAvatarVisual.d.ts +48 -0
  85. package/umd/src/avatars/visuals/orbAvatarVisual.test.d.ts +1 -0
  86. package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
  87. package/umd/src/book-2.0/agent-source/parseAgentSourceWithCommitments.use.test.d.ts +1 -0
  88. package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.d.ts +9 -8
  89. package/umd/src/commitments/ACTION/ACTION.d.ts +8 -2
  90. package/umd/src/commitments/ACTION/ACTION.test.d.ts +1 -0
  91. package/umd/src/commitments/DELETE/DELETE.d.ts +7 -3
  92. package/umd/src/commitments/DELETE/DELETE.test.d.ts +1 -0
  93. package/umd/src/commitments/FORMAT/FORMAT.d.ts +10 -4
  94. package/umd/src/commitments/FORMAT/FORMAT.test.d.ts +1 -0
  95. package/umd/src/commitments/GOAL/GOAL.d.ts +4 -0
  96. package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
  97. package/umd/src/commitments/META/META.d.ts +2 -0
  98. package/umd/src/commitments/META_AVATAR/META_AVATAR.d.ts +26 -0
  99. package/umd/src/commitments/MODEL/MODEL.d.ts +4 -0
  100. package/umd/src/commitments/MODEL/MODEL.test.d.ts +1 -0
  101. package/umd/src/commitments/RULE/RULE.d.ts +4 -0
  102. package/umd/src/commitments/TEAM/TEAM.d.ts +4 -0
  103. package/umd/src/commitments/TEMPLATE/TEMPLATE.d.ts +10 -4
  104. package/umd/src/commitments/_base/BaseCommitmentDefinition.d.ts +12 -0
  105. package/umd/src/commitments/_base/CommitmentDefinition.d.ts +21 -1
  106. package/umd/src/commitments/_common/getAllCommitmentDefinitions.test.d.ts +1 -0
  107. package/umd/src/commitments/_common/getCommitmentNoticeMetadata.d.ts +51 -0
  108. package/umd/src/commitments/_common/getCommitmentNoticeMetadata.test.d.ts +1 -0
  109. package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.openClosed.test.d.ts +1 -0
  110. package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.order.test.d.ts +1 -0
  111. package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.use.test.d.ts +1 -0
  112. package/umd/src/commitments/_common/sortCommitmentDefinitions.d.ts +31 -0
  113. package/umd/src/commitments/_common/teamInternalAgentAccess.d.ts +51 -0
  114. package/umd/src/commitments/_common/toolRuntimeContext.d.ts +4 -0
  115. package/umd/src/commitments/index.d.ts +2 -2
  116. package/umd/src/commitments/index.test.d.ts +1 -0
  117. package/umd/src/llm-providers/agent/Agent.d.ts +2 -0
  118. package/umd/src/llm-providers/agent/RemoteAgent.d.ts +1 -0
  119. package/umd/src/llm-providers/agent/RemoteAgentOptions.d.ts +4 -0
  120. package/umd/src/playground/playground.d.ts +1 -0
  121. package/umd/src/transpilers/_common/BookTranspilerOptions.d.ts +20 -0
  122. package/umd/src/transpilers/_common/TranspiledTeamExport.d.ts +80 -0
  123. package/umd/src/transpilers/_common/createTranspiledTeamRuntimeSection.d.ts +55 -0
  124. package/umd/src/transpilers/_common/createZodSchemaSource.d.ts +40 -0
  125. package/umd/src/transpilers/_common/formatUsedToolFunctions.d.ts +18 -0
  126. package/umd/src/transpilers/_common/formatUsedToolFunctions.test.d.ts +1 -0
  127. package/umd/src/transpilers/_common/prepareSdkTranspilerContext.d.ts +48 -0
  128. package/umd/src/transpilers/_common/resolveClaudeModelName.d.ts +12 -0
  129. package/umd/src/transpilers/_common/transpiledTeamTranspilers.test.d.ts +1 -0
  130. package/umd/src/transpilers/agent-os/AgentOsTranspiler.d.ts +16 -0
  131. package/umd/src/transpilers/agent-os/AgentOsTranspiler.test.d.ts +1 -0
  132. package/umd/src/transpilers/agent-os/register.d.ts +12 -0
  133. package/umd/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.d.ts +16 -0
  134. package/umd/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.test.d.ts +1 -0
  135. package/umd/src/transpilers/anthropic-claude-managed/register.d.ts +12 -0
  136. package/umd/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.d.ts +16 -0
  137. package/umd/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.test.d.ts +1 -0
  138. package/umd/src/transpilers/anthropic-claude-sdk/register.d.ts +12 -0
  139. package/umd/src/transpilers/e2b/E2BTranspiler.d.ts +16 -0
  140. package/umd/src/transpilers/e2b/E2BTranspiler.test.d.ts +1 -0
  141. package/umd/src/transpilers/e2b/register.d.ts +12 -0
  142. package/umd/src/transpilers/openai-agents/OpenAiAgentsTranspiler.d.ts +16 -0
  143. package/umd/src/transpilers/openai-agents/OpenAiAgentsTranspiler.test.d.ts +1 -0
  144. package/umd/src/transpilers/openai-agents/register.d.ts +12 -0
  145. package/umd/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +15 -0
  146. package/umd/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
  147. package/umd/src/version.d.ts +1 -1
  148. package/esm/src/commitments/USE/USE.d.ts +0 -51
  149. package/umd/src/commitments/USE/USE.d.ts +0 -51
package/umd/index.umd.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-53';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-56';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1333,6 +1333,24 @@
1333
1333
  get requiresContent() {
1334
1334
  return true;
1335
1335
  }
1336
+ /**
1337
+ * Whether this commitment should be prioritized in menus, documentation, and intellisense.
1338
+ */
1339
+ get isImportant() {
1340
+ return false;
1341
+ }
1342
+ /**
1343
+ * Whether this commitment is unfinished and not ready to use.
1344
+ */
1345
+ get isUnfinished() {
1346
+ return false;
1347
+ }
1348
+ /**
1349
+ * Whether this commitment is low-level and should be surfaced with caution.
1350
+ */
1351
+ get isLowLevel() {
1352
+ return false;
1353
+ }
1336
1354
  /**
1337
1355
  * Optional UI/docs-only deprecation metadata.
1338
1356
  */
@@ -1449,8 +1467,8 @@
1449
1467
  /**
1450
1468
  * ACTION commitment definition
1451
1469
  *
1452
- * The ACTION commitment defines specific actions or capabilities that the agent can perform.
1453
- * This helps define what the agent is capable of doing and how it should approach tasks.
1470
+ * Deprecated legacy commitment for broad capability notes.
1471
+ * New books should prefer the appropriate `USE*` commitment instead.
1454
1472
  *
1455
1473
  * Example usage in agent source:
1456
1474
  *
@@ -1469,7 +1487,15 @@
1469
1487
  * Short one-line description of ACTION.
1470
1488
  */
1471
1489
  get description() {
1472
- return 'Define agent capabilities and actions it can perform.';
1490
+ return 'Deprecated legacy capability commitment. Prefer concrete `USE*` commitments.';
1491
+ }
1492
+ /**
1493
+ * Optional UI/docs-only deprecation metadata.
1494
+ */
1495
+ get deprecation() {
1496
+ return {
1497
+ message: 'Use a concrete `USE*` commitment instead.',
1498
+ };
1473
1499
  }
1474
1500
  /**
1475
1501
  * Icon for this commitment.
@@ -1484,33 +1510,43 @@
1484
1510
  return spacetrim.spaceTrim(`
1485
1511
  # ${this.type}
1486
1512
 
1487
- Defines specific actions or capabilities that the agent can perform.
1513
+ Deprecated legacy commitment for broad capability notes.
1488
1514
 
1489
- ## Key aspects
1515
+ ## Migration
1490
1516
 
1491
- - Both terms work identically and can be used interchangeably.
1492
- - Each action adds to the agent's capability list.
1493
- - Actions help users understand what the agent can do.
1517
+ - Existing \`${this.type}\` and \`ACTIONS\` books still parse and compile.
1518
+ - New books should prefer the appropriate \`USE*\` commitment instead.
1519
+ - Keep \`${this.type}\` only when maintaining older books that already rely on it.
1494
1520
 
1495
- ## Examples
1521
+ ## Preferred replacement
1496
1522
 
1497
1523
  \`\`\`book
1498
- Code Assistant
1524
+ Research Assistant
1499
1525
 
1500
- PERSONA You are a programming assistant
1501
- ACTION Can generate code snippets and explain programming concepts
1502
- ACTION Able to debug existing code and suggest improvements
1503
- ACTION Can create unit tests for functions
1526
+ PERSONA You are a helpful research assistant
1527
+ USE SEARCH ENGINE
1528
+ RULE Always cite your sources when providing information from the web
1529
+ \`\`\`
1530
+
1531
+ ## Legacy compatibility example
1532
+
1533
+ \`\`\`book
1534
+ Research Assistant
1535
+
1536
+ PERSONA You are a helpful research assistant
1537
+ ACTION Can search for current information and summarize findings
1538
+ RULE Always cite your sources when providing information from the web
1504
1539
  \`\`\`
1505
1540
 
1541
+ ## Legacy compatibility example with additional tools
1542
+
1506
1543
  \`\`\`book
1507
- Data Scientist
1544
+ Code Assistant
1508
1545
 
1509
- PERSONA You are a data analysis expert
1510
- ACTION Able to analyze data and provide insights
1511
- ACTION Can create visualizations and charts
1512
- ACTION Capable of statistical analysis and modeling
1513
- KNOWLEDGE Data analysis best practices and statistical methods
1546
+ PERSONA You are a programming assistant
1547
+ USE BROWSER
1548
+ USE SEARCH ENGINE
1549
+ RULE Prefer the narrowest useful capability for the task.
1514
1550
  \`\`\`
1515
1551
  `);
1516
1552
  }
@@ -1519,7 +1555,7 @@
1519
1555
  if (!trimmedContent) {
1520
1556
  return requirements;
1521
1557
  }
1522
- // Add action capability to the system message
1558
+ // Keep the legacy capability note for backward compatibility.
1523
1559
  const actionSection = `Capability: ${trimmedContent}`;
1524
1560
  return this.appendToSystemMessage(requirements, actionSection, '\n\n');
1525
1561
  }
@@ -1672,9 +1708,9 @@
1672
1708
  /**
1673
1709
  * DELETE commitment definition
1674
1710
  *
1675
- * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is used to
1676
- * remove or disregard certain information or context. This can be useful for
1677
- * overriding previous commitments or removing unwanted behaviors.
1711
+ * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is a low-level
1712
+ * unfinished commitment used to remove or disregard certain information or context.
1713
+ * It is intentionally surfaced with caution because it is not ready for broad use yet.
1678
1714
  *
1679
1715
  * Example usage in agent source:
1680
1716
  *
@@ -1695,7 +1731,13 @@
1695
1731
  * Short one-line description of DELETE/CANCEL/DISCARD/REMOVE.
1696
1732
  */
1697
1733
  get description() {
1698
- return 'Remove or **disregard** certain information, context, or previous commitments.';
1734
+ return 'Unfinished low-level commitment for removing or disregarding information. Use carefully.';
1735
+ }
1736
+ /**
1737
+ * Marks DELETE as unfinished and not ready to use.
1738
+ */
1739
+ get isUnfinished() {
1740
+ return true;
1699
1741
  }
1700
1742
  /**
1701
1743
  * Icon for this commitment.
@@ -1710,7 +1752,13 @@
1710
1752
  return spacetrim.spaceTrim(`
1711
1753
  # DELETE (CANCEL, DISCARD, REMOVE)
1712
1754
 
1713
- A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
1755
+ A low-level unfinished commitment to remove or disregard certain information or context. It is not ready to use broadly yet, so use it carefully.
1756
+
1757
+ ## Status
1758
+
1759
+ - This commitment is unfinished and not ready to use yet.
1760
+ - Treat it as a low-level prompt-surgery tool rather than a general-purpose commitment.
1761
+ - Prefer higher-level commitments when a clearer dedicated commitment exists.
1714
1762
 
1715
1763
  ## Aliases
1716
1764
 
@@ -1725,6 +1773,7 @@
1725
1773
  - Useful for overriding previous commitments in the same agent definition.
1726
1774
  - Can be used to remove inherited behaviors from base personas.
1727
1775
  - Helps fine-tune agent behavior by explicitly removing unwanted elements.
1776
+ - Because this commitment is unfinished, keep an eye on future changes before relying on it in production books.
1728
1777
 
1729
1778
  ## Use cases
1730
1779
 
@@ -1732,6 +1781,7 @@
1732
1781
  - Removing conflicting or outdated instructions
1733
1782
  - Disabling specific response patterns
1734
1783
  - Canceling previous formatting or style requirements
1784
+ - Experimenting with low-level prompt rewrites when you know exactly what needs to be removed
1735
1785
 
1736
1786
  ## Examples
1737
1787
 
@@ -1898,11 +1948,10 @@
1898
1948
  /**
1899
1949
  * FORMAT commitment definition
1900
1950
  *
1901
- * The FORMAT commitment defines the specific output structure and formatting
1902
- * that the agent should use in its responses. This includes data formats,
1903
- * response templates, and structural requirements.
1951
+ * Deprecated legacy commitment for output formatting and response structure.
1952
+ * New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
1904
1953
  *
1905
- * Example usage in agent source:
1954
+ * Legacy example usage in agent source:
1906
1955
  *
1907
1956
  * ```book
1908
1957
  * FORMAT Always respond in JSON format with 'status' and 'data' fields
@@ -1919,7 +1968,16 @@
1919
1968
  * Short one-line description of FORMAT.
1920
1969
  */
1921
1970
  get description() {
1922
- return 'Specify output structure or formatting requirements.';
1971
+ return 'Deprecated legacy formatting commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
1972
+ }
1973
+ /**
1974
+ * Optional UI/docs-only deprecation metadata.
1975
+ */
1976
+ get deprecation() {
1977
+ return {
1978
+ message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
1979
+ replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
1980
+ };
1923
1981
  }
1924
1982
  /**
1925
1983
  * Icon for this commitment.
@@ -1934,31 +1992,39 @@
1934
1992
  return spacetrim.spaceTrim(`
1935
1993
  # ${this.type}
1936
1994
 
1937
- Defines the specific output structure and formatting for responses (data formats, templates, structure).
1995
+ Deprecated legacy commitment for output formatting and response structure.
1938
1996
 
1939
- ## Key aspects
1997
+ ## Migration
1940
1998
 
1941
- - Both terms work identically and can be used interchangeably.
1942
- - If they are in conflict, the last one takes precedence.
1943
- - You can specify both data formats and presentation styles.
1999
+ - Existing \`${this.type}\` and \`FORMATS\` books still parse and compile.
2000
+ - New books should use \`WRITING RULES\` for formatting or structure constraints and \`WRITING SAMPLE\` when a concrete example communicates the target shape better.
2001
+ - Runtime behavior is intentionally unchanged for backward compatibility.
1944
2002
 
1945
- ## Examples
2003
+ ## Preferred replacement
1946
2004
 
1947
2005
  \`\`\`book
1948
- Customer Support Bot
2006
+ Data Analyst
1949
2007
 
1950
- PERSONA You are a helpful customer support agent
1951
- FORMAT Always respond in JSON format with 'status' and 'data' fields
1952
- FORMAT Use markdown formatting for all code blocks
2008
+ GOAL Present results in a clean, readable structure.
2009
+ WRITING RULES Use markdown headings for sections and bullet points for lists.
2010
+ WRITING RULES Keep tables narrow and readable.
2011
+ WRITING SAMPLE
2012
+ Summary
2013
+ - ...
2014
+ Details
2015
+ - ...
2016
+ Next steps
2017
+ - ...
1953
2018
  \`\`\`
1954
2019
 
2020
+ ## Legacy compatibility example
2021
+
1955
2022
  \`\`\`book
1956
2023
  Data Analyst
1957
2024
 
1958
- PERSONA You are a data analysis expert
2025
+ GOAL Present results in a clean structure.
1959
2026
  FORMAT Present results in structured tables
1960
2027
  FORMAT Include confidence scores for all predictions
1961
- WRITING RULES Be concise and precise in explanations
1962
2028
  \`\`\`
1963
2029
  `);
1964
2030
  }
@@ -6481,6 +6547,12 @@
6481
6547
  get description() {
6482
6548
  return 'Define the effective agent **goal**; when multiple goals exist, only the last one stays effective.';
6483
6549
  }
6550
+ /**
6551
+ * Marks GOAL as one of the priority commitments surfaced first in catalogues.
6552
+ */
6553
+ get isImportant() {
6554
+ return true;
6555
+ }
6484
6556
  /**
6485
6557
  * Icon for this commitment.
6486
6558
  */
@@ -6892,6 +6964,12 @@
6892
6964
  get description() {
6893
6965
  return 'Add domain **knowledge** via direct text or external sources (RAG).';
6894
6966
  }
6967
+ /**
6968
+ * Marks KNOWLEDGE as one of the priority commitments surfaced first in catalogues.
6969
+ */
6970
+ get isImportant() {
6971
+ return true;
6972
+ }
6895
6973
  /**
6896
6974
  * Icon for this commitment.
6897
6975
  */
@@ -8179,6 +8257,7 @@
8179
8257
  * META commitment definition
8180
8258
  *
8181
8259
  * The META commitment handles all meta-information about the agent such as:
8260
+ * - META AVATAR: Sets the agent's built-in default avatar visual
8182
8261
  * - META IMAGE: Sets the agent's avatar/profile image URL
8183
8262
  * - META LINK: Provides profile/source links for the person the agent models
8184
8263
  * - META DOMAIN: Sets the canonical custom domain/host of the agent
@@ -8193,6 +8272,7 @@
8193
8272
  * Example usage in agent source:
8194
8273
  *
8195
8274
  * ```book
8275
+ * META AVATAR pixel-art
8196
8276
  * META IMAGE https://example.com/avatar.jpg
8197
8277
  * META LINK https://twitter.com/username
8198
8278
  * META DOMAIN my-agent.com
@@ -8213,112 +8293,3338 @@
8213
8293
  * Short one-line description of META commitments.
8214
8294
  */
8215
8295
  get description() {
8216
- return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
8296
+ return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
8297
+ }
8298
+ /**
8299
+ * Icon for this commitment.
8300
+ */
8301
+ get icon() {
8302
+ return 'â„šī¸';
8303
+ }
8304
+ /**
8305
+ * Markdown documentation for META commitment.
8306
+ */
8307
+ get documentation() {
8308
+ return spacetrim.spaceTrim(`
8309
+ # META
8310
+
8311
+ Sets meta-information about the agent that is used for display and attribution purposes.
8312
+
8313
+ ## Supported META types
8314
+
8315
+ - **META AVATAR** - Sets the agent's built-in default avatar visual
8316
+ - **META IMAGE** - Sets the agent's avatar/profile image URL
8317
+ - **META LINK** - Provides profile/source links for the person the agent models
8318
+ - **META DOMAIN** - Sets the canonical custom domain/host of the agent
8319
+ - **META TITLE** - Sets the agent's display title
8320
+ - **META DESCRIPTION** - Sets the agent's description
8321
+ - **META INPUT PLACEHOLDER** - Sets chat input placeholder text
8322
+ - **META [ANYTHING]** - Any other meta information in uppercase format
8323
+
8324
+ ## Key aspects
8325
+
8326
+ - Does not modify the agent's behavior or responses
8327
+ - Used for visual representation and attribution in user interfaces
8328
+ - Multiple META commitments of different types can be used
8329
+ - Multiple META LINK commitments can be used for different social profiles
8330
+ - If multiple META commitments of the same type are specified, the last one takes precedence (except for LINK)
8331
+
8332
+ ## Examples
8333
+
8334
+ ### Basic meta information
8335
+
8336
+ \`\`\`book
8337
+ Professional Assistant
8338
+
8339
+ META AVATAR octopus3
8340
+ META IMAGE https://example.com/professional-avatar.jpg
8341
+ META TITLE Senior Business Consultant
8342
+ META DESCRIPTION Specialized in strategic planning and project management
8343
+ META LINK https://linkedin.com/in/professional
8344
+ \`\`\`
8345
+
8346
+ ### Multiple links and custom meta
8347
+
8348
+ \`\`\`book
8349
+ Open Source Developer
8350
+
8351
+ META IMAGE /assets/dev-avatar.png
8352
+ META LINK https://github.com/developer
8353
+ META LINK https://twitter.com/devhandle
8354
+ META AUTHOR Jane Smith
8355
+ META VERSION 2.1
8356
+ META LICENSE MIT
8357
+ \`\`\`
8358
+
8359
+ ### Creative assistant
8360
+
8361
+ \`\`\`book
8362
+ Creative Helper
8363
+
8364
+ META IMAGE https://example.com/creative-bot.jpg
8365
+ META TITLE Creative Writing Assistant
8366
+ META DESCRIPTION Helps with brainstorming, storytelling, and creative projects
8367
+ META INSPIRATION Books, movies, and real-world experiences
8368
+ \`\`\`
8369
+ `);
8370
+ }
8371
+ applyToAgentModelRequirements(requirements, content) {
8372
+ // META commitments don't modify the system message or model requirements
8373
+ // They are handled separately in the parsing logic for meta information extraction
8374
+ // This method exists for consistency with the CommitmentDefinition interface
8375
+ return requirements;
8376
+ }
8377
+ /**
8378
+ * Extracts meta information from the content based on the meta type
8379
+ * This is used by the parsing logic
8380
+ */
8381
+ extractMetaValue(metaType, content) {
8382
+ const trimmedContent = content.trim();
8383
+ return trimmedContent || null;
8384
+ }
8385
+ /**
8386
+ * Validates if the provided content is a valid URL (for IMAGE and LINK types)
8387
+ */
8388
+ isValidUrl(content) {
8389
+ try {
8390
+ new URL(content.trim());
8391
+ return true;
8392
+ }
8393
+ catch (_a) {
8394
+ return false;
8395
+ }
8396
+ }
8397
+ /**
8398
+ * Checks if this is a known meta type
8399
+ */
8400
+ isKnownMetaType(metaType) {
8401
+ const knownTypes = ['AVATAR', 'IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
8402
+ return knownTypes.includes(metaType.toUpperCase());
8403
+ }
8404
+ }
8405
+ // Note: [💞] Ignore a discrepancy between file name and entity name
8406
+
8407
+ /**
8408
+ * Makes color transformer which darker the given color
8409
+ *
8410
+ * @param amount from 0 to 1
8411
+ *
8412
+ * @public exported from `@promptbook/color`
8413
+ */
8414
+ function darken(amount) {
8415
+ return lighten(-amount);
8416
+ }
8417
+
8418
+ /* eslint-disable no-magic-numbers */
8419
+ /**
8420
+ * Corner radius ratio used for the common rounded card frame.
8421
+ *
8422
+ * @private utility of the avatar rendering system
8423
+ */
8424
+ const FRAME_RADIUS_RATIO = 0.18;
8425
+ /**
8426
+ * Draws the common rounded background frame used by most visuals.
8427
+ *
8428
+ * @param context Canvas 2D context.
8429
+ * @param size Canvas size in CSS pixels.
8430
+ * @param palette Derived avatar palette.
8431
+ *
8432
+ * @private utility of the avatar rendering system
8433
+ */
8434
+ function drawAvatarFrame(context, size, palette) {
8435
+ if (palette.background === 'transparent' && palette.backgroundSecondary === 'transparent') {
8436
+ return;
8437
+ }
8438
+ const gradient = context.createLinearGradient(0, 0, size, size);
8439
+ gradient.addColorStop(0, palette.background);
8440
+ gradient.addColorStop(1, palette.backgroundSecondary);
8441
+ context.save();
8442
+ createRoundedRectPath(context, 0, 0, size, size, size * FRAME_RADIUS_RATIO);
8443
+ context.fillStyle = gradient;
8444
+ context.fill();
8445
+ context.restore();
8446
+ context.save();
8447
+ context.strokeStyle = 'rgba(255,255,255,0.12)';
8448
+ context.lineWidth = Math.max(1.5, size * 0.012);
8449
+ createRoundedRectPath(context, size * 0.02, size * 0.02, size * 0.96, size * 0.96, size * 0.15);
8450
+ context.stroke();
8451
+ context.restore();
8452
+ }
8453
+ /**
8454
+ * Creates a rounded rectangle path on the current canvas context.
8455
+ *
8456
+ * @param context Canvas 2D context.
8457
+ * @param x Left coordinate.
8458
+ * @param y Top coordinate.
8459
+ * @param width Rectangle width.
8460
+ * @param height Rectangle height.
8461
+ * @param radius Corner radius.
8462
+ *
8463
+ * @private utility of the avatar rendering system
8464
+ */
8465
+ function createRoundedRectPath(context, x, y, width, height, radius) {
8466
+ const normalizedRadius = Math.min(radius, width / 2, height / 2);
8467
+ context.beginPath();
8468
+ context.moveTo(x + normalizedRadius, y);
8469
+ context.arcTo(x + width, y, x + width, y + height, normalizedRadius);
8470
+ context.arcTo(x + width, y + height, x, y + height, normalizedRadius);
8471
+ context.arcTo(x, y + height, x, y, normalizedRadius);
8472
+ context.arcTo(x, y, x + width, y, normalizedRadius);
8473
+ context.closePath();
8474
+ }
8475
+ /**
8476
+ * Picks one deterministic element from a non-empty collection.
8477
+ *
8478
+ * @param items Candidate items.
8479
+ * @param random Seeded random generator.
8480
+ * @returns Picked item.
8481
+ *
8482
+ * @private utility of the avatar rendering system
8483
+ */
8484
+ function pickRandomItem(items, random) {
8485
+ return items[Math.floor(random() * items.length)];
8486
+ }
8487
+
8488
+ /* eslint-disable no-magic-numbers */
8489
+ /**
8490
+ * Builds a smoothly morphing octopus-like silhouette from deterministic parameters.
8491
+ *
8492
+ * @param options Shape construction options.
8493
+ * @returns Closed-loop body points.
8494
+ *
8495
+ * @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
8496
+ */
8497
+ function createOrganicOctopusBodyPoints(options) {
8498
+ const { centerX, centerY, bodyRadius, horizontalStretch, verticalStretch, mantleLift, lowerDrop, tentacleDepth, wobbleAmplitude, lobeCount, shapePhase, timeMs, pointCount = 36, } = options;
8499
+ return Array.from({ length: pointCount }, (_, pointIndex) => {
8500
+ const progress = pointIndex / pointCount;
8501
+ const angle = -Math.PI / 2 + progress * Math.PI * 2;
8502
+ const cosine = Math.cos(angle);
8503
+ const sine = Math.sin(angle);
8504
+ const upperFactor = Math.max(0, -sine);
8505
+ const lowerFactor = Math.max(0, sine);
8506
+ const lobeEnvelope = Math.pow(lowerFactor, 1.35);
8507
+ const tentacleWave = Math.max(0, Math.cos(angle * lobeCount + shapePhase + timeMs / 780)) * tentacleDepth * lobeEnvelope;
8508
+ const surfaceWave = Math.sin(angle * 3 + shapePhase + timeMs / 1200) * 0.62 +
8509
+ Math.sin(angle * 5 - shapePhase * 0.7 - timeMs / 910) * 0.38;
8510
+ const breathingWave = Math.sin(timeMs / 960 + shapePhase + angle * 0.45) * wobbleAmplitude;
8511
+ const radius = bodyRadius * (1 + upperFactor * 0.12 + lowerFactor * 0.08 + surfaceWave * 0.05) +
8512
+ tentacleWave +
8513
+ breathingWave;
8514
+ return {
8515
+ x: centerX +
8516
+ cosine * radius * horizontalStretch +
8517
+ Math.sin(angle * 2 + shapePhase) * lobeEnvelope * wobbleAmplitude * 0.7,
8518
+ y: centerY +
8519
+ sine * radius * verticalStretch -
8520
+ upperFactor * mantleLift +
8521
+ lowerFactor * lowerDrop +
8522
+ tentacleWave * 0.28,
8523
+ };
8524
+ });
8525
+ }
8526
+ /**
8527
+ * Traces a smooth closed path through the provided points.
8528
+ *
8529
+ * @param context Canvas 2D context.
8530
+ * @param points Closed-loop points.
8531
+ *
8532
+ * @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
8533
+ */
8534
+ function traceSmoothClosedPath(context, points) {
8535
+ const lastPoint = points[points.length - 1];
8536
+ const firstPoint = points[0];
8537
+ const initialMidpoint = {
8538
+ x: (lastPoint.x + firstPoint.x) / 2,
8539
+ y: (lastPoint.y + firstPoint.y) / 2,
8540
+ };
8541
+ context.beginPath();
8542
+ context.moveTo(initialMidpoint.x, initialMidpoint.y);
8543
+ for (let pointIndex = 0; pointIndex < points.length; pointIndex++) {
8544
+ const point = points[pointIndex];
8545
+ const nextPoint = points[(pointIndex + 1) % points.length];
8546
+ const midpoint = {
8547
+ x: (point.x + nextPoint.x) / 2,
8548
+ y: (point.y + nextPoint.y) / 2,
8549
+ };
8550
+ context.quadraticCurveTo(point.x, point.y, midpoint.x, midpoint.y);
8551
+ }
8552
+ context.closePath();
8553
+ }
8554
+ /**
8555
+ * Creates deterministic ribbon tentacles for the organic octopus visuals.
8556
+ *
8557
+ * @param options Tentacle construction options.
8558
+ * @returns Tentacle descriptors.
8559
+ *
8560
+ * @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
8561
+ */
8562
+ function createOrganicOctopusTentacleShapes(options) {
8563
+ var _a, _b, _c, _d, _e, _f, _g, _h;
8564
+ const { size, centerX, centerY, bodyRadius, horizontalStretch, tentacleCount, shapePhase, createRandom, timeMs, saltPrefix, bodyPoints, variation, } = options;
8565
+ const baseY = centerY + bodyRadius * 0.74;
8566
+ const lowerBodyAnchorPoints = bodyPoints
8567
+ ? resolveTentacleBodyAnchorPoints(bodyPoints, centerY + bodyRadius * 0.04)
8568
+ : null;
8569
+ const flowLengthScale = (_a = variation === null || variation === void 0 ? void 0 : variation.flowLengthScale) !== null && _a !== void 0 ? _a : 1;
8570
+ const lateralReachScale = (_b = variation === null || variation === void 0 ? void 0 : variation.lateralReachScale) !== null && _b !== void 0 ? _b : 1;
8571
+ const tipReachScale = (_c = variation === null || variation === void 0 ? void 0 : variation.tipReachScale) !== null && _c !== void 0 ? _c : 1;
8572
+ const baseWidthScale = (_d = variation === null || variation === void 0 ? void 0 : variation.baseWidthScale) !== null && _d !== void 0 ? _d : 1;
8573
+ const tipWidthScale = (_e = variation === null || variation === void 0 ? void 0 : variation.tipWidthScale) !== null && _e !== void 0 ? _e : 1;
8574
+ const rootSpreadScale = (_f = variation === null || variation === void 0 ? void 0 : variation.rootSpreadScale) !== null && _f !== void 0 ? _f : 1;
8575
+ const startYOffsetScale = (_g = variation === null || variation === void 0 ? void 0 : variation.startYOffsetScale) !== null && _g !== void 0 ? _g : 1;
8576
+ const swayScale = (_h = variation === null || variation === void 0 ? void 0 : variation.swayScale) !== null && _h !== void 0 ? _h : 1;
8577
+ return Array.from({ length: tentacleCount }, (_, tentacleIndex) => {
8578
+ const tentacleRandom = createRandom(`${saltPrefix}-tentacle-${tentacleIndex}`);
8579
+ const spreadProgress = tentacleCount === 1 ? 0.5 : tentacleIndex / (tentacleCount - 1);
8580
+ const centeredProgress = spreadProgress - 0.5;
8581
+ const spreadCenteredProgress = centeredProgress * rootSpreadScale;
8582
+ const spreadAnchorProgress = Math.min(1, Math.max(0, 0.5 + spreadCenteredProgress));
8583
+ const temporalSway = Math.sin(timeMs / (720 + tentacleIndex * 34) + shapePhase + tentacleRandom() * Math.PI * 2) *
8584
+ size *
8585
+ (0.014 + tentacleRandom() * 0.015) *
8586
+ swayScale;
8587
+ const flowLength = size * (0.24 + tentacleRandom() * 0.18) * flowLengthScale;
8588
+ const curlDirection = spreadCenteredProgress === 0 ? (tentacleRandom() < 0.5 ? -1 : 1) : Math.sign(spreadCenteredProgress);
8589
+ const lateralReach = spreadCenteredProgress * size * (0.1 + tentacleRandom() * 0.1) * lateralReachScale + temporalSway;
8590
+ const tipReach = curlDirection * size * (0.025 + tentacleRandom() * 0.07) * tipReachScale;
8591
+ const startYOffset = (Math.abs(spreadCenteredProgress) * size * 0.012 + tentacleRandom() * size * 0.01) * startYOffsetScale;
8592
+ const startPoint = lowerBodyAnchorPoints && lowerBodyAnchorPoints.length >= 2
8593
+ ? createInsetTentacleStartPoint({
8594
+ bodyPoints: lowerBodyAnchorPoints,
8595
+ anchorProgress: spreadAnchorProgress,
8596
+ centerX,
8597
+ centerY,
8598
+ bodyRadius,
8599
+ centeredProgress: spreadCenteredProgress,
8600
+ startYOffset,
8601
+ })
8602
+ : {
8603
+ x: centerX + spreadCenteredProgress * bodyRadius * horizontalStretch * 1.52,
8604
+ y: baseY + startYOffset,
8605
+ };
8606
+ const controlPointOne = {
8607
+ x: startPoint.x + spreadCenteredProgress * size * 0.045 * lateralReachScale + temporalSway * 0.4,
8608
+ y: startPoint.y + flowLength * (0.21 + tentacleRandom() * 0.08),
8609
+ };
8610
+ const controlPointTwo = {
8611
+ x: startPoint.x + lateralReach + tipReach,
8612
+ y: startPoint.y + flowLength * (0.62 + tentacleRandom() * 0.12),
8613
+ };
8614
+ const endPoint = {
8615
+ x: startPoint.x + lateralReach + tipReach * 1.2,
8616
+ y: startPoint.y +
8617
+ flowLength * (0.9 + tentacleRandom() * 0.12) +
8618
+ Math.cos(timeMs / (840 + tentacleIndex * 41) + shapePhase) * size * (0.008 + tentacleRandom() * 0.01),
8619
+ };
8620
+ const baseWidth = size * (0.038 + tentacleRandom() * 0.02) * (1 - Math.abs(spreadCenteredProgress) * 0.18) * baseWidthScale;
8621
+ const tipWidth = baseWidth * Math.min(0.52, (0.18 + tentacleRandom() * 0.2) * tipWidthScale);
8622
+ return {
8623
+ startPoint,
8624
+ controlPointOne,
8625
+ controlPointTwo,
8626
+ endPoint,
8627
+ baseWidth,
8628
+ tipWidth,
8629
+ colorBias: tentacleRandom(),
8630
+ highlightBias: tentacleRandom(),
8631
+ sampleCount: 14 + Math.floor(tentacleRandom() * 6),
8632
+ };
8633
+ });
8634
+ }
8635
+ /**
8636
+ * Narrows the body contour to lower anchor points that can safely host tentacle roots.
8637
+ *
8638
+ * @param bodyPoints Generated closed-loop body points.
8639
+ * @param lowerBodyThresholdY Minimum Y coordinate considered part of the lower mantle.
8640
+ * @returns Body points sorted from left to right across the lower silhouette.
8641
+ *
8642
+ * @private shared geometry helper of `octopus3AvatarVisual`
8643
+ */
8644
+ function resolveTentacleBodyAnchorPoints(bodyPoints, lowerBodyThresholdY) {
8645
+ const lowerBodyPoints = bodyPoints
8646
+ .filter((bodyPoint) => bodyPoint.y >= lowerBodyThresholdY)
8647
+ .sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
8648
+ if (lowerBodyPoints.length >= 2) {
8649
+ return lowerBodyPoints;
8650
+ }
8651
+ return [...bodyPoints].sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
8652
+ }
8653
+ /**
8654
+ * Resolves one tentacle root from the provided lower body contour and nudges it inside the mantle.
8655
+ *
8656
+ * @param options Tentacle anchor options.
8657
+ * @returns Tentacle start point safely embedded inside the body silhouette.
8658
+ *
8659
+ * @private shared geometry helper of `octopus3AvatarVisual`
8660
+ */
8661
+ function createInsetTentacleStartPoint(options) {
8662
+ const { bodyPoints, anchorProgress, centerX, centerY, bodyRadius, centeredProgress, startYOffset } = options;
8663
+ const clampedAnchorProgress = Math.min(0.94, Math.max(0.06, anchorProgress));
8664
+ const bodyAnchorPoint = interpolatePointAlongTentacleAnchors(bodyPoints, clampedAnchorProgress);
8665
+ const inwardX = centerX - bodyAnchorPoint.x;
8666
+ const inwardY = centerY + bodyRadius * 0.08 - bodyAnchorPoint.y;
8667
+ const inwardLength = Math.hypot(inwardX, inwardY) || 1;
8668
+ const insetDistance = bodyRadius * (0.12 + Math.abs(centeredProgress) * 0.05) + startYOffset * 0.32;
8669
+ return {
8670
+ x: bodyAnchorPoint.x + (inwardX / inwardLength) * insetDistance,
8671
+ y: bodyAnchorPoint.y + (inwardY / inwardLength) * insetDistance,
8672
+ };
8673
+ }
8674
+ /**
8675
+ * Interpolates one left-to-right anchor point along the prepared lower body contour.
8676
+ *
8677
+ * @param bodyPoints Lower body contour points sorted from left to right.
8678
+ * @param progress Interpolation progress in the range `[0, 1]`.
8679
+ * @returns Interpolated anchor point.
8680
+ *
8681
+ * @private shared geometry helper of `octopus3AvatarVisual`
8682
+ */
8683
+ function interpolatePointAlongTentacleAnchors(bodyPoints, progress) {
8684
+ if (bodyPoints.length === 1) {
8685
+ return bodyPoints[0];
8686
+ }
8687
+ const anchorIndex = progress * (bodyPoints.length - 1);
8688
+ const startIndex = Math.floor(anchorIndex);
8689
+ const endIndex = Math.min(bodyPoints.length - 1, startIndex + 1);
8690
+ const blend = anchorIndex - startIndex;
8691
+ const startPoint = bodyPoints[startIndex];
8692
+ const endPoint = bodyPoints[endIndex];
8693
+ return {
8694
+ x: startPoint.x + (endPoint.x - startPoint.x) * blend,
8695
+ y: startPoint.y + (endPoint.y - startPoint.y) * blend,
8696
+ };
8697
+ }
8698
+ /**
8699
+ * Samples the cubic tentacle centerline and offsets normals to build a filled ribbon.
8700
+ *
8701
+ * @param tentacleShape Deterministic tentacle descriptor.
8702
+ * @returns Sampled ribbon points.
8703
+ *
8704
+ * @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
8705
+ */
8706
+ function sampleOrganicTentacleRibbonPoints(tentacleShape) {
8707
+ return Array.from({ length: tentacleShape.sampleCount + 1 }, (_, sampleIndex) => {
8708
+ const progress = sampleIndex / tentacleShape.sampleCount;
8709
+ const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
8710
+ const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.04));
8711
+ const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.04));
8712
+ const tangentX = nextPoint.x - previousPoint.x;
8713
+ const tangentY = nextPoint.y - previousPoint.y;
8714
+ const tangentLength = Math.hypot(tangentX, tangentY) || 1;
8715
+ const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
8716
+ return {
8717
+ x: point.x,
8718
+ y: point.y,
8719
+ normalX: -tangentY / tangentLength,
8720
+ normalY: tangentX / tangentLength,
8721
+ width,
8722
+ progress,
8723
+ };
8724
+ });
8725
+ }
8726
+ /**
8727
+ * Resolves smooth pupil offsets that blend autonomous idle drift with live viewer tracking.
8728
+ *
8729
+ * @param options Eye motion options.
8730
+ * @returns Resolved pupil offsets.
8731
+ *
8732
+ * @private shared geometry helper of octopus avatar visuals
8733
+ */
8734
+ function resolveOrganicEyeMotion(options) {
8735
+ const { radiusX, radiusY, timeMs, phase, interaction, autonomousDriftRatioX = 0.12, autonomousDriftRatioY = 0.08, } = options;
8736
+ const autonomousOffsetX = Math.sin(timeMs / 1280 + phase) * radiusX * autonomousDriftRatioX;
8737
+ const autonomousOffsetY = Math.cos(timeMs / 940 + phase) * radiusY * autonomousDriftRatioY;
8738
+ const interactionBlend = Math.min(1, interaction.intensity * 0.9);
8739
+ return {
8740
+ pupilOffsetX: autonomousOffsetX * (1 - interactionBlend) + interaction.gazeX * radiusX * (0.18 + interactionBlend * 0.18),
8741
+ pupilOffsetY: autonomousOffsetY * (1 - interactionBlend) + interaction.gazeY * radiusY * (0.16 + interactionBlend * 0.16),
8742
+ };
8743
+ }
8744
+ /**
8745
+ * Samples one point on a cubic Bezier curve.
8746
+ *
8747
+ * @param startPoint Curve start point.
8748
+ * @param controlPointOne First control point.
8749
+ * @param controlPointTwo Second control point.
8750
+ * @param endPoint Curve end point.
8751
+ * @param progress Sampling progress in the range `[0, 1]`.
8752
+ * @returns Sampled point.
8753
+ *
8754
+ * @private shared geometry helper of `octopus3AvatarVisual`
8755
+ */
8756
+ function getCubicBezierPoint(startPoint, controlPointOne, controlPointTwo, endPoint, progress) {
8757
+ const inverseProgress = 1 - progress;
8758
+ return {
8759
+ x: inverseProgress * inverseProgress * inverseProgress * startPoint.x +
8760
+ 3 * inverseProgress * inverseProgress * progress * controlPointOne.x +
8761
+ 3 * inverseProgress * progress * progress * controlPointTwo.x +
8762
+ progress * progress * progress * endPoint.x,
8763
+ y: inverseProgress * inverseProgress * inverseProgress * startPoint.y +
8764
+ 3 * inverseProgress * inverseProgress * progress * controlPointOne.y +
8765
+ 3 * inverseProgress * progress * progress * controlPointTwo.y +
8766
+ progress * progress * progress * endPoint.y,
8767
+ };
8768
+ }
8769
+
8770
+ /* eslint-disable no-magic-numbers */
8771
+ /**
8772
+ * Glyph ramp used for the main octopus body fill.
8773
+ *
8774
+ * @private helper of `asciiOctopusAvatarVisual`
8775
+ */
8776
+ const BODY_GLYPHS = ['.', ':', '-', '=', '+', '*', '#', '%', '@'];
8777
+ /**
8778
+ * Glyph ramp used on silhouette edges so the ASCII blob stays legible.
8779
+ *
8780
+ * @private helper of `asciiOctopusAvatarVisual`
8781
+ */
8782
+ const OUTLINE_GLYPHS = ['#', '%', '@'];
8783
+ /**
8784
+ * Glyph ramp used in the surrounding atmosphere.
8785
+ *
8786
+ * @private helper of `asciiOctopusAvatarVisual`
8787
+ */
8788
+ const ATMOSPHERE_GLYPHS = ['.', ':', "'", '`'];
8789
+ /**
8790
+ * AsciiOctopus avatar visual.
8791
+ *
8792
+ * @private built-in avatar visual
8793
+ */
8794
+ const asciiOctopusAvatarVisual = {
8795
+ id: 'ascii-octopus',
8796
+ title: 'AsciiOctopus',
8797
+ description: 'Morphing alien octopus translated into animated ASCII glyphs with responsive eyes and seeded geometry.',
8798
+ isAnimated: true,
8799
+ supportsPointerTracking: true,
8800
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
8801
+ const gridRandom = createRandom('ascii-octopus-grid');
8802
+ const staticRandom = createRandom('ascii-octopus-static');
8803
+ const gridMetrics = createAsciiGridMetrics(size, gridRandom);
8804
+ const layout = createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction);
8805
+ drawAvatarFrame(context, size, palette);
8806
+ drawAsciiBackdrop(context, size, palette, layout, timeMs);
8807
+ context.save();
8808
+ context.font = `600 ${gridMetrics.fontSize}px monospace`;
8809
+ context.textAlign = 'center';
8810
+ context.textBaseline = 'middle';
8811
+ // The ASCII renderer samples the morphing octopus field on a low-resolution grid so the shape stays organic
8812
+ // while the glyph layout remains deterministic for the same avatar input.
8813
+ const cellRandom = createRandom('ascii-octopus-cells');
8814
+ for (let rowIndex = 0; rowIndex < gridMetrics.rowCount; rowIndex++) {
8815
+ for (let columnIndex = 0; columnIndex < gridMetrics.columnCount; columnIndex++) {
8816
+ const point = {
8817
+ x: gridMetrics.offsetX + columnIndex * gridMetrics.cellWidth,
8818
+ y: gridMetrics.offsetY + rowIndex * gridMetrics.cellHeight,
8819
+ };
8820
+ const noise = cellRandom();
8821
+ const glyphDescriptor = resolveAsciiGlyph({
8822
+ point,
8823
+ layout,
8824
+ palette,
8825
+ cellWidth: gridMetrics.cellWidth,
8826
+ cellHeight: gridMetrics.cellHeight,
8827
+ noise,
8828
+ timeMs,
8829
+ });
8830
+ if (!glyphDescriptor) {
8831
+ continue;
8832
+ }
8833
+ context.fillStyle = glyphDescriptor.color;
8834
+ context.fillText(glyphDescriptor.character, point.x, point.y);
8835
+ }
8836
+ }
8837
+ context.restore();
8838
+ },
8839
+ };
8840
+ /**
8841
+ * Draws the dark terminal-like glow behind the ASCII octopus.
8842
+ *
8843
+ * @param context Canvas 2D context.
8844
+ * @param size Canvas size in CSS pixels.
8845
+ * @param palette Derived avatar palette.
8846
+ * @param layout Prepared octopus layout.
8847
+ * @param timeMs Current animation time in milliseconds.
8848
+ *
8849
+ * @private helper of `asciiOctopusAvatarVisual`
8850
+ */
8851
+ function drawAsciiBackdrop(context, size, palette, layout, timeMs) {
8852
+ const haloGradient = context.createRadialGradient(layout.centerX, layout.centerY - size * 0.12, size * 0.06, layout.centerX, layout.centerY, size * 0.62);
8853
+ haloGradient.addColorStop(0, `${palette.highlight}26`);
8854
+ haloGradient.addColorStop(0.42, `${palette.accent}16`);
8855
+ haloGradient.addColorStop(1, `${palette.highlight}00`);
8856
+ context.fillStyle = haloGradient;
8857
+ context.fillRect(0, 0, size, size);
8858
+ const lowerGlowGradient = context.createRadialGradient(layout.centerX + Math.sin(timeMs / 1100 + layout.shapePhase) * size * 0.03, layout.centerY + size * 0.2, size * 0.05, layout.centerX, layout.centerY + size * 0.24, size * 0.46);
8859
+ lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
8860
+ lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
8861
+ context.fillStyle = lowerGlowGradient;
8862
+ context.fillRect(0, 0, size, size);
8863
+ context.beginPath();
8864
+ context.ellipse(layout.centerX, layout.centerY + size * 0.29, size * 0.23, size * 0.065, 0, 0, Math.PI * 2);
8865
+ context.fillStyle = `${palette.shadow}33`;
8866
+ context.fill();
8867
+ }
8868
+ /**
8869
+ * Resolves the ASCII character that should be drawn for one sampled cell.
8870
+ *
8871
+ * @param options Cell evaluation options.
8872
+ * @returns Character descriptor or `null` when the cell should stay empty.
8873
+ *
8874
+ * @private helper of `asciiOctopusAvatarVisual`
8875
+ */
8876
+ function resolveAsciiGlyph(options) {
8877
+ const { point, layout, palette, cellWidth, cellHeight, noise, timeMs } = options;
8878
+ const eyeGlyphDescriptor = resolveEyeGlyph(point, layout.leftEye, layout.interaction, palette, timeMs) ||
8879
+ resolveEyeGlyph(point, layout.rightEye, layout.interaction, palette, timeMs);
8880
+ if (eyeGlyphDescriptor) {
8881
+ return eyeGlyphDescriptor;
8882
+ }
8883
+ const mouthGlyphDescriptor = resolveMouthGlyph(point, layout, palette, cellHeight);
8884
+ if (mouthGlyphDescriptor) {
8885
+ return mouthGlyphDescriptor;
8886
+ }
8887
+ const isWithinOctopusBounds = point.x >= layout.leftBound &&
8888
+ point.x <= layout.rightBound &&
8889
+ point.y >= layout.topBound &&
8890
+ point.y <= layout.bottomBound;
8891
+ if (!isWithinOctopusBounds) {
8892
+ return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
8893
+ }
8894
+ const isInsideBody = isPointInsidePolygon(point, layout.bodyPoints);
8895
+ const bodyEdgeDistance = isInsideBody
8896
+ ? getDistanceToPolyline(point, layout.bodyPoints, true)
8897
+ : Number.POSITIVE_INFINITY;
8898
+ const tentacleCoverage = measureTentacleCoverage(point, layout.sampledTentacles, cellWidth);
8899
+ if (isInsideBody || tentacleCoverage) {
8900
+ return resolveOctopusSurfaceGlyph({
8901
+ point,
8902
+ layout,
8903
+ palette,
8904
+ isInsideBody,
8905
+ bodyEdgeDistance,
8906
+ tentacleCoverage,
8907
+ cellWidth,
8908
+ cellHeight,
8909
+ noise,
8910
+ timeMs,
8911
+ });
8912
+ }
8913
+ return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
8914
+ }
8915
+ /**
8916
+ * Resolves the ASCII character for one eye cell.
8917
+ *
8918
+ * @param point Sampled cell point.
8919
+ * @param eyeFeature Eye geometry.
8920
+ * @param palette Derived avatar palette.
8921
+ * @param timeMs Current animation time in milliseconds.
8922
+ * @returns Eye glyph descriptor or `null`.
8923
+ *
8924
+ * @private helper of `asciiOctopusAvatarVisual`
8925
+ */
8926
+ function resolveEyeGlyph(point, eyeFeature, interaction, palette, timeMs) {
8927
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
8928
+ radiusX: eyeFeature.radiusX,
8929
+ radiusY: eyeFeature.radiusY,
8930
+ timeMs,
8931
+ phase: eyeFeature.phase,
8932
+ interaction,
8933
+ });
8934
+ const scleraDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX, eyeFeature.centerY, eyeFeature.radiusX, eyeFeature.radiusY, eyeFeature.rotation);
8935
+ if (scleraDistance > 1.08) {
8936
+ return null;
8937
+ }
8938
+ const highlightDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX - eyeFeature.radiusX * 0.24, eyeFeature.centerY + pupilOffsetY - eyeFeature.radiusY * 0.26, eyeFeature.radiusX * 0.18, eyeFeature.radiusY * 0.14, eyeFeature.rotation);
8939
+ if (highlightDistance <= 1) {
8940
+ return { character: '*', color: '#ffffff' };
8941
+ }
8942
+ const pupilDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.2, eyeFeature.radiusY * 0.48, eyeFeature.rotation);
8943
+ if (pupilDistance <= 1) {
8944
+ return { character: '@', color: palette.ink };
8945
+ }
8946
+ const irisDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.64, eyeFeature.radiusY * 0.72, eyeFeature.rotation);
8947
+ if (irisDistance <= 1) {
8948
+ return {
8949
+ character: irisDistance < 0.46 ? '0' : 'o',
8950
+ color: irisDistance < 0.62 ? palette.secondary : `${palette.highlight}d9`,
8951
+ };
8952
+ }
8953
+ return {
8954
+ character: scleraDistance > 0.82 ? 'o' : '0',
8955
+ color: '#f8fbff',
8956
+ };
8957
+ }
8958
+ /**
8959
+ * Resolves the ASCII character for the octopus mouth.
8960
+ *
8961
+ * @param point Sampled cell point.
8962
+ * @param layout Prepared octopus layout.
8963
+ * @param palette Derived avatar palette.
8964
+ * @param cellHeight Character cell height.
8965
+ * @returns Mouth glyph descriptor or `null`.
8966
+ *
8967
+ * @private helper of `asciiOctopusAvatarVisual`
8968
+ */
8969
+ function resolveMouthGlyph(point, layout, palette, cellHeight) {
8970
+ const mouthDistance = getDistanceToPolyline(point, layout.mouthPoints, false);
8971
+ if (mouthDistance > cellHeight * 0.38) {
8972
+ return null;
8973
+ }
8974
+ const horizontalProgress = clamp01((point.x - layout.mouthPoints[0].x) /
8975
+ (layout.mouthPoints[layout.mouthPoints.length - 1].x - layout.mouthPoints[0].x));
8976
+ let character = '-';
8977
+ if (horizontalProgress < 0.28) {
8978
+ character = '\\';
8979
+ }
8980
+ else if (horizontalProgress > 0.72) {
8981
+ character = '/';
8982
+ }
8983
+ else if (horizontalProgress > 0.42 && horizontalProgress < 0.58) {
8984
+ character = '_';
8985
+ }
8986
+ return {
8987
+ character,
8988
+ color: `${palette.ink}bf`,
8989
+ };
8990
+ }
8991
+ /**
8992
+ * Resolves the ASCII character for body and tentacle cells.
8993
+ *
8994
+ * @param options Surface evaluation options.
8995
+ * @returns Surface glyph descriptor.
8996
+ *
8997
+ * @private helper of `asciiOctopusAvatarVisual`
8998
+ */
8999
+ function resolveOctopusSurfaceGlyph(options) {
9000
+ const { point, layout, palette, isInsideBody, bodyEdgeDistance, tentacleCoverage, cellHeight, noise, timeMs } = options;
9001
+ const isTentacleDominant = tentacleCoverage !== null && (!isInsideBody || point.y > layout.centerY + layout.bodyRadius * 0.08);
9002
+ if (isTentacleDominant && tentacleCoverage) {
9003
+ const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.78;
9004
+ if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.42) {
9005
+ return {
9006
+ character: noise > 0.9 ? '0' : 'o',
9007
+ color: `${palette.highlight}d0`,
9008
+ };
9009
+ }
9010
+ return {
9011
+ character: pickTentacleCharacter(tentacleCoverage, noise),
9012
+ color: tentacleCoverage.progress < 0.24
9013
+ ? `${palette.secondary}c7`
9014
+ : tentacleCoverage.progress > 0.72
9015
+ ? `${palette.accent}bf`
9016
+ : tentacleCoverage.normalizedDistance > 0.7
9017
+ ? `${palette.highlight}bf`
9018
+ : `${palette.primary}c9`,
9019
+ };
9020
+ }
9021
+ const highlightBias = clamp01((layout.centerY - point.y + layout.bodyRadius * 0.44) / (layout.bodyRadius * 1.14));
9022
+ const bodyDepth = clamp01(1 - bodyEdgeDistance / (layout.bodyRadius * 0.9));
9023
+ const shimmer = Math.sin(timeMs / 720 + point.x * 0.085 + point.y * 0.06 + layout.shapePhase) * 0.05;
9024
+ const bodyIntensity = clamp01(0.22 + bodyDepth * 0.58 + highlightBias * 0.2 + shimmer + (noise - 0.5) * 0.18);
9025
+ const isOutline = isInsideBody && bodyEdgeDistance < cellHeight * 0.54;
9026
+ const character = isOutline
9027
+ ? pickRampCharacter(OUTLINE_GLYPHS, clamp01(0.58 + bodyIntensity * 0.42))
9028
+ : pickRampCharacter(BODY_GLYPHS, bodyIntensity);
9029
+ let color = `${palette.primary}bf`;
9030
+ if (highlightBias > 0.76) {
9031
+ color = `${palette.highlight}d9`;
9032
+ }
9033
+ else if (bodyDepth > 0.7) {
9034
+ color = `${palette.secondary}cb`;
9035
+ }
9036
+ else if ((point.x < layout.centerX && noise > 0.58) || (point.x >= layout.centerX && noise < 0.42)) {
9037
+ color = `${palette.accent}ba`;
9038
+ }
9039
+ return {
9040
+ character,
9041
+ color: isOutline ? `${palette.highlight}c9` : color,
9042
+ };
9043
+ }
9044
+ /**
9045
+ * Resolves faint atmosphere glyphs around the ASCII octopus.
9046
+ *
9047
+ * @param point Sampled cell point.
9048
+ * @param layout Prepared octopus layout.
9049
+ * @param palette Derived avatar palette.
9050
+ * @param noise Stable per-cell noise.
9051
+ * @param timeMs Current animation time in milliseconds.
9052
+ * @returns Atmosphere glyph descriptor or `null`.
9053
+ *
9054
+ * @private helper of `asciiOctopusAvatarVisual`
9055
+ */
9056
+ function resolveAtmosphereGlyph(point, layout, palette, noise, timeMs) {
9057
+ const horizontalDistance = Math.abs(point.x - layout.centerX) / (layout.bodyRadius * layout.horizontalStretch * 2.2);
9058
+ const verticalDistance = Math.abs(point.y - (layout.centerY + layout.bodyRadius * 0.04)) / (layout.bodyRadius * 2.1);
9059
+ const haloDistance = Math.hypot(horizontalDistance, verticalDistance);
9060
+ const shimmer = Math.sin(timeMs / 1450 + point.x * 0.03 + point.y * 0.04 + layout.shapePhase) * 0.06;
9061
+ const density = clamp01(1.16 - haloDistance + shimmer + (noise - 0.5) * 0.14);
9062
+ if (density < 0.18 || noise > density * 0.84 + 0.34) {
9063
+ return null;
9064
+ }
9065
+ return {
9066
+ character: pickRampCharacter(ATMOSPHERE_GLYPHS, density),
9067
+ color: point.y < layout.centerY ? `${palette.highlight}63` : `${palette.accent}47`,
9068
+ };
9069
+ }
9070
+ /**
9071
+ * Builds the grid used by the ASCII renderer.
9072
+ *
9073
+ * @param size Canvas size in CSS pixels.
9074
+ * @param staticRandom Stable random generator for this avatar.
9075
+ * @returns Grid metrics.
9076
+ *
9077
+ * @private helper of `asciiOctopusAvatarVisual`
9078
+ */
9079
+ function createAsciiGridMetrics(size, staticRandom) {
9080
+ const fontSize = Math.max(9, Math.round(size * (0.048 + staticRandom() * 0.006)));
9081
+ const cellWidth = fontSize * (0.58 + staticRandom() * 0.04);
9082
+ const cellHeight = fontSize * 0.82;
9083
+ const columnCount = Math.max(12, Math.floor(size / cellWidth) - 1);
9084
+ const rowCount = Math.max(12, Math.floor(size / cellHeight) - 1);
9085
+ const offsetX = (size - (columnCount - 1) * cellWidth) / 2;
9086
+ const offsetY = (size - (rowCount - 1) * cellHeight) / 2;
9087
+ return {
9088
+ fontSize,
9089
+ cellWidth,
9090
+ cellHeight,
9091
+ columnCount,
9092
+ rowCount,
9093
+ offsetX,
9094
+ offsetY,
9095
+ };
9096
+ }
9097
+ /**
9098
+ * Builds the deterministic octopus geometry that will later be sampled into ASCII cells.
9099
+ *
9100
+ * @param size Canvas size in CSS pixels.
9101
+ * @param timeMs Current animation time in milliseconds.
9102
+ * @param createRandom Seeded random factory scoped to the avatar.
9103
+ * @param staticRandom Stable random generator for this avatar.
9104
+ * @returns Prepared octopus layout.
9105
+ *
9106
+ * @private helper of `asciiOctopusAvatarVisual`
9107
+ */
9108
+ function createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction) {
9109
+ const centerX = size * (0.5 + (staticRandom() - 0.5) * 0.02) + interaction.bodyOffsetX * size * 0.05;
9110
+ const centerY = size * (0.41 + staticRandom() * 0.05) + interaction.bodyOffsetY * size * 0.035;
9111
+ const bodyRadius = size * (0.195 + staticRandom() * 0.05);
9112
+ const horizontalStretch = 1.08 + staticRandom() * 0.22;
9113
+ const verticalStretch = 0.88 + staticRandom() * 0.14;
9114
+ const mantleLift = size * (0.1 + staticRandom() * 0.03);
9115
+ const lowerDrop = size * (0.03 + staticRandom() * 0.024);
9116
+ const tentacleDepth = size * (0.026 + staticRandom() * 0.022);
9117
+ const wobbleAmplitude = size * (0.008 + staticRandom() * 0.01);
9118
+ const lobeCount = 5 + Math.floor(staticRandom() * 4);
9119
+ const shapePhase = staticRandom() * Math.PI * 2;
9120
+ const tentacleCount = 8 + Math.floor(staticRandom() * 5);
9121
+ const eyeSpacing = size * (0.108 + staticRandom() * 0.042);
9122
+ const eyeRadiusX = size * (0.05 + staticRandom() * 0.015);
9123
+ const eyeRadiusY = eyeRadiusX * (1.16 + staticRandom() * 0.2);
9124
+ const bodyPoints = createOrganicOctopusBodyPoints({
9125
+ centerX,
9126
+ centerY,
9127
+ bodyRadius,
9128
+ horizontalStretch,
9129
+ verticalStretch,
9130
+ mantleLift,
9131
+ lowerDrop,
9132
+ tentacleDepth,
9133
+ wobbleAmplitude,
9134
+ lobeCount,
9135
+ shapePhase,
9136
+ timeMs,
9137
+ pointCount: 40,
9138
+ });
9139
+ const tentacleShapes = createOrganicOctopusTentacleShapes({
9140
+ size,
9141
+ centerX,
9142
+ centerY,
9143
+ bodyRadius,
9144
+ horizontalStretch,
9145
+ tentacleCount,
9146
+ shapePhase,
9147
+ createRandom,
9148
+ timeMs,
9149
+ saltPrefix: 'ascii-octopus',
9150
+ bodyPoints,
9151
+ });
9152
+ const sampledTentacles = tentacleShapes.map(sampleOrganicTentacleRibbonPoints);
9153
+ const leftEye = {
9154
+ centerX: centerX - eyeSpacing,
9155
+ centerY: centerY - size * 0.01,
9156
+ radiusX: eyeRadiusX,
9157
+ radiusY: eyeRadiusY,
9158
+ rotation: (staticRandom() - 0.5) * 0.24,
9159
+ phase: shapePhase,
9160
+ };
9161
+ const rightEye = {
9162
+ centerX: centerX + eyeSpacing,
9163
+ centerY: centerY - size * 0.01,
9164
+ radiusX: eyeRadiusX,
9165
+ radiusY: eyeRadiusY,
9166
+ rotation: (staticRandom() - 0.5) * 0.24,
9167
+ phase: shapePhase + Math.PI / 4,
9168
+ };
9169
+ const mouthPoints = sampleQuadraticBezierPoints({ x: centerX - size * 0.074, y: centerY + size * 0.092 }, {
9170
+ x: centerX,
9171
+ y: centerY +
9172
+ size * (0.142 + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
9173
+ interaction.gazeY * size * 0.012,
9174
+ }, { x: centerX + size * 0.074, y: centerY + size * 0.092 }, 12);
9175
+ let leftBound = Number.POSITIVE_INFINITY;
9176
+ let rightBound = Number.NEGATIVE_INFINITY;
9177
+ let topBound = Number.POSITIVE_INFINITY;
9178
+ let bottomBound = Number.NEGATIVE_INFINITY;
9179
+ for (const bodyPoint of bodyPoints) {
9180
+ leftBound = Math.min(leftBound, bodyPoint.x);
9181
+ rightBound = Math.max(rightBound, bodyPoint.x);
9182
+ topBound = Math.min(topBound, bodyPoint.y);
9183
+ bottomBound = Math.max(bottomBound, bodyPoint.y);
9184
+ }
9185
+ for (const sampledTentacle of sampledTentacles) {
9186
+ for (const ribbonPoint of sampledTentacle) {
9187
+ leftBound = Math.min(leftBound, ribbonPoint.x - ribbonPoint.width);
9188
+ rightBound = Math.max(rightBound, ribbonPoint.x + ribbonPoint.width);
9189
+ topBound = Math.min(topBound, ribbonPoint.y - ribbonPoint.width);
9190
+ bottomBound = Math.max(bottomBound, ribbonPoint.y + ribbonPoint.width);
9191
+ }
9192
+ }
9193
+ return {
9194
+ centerX,
9195
+ centerY,
9196
+ bodyRadius,
9197
+ horizontalStretch,
9198
+ shapePhase,
9199
+ interaction,
9200
+ bodyPoints,
9201
+ sampledTentacles,
9202
+ leftEye,
9203
+ rightEye,
9204
+ mouthPoints,
9205
+ leftBound: leftBound - size * 0.08,
9206
+ rightBound: rightBound + size * 0.08,
9207
+ topBound: topBound - size * 0.08,
9208
+ bottomBound: bottomBound + size * 0.08,
9209
+ };
9210
+ }
9211
+ /**
9212
+ * Samples points along a quadratic Bezier curve.
9213
+ *
9214
+ * @param startPoint Curve start point.
9215
+ * @param controlPoint Curve control point.
9216
+ * @param endPoint Curve end point.
9217
+ * @param pointCount Number of intervals to sample.
9218
+ * @returns Sampled curve points.
9219
+ *
9220
+ * @private helper of `asciiOctopusAvatarVisual`
9221
+ */
9222
+ function sampleQuadraticBezierPoints(startPoint, controlPoint, endPoint, pointCount) {
9223
+ return Array.from({ length: pointCount + 1 }, (_, pointIndex) => {
9224
+ const progress = pointIndex / pointCount;
9225
+ const inverseProgress = 1 - progress;
9226
+ return {
9227
+ x: inverseProgress * inverseProgress * startPoint.x +
9228
+ 2 * inverseProgress * progress * controlPoint.x +
9229
+ progress * progress * endPoint.x,
9230
+ y: inverseProgress * inverseProgress * startPoint.y +
9231
+ 2 * inverseProgress * progress * controlPoint.y +
9232
+ progress * progress * endPoint.y,
9233
+ };
9234
+ });
9235
+ }
9236
+ /**
9237
+ * Measures how strongly the sampled cell intersects with the generated tentacles.
9238
+ *
9239
+ * @param point Sampled cell point.
9240
+ * @param sampledTentacles Pre-sampled tentacle ribbons.
9241
+ * @param cellWidth Character cell width.
9242
+ * @returns Nearest tentacle coverage or `null`.
9243
+ *
9244
+ * @private helper of `asciiOctopusAvatarVisual`
9245
+ */
9246
+ function measureTentacleCoverage(point, sampledTentacles, cellWidth) {
9247
+ let bestTentacleCoverage = null;
9248
+ let bestNormalizedDistance = 0;
9249
+ for (const sampledTentacle of sampledTentacles) {
9250
+ for (const ribbonPoint of sampledTentacle) {
9251
+ const deltaX = point.x - ribbonPoint.x;
9252
+ const deltaY = point.y - ribbonPoint.y;
9253
+ const distance = Math.hypot(deltaX, deltaY);
9254
+ const coverageRadius = ribbonPoint.width + cellWidth * 0.22;
9255
+ const normalizedDistance = 1 - distance / coverageRadius;
9256
+ if (normalizedDistance <= bestNormalizedDistance || normalizedDistance <= 0) {
9257
+ continue;
9258
+ }
9259
+ bestNormalizedDistance = normalizedDistance;
9260
+ bestTentacleCoverage = {
9261
+ tangentAngle: Math.atan2(-ribbonPoint.normalX, ribbonPoint.normalY),
9262
+ progress: ribbonPoint.progress,
9263
+ normalizedDistance,
9264
+ };
9265
+ }
9266
+ }
9267
+ return bestTentacleCoverage;
9268
+ }
9269
+ /**
9270
+ * Picks one ASCII character that matches the nearest tentacle direction.
9271
+ *
9272
+ * @param tentacleCoverage Nearest tentacle coverage.
9273
+ * @param noise Stable per-cell noise.
9274
+ * @returns Tentacle ASCII character.
9275
+ *
9276
+ * @private helper of `asciiOctopusAvatarVisual`
9277
+ */
9278
+ function pickTentacleCharacter(tentacleCoverage, noise) {
9279
+ const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.82;
9280
+ if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.34) {
9281
+ return noise > 0.91 ? '0' : 'o';
9282
+ }
9283
+ const horizontalWeight = Math.abs(Math.cos(tentacleCoverage.tangentAngle));
9284
+ const verticalWeight = Math.abs(Math.sin(tentacleCoverage.tangentAngle));
9285
+ if (horizontalWeight > 0.84) {
9286
+ return noise > 0.52 ? '=' : '-';
9287
+ }
9288
+ if (verticalWeight > 0.82) {
9289
+ return noise > 0.56 ? '|' : '!';
9290
+ }
9291
+ return Math.sin(tentacleCoverage.tangentAngle) * Math.cos(tentacleCoverage.tangentAngle) > 0 ? '\\' : '/';
9292
+ }
9293
+ /**
9294
+ * Picks one character from an ordered ramp.
9295
+ *
9296
+ * @param glyphRamp Ordered glyph ramp.
9297
+ * @param intensity Normalized intensity in the range `[0, 1]`.
9298
+ * @returns Selected glyph.
9299
+ *
9300
+ * @private helper of `asciiOctopusAvatarVisual`
9301
+ */
9302
+ function pickRampCharacter(glyphRamp, intensity) {
9303
+ const characterIndex = Math.min(glyphRamp.length - 1, Math.floor(clamp01(intensity) * glyphRamp.length));
9304
+ return glyphRamp[characterIndex];
9305
+ }
9306
+ /**
9307
+ * Measures the normalized distance from a point to a rotated ellipse.
9308
+ *
9309
+ * @param point Sampled cell point.
9310
+ * @param centerX Ellipse center X coordinate.
9311
+ * @param centerY Ellipse center Y coordinate.
9312
+ * @param radiusX Horizontal ellipse radius.
9313
+ * @param radiusY Vertical ellipse radius.
9314
+ * @param rotation Ellipse rotation in radians.
9315
+ * @returns Normalized ellipse distance where values below `1` are inside.
9316
+ *
9317
+ * @private helper of `asciiOctopusAvatarVisual`
9318
+ */
9319
+ function measureRotatedEllipseDistance(point, centerX, centerY, radiusX, radiusY, rotation) {
9320
+ const cosine = Math.cos(rotation);
9321
+ const sine = Math.sin(rotation);
9322
+ const translatedX = point.x - centerX;
9323
+ const translatedY = point.y - centerY;
9324
+ const localX = translatedX * cosine + translatedY * sine;
9325
+ const localY = -translatedX * sine + translatedY * cosine;
9326
+ return Math.sqrt((localX * localX) / (radiusX * radiusX) + (localY * localY) / (radiusY * radiusY));
9327
+ }
9328
+ /**
9329
+ * Checks whether a point lies inside the given closed polygon.
9330
+ *
9331
+ * @param point Sampled cell point.
9332
+ * @param polygonPoints Polygon points in order.
9333
+ * @returns `true` when the point lies inside the polygon.
9334
+ *
9335
+ * @private helper of `asciiOctopusAvatarVisual`
9336
+ */
9337
+ function isPointInsidePolygon(point, polygonPoints) {
9338
+ let isInside = false;
9339
+ for (let currentPointIndex = 0, previousPointIndex = polygonPoints.length - 1; currentPointIndex < polygonPoints.length; previousPointIndex = currentPointIndex++) {
9340
+ const currentPoint = polygonPoints[currentPointIndex];
9341
+ const previousPoint = polygonPoints[previousPointIndex];
9342
+ const isIntersecting = currentPoint.y > point.y !== previousPoint.y > point.y &&
9343
+ point.x <
9344
+ ((previousPoint.x - currentPoint.x) * (point.y - currentPoint.y)) / (previousPoint.y - currentPoint.y) +
9345
+ currentPoint.x;
9346
+ if (isIntersecting) {
9347
+ isInside = !isInside;
9348
+ }
9349
+ }
9350
+ return isInside;
9351
+ }
9352
+ /**
9353
+ * Measures the shortest distance from a point to a polyline.
9354
+ *
9355
+ * @param point Sampled cell point.
9356
+ * @param polylinePoints Polyline points in order.
9357
+ * @param isClosed Whether the final point should connect back to the first point.
9358
+ * @returns Shortest distance to the polyline.
9359
+ *
9360
+ * @private helper of `asciiOctopusAvatarVisual`
9361
+ */
9362
+ function getDistanceToPolyline(point, polylinePoints, isClosed) {
9363
+ let shortestDistance = Number.POSITIVE_INFINITY;
9364
+ const segmentCount = isClosed ? polylinePoints.length : polylinePoints.length - 1;
9365
+ for (let segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) {
9366
+ const startPoint = polylinePoints[segmentIndex];
9367
+ const endPoint = polylinePoints[(segmentIndex + 1) % polylinePoints.length];
9368
+ shortestDistance = Math.min(shortestDistance, getDistanceToLineSegment(point, startPoint, endPoint));
9369
+ }
9370
+ return shortestDistance;
9371
+ }
9372
+ /**
9373
+ * Measures the shortest distance from a point to one line segment.
9374
+ *
9375
+ * @param point Sampled cell point.
9376
+ * @param startPoint Segment start point.
9377
+ * @param endPoint Segment end point.
9378
+ * @returns Shortest distance to the segment.
9379
+ *
9380
+ * @private helper of `asciiOctopusAvatarVisual`
9381
+ */
9382
+ function getDistanceToLineSegment(point, startPoint, endPoint) {
9383
+ const deltaX = endPoint.x - startPoint.x;
9384
+ const deltaY = endPoint.y - startPoint.y;
9385
+ const segmentLengthSquared = deltaX * deltaX + deltaY * deltaY;
9386
+ if (segmentLengthSquared === 0) {
9387
+ return Math.hypot(point.x - startPoint.x, point.y - startPoint.y);
9388
+ }
9389
+ const progress = clamp01(((point.x - startPoint.x) * deltaX + (point.y - startPoint.y) * deltaY) / segmentLengthSquared);
9390
+ const projectionX = startPoint.x + deltaX * progress;
9391
+ const projectionY = startPoint.y + deltaY * progress;
9392
+ return Math.hypot(point.x - projectionX, point.y - projectionY);
9393
+ }
9394
+ /**
9395
+ * Clamps a number into the inclusive range `[0, 1]`.
9396
+ *
9397
+ * @param value Arbitrary numeric value.
9398
+ * @returns Clamped value.
9399
+ *
9400
+ * @private helper of `asciiOctopusAvatarVisual`
9401
+ */
9402
+ function clamp01(value) {
9403
+ return Math.max(0, Math.min(1, value));
9404
+ }
9405
+
9406
+ /* eslint-disable no-magic-numbers */
9407
+ /**
9408
+ * Fractal avatar visual.
9409
+ *
9410
+ * @private built-in avatar visual
9411
+ */
9412
+ const fractalAvatarVisual = {
9413
+ id: 'fractal',
9414
+ title: 'Fractal',
9415
+ description: 'Layered dragon-curve ribbons with deterministic glows, bends, and seeded color interplay.',
9416
+ isAnimated: true,
9417
+ render({ context, size, palette, createRandom, timeMs }) {
9418
+ const staticRandom = createRandom('fractal-static');
9419
+ const centerX = size * 0.5;
9420
+ const centerY = size * 0.5;
9421
+ const layerCount = 2 + Math.floor(staticRandom() * 3);
9422
+ const haloRotation = staticRandom() * Math.PI * 2;
9423
+ const colorSequence = [palette.primary, palette.secondary, palette.accent, palette.highlight];
9424
+ drawAvatarFrame(context, size, palette);
9425
+ drawFractalBackground(context, size, palette, timeMs, haloRotation);
9426
+ for (let layerIndex = 0; layerIndex < layerCount; layerIndex++) {
9427
+ const layerRandom = createRandom(`fractal-layer-${layerIndex}`);
9428
+ const order = 8 + Math.floor(layerRandom() * 4);
9429
+ const turnSequence = createDragonCurveTurns(order);
9430
+ const basePoints = createDragonCurvePoints(turnSequence);
9431
+ const transformedPoints = transformDragonCurvePoints(basePoints, {
9432
+ size,
9433
+ centerX: centerX + (layerRandom() - 0.5) * size * 0.08,
9434
+ centerY: centerY + (layerRandom() - 0.5) * size * 0.08,
9435
+ rotation: layerRandom() * Math.PI * 2 + Math.sin(timeMs / (1700 + layerIndex * 280) + layerIndex) * 0.14,
9436
+ scale: size * (0.19 + layerIndex * 0.055 + layerRandom() * 0.045),
9437
+ horizontalStretch: 0.74 + layerRandom() * 0.9,
9438
+ verticalStretch: 0.74 + layerRandom() * 0.9,
9439
+ warpAmplitude: size * (0.008 + layerRandom() * 0.012),
9440
+ warpPhase: layerRandom() * Math.PI * 2,
9441
+ mirrorX: layerRandom() < 0.5 ? -1 : 1,
9442
+ mirrorY: layerRandom() < 0.38 ? -1 : 1,
9443
+ timeMs,
9444
+ });
9445
+ const primaryColor = colorSequence[layerIndex % colorSequence.length];
9446
+ const secondaryColor = colorSequence[(layerIndex + 1) % colorSequence.length];
9447
+ const tertiaryColor = colorSequence[(layerIndex + 2) % colorSequence.length];
9448
+ const strokeWidth = size * (0.026 - layerIndex * 0.0035);
9449
+ drawDragonCurveLayer(context, transformedPoints, {
9450
+ size,
9451
+ primaryColor,
9452
+ secondaryColor,
9453
+ tertiaryColor,
9454
+ shadowColor: palette.shadow,
9455
+ strokeWidth,
9456
+ timeMs,
9457
+ layerIndex,
9458
+ });
9459
+ }
9460
+ drawFractalCore(context, size, palette, timeMs, staticRandom());
9461
+ },
9462
+ };
9463
+ /**
9464
+ * Draws the shared luminous atmosphere behind the curve layers.
9465
+ *
9466
+ * @param context Canvas 2D context.
9467
+ * @param size Canvas size in CSS pixels.
9468
+ * @param palette Derived avatar palette.
9469
+ * @param timeMs Current animation time in milliseconds.
9470
+ * @param haloRotation Seed-based phase offset.
9471
+ *
9472
+ * @private helper of `fractalAvatarVisual`
9473
+ */
9474
+ function drawFractalBackground(context, size, palette, timeMs, haloRotation) {
9475
+ const centerX = size * 0.5;
9476
+ const centerY = size * 0.5;
9477
+ const radialGlow = context.createRadialGradient(centerX, centerY, size * 0.06, centerX, centerY, size * 0.72);
9478
+ radialGlow.addColorStop(0, `${palette.highlight}55`);
9479
+ radialGlow.addColorStop(0.4, `${palette.secondary}1f`);
9480
+ radialGlow.addColorStop(1, `${palette.highlight}00`);
9481
+ context.fillStyle = radialGlow;
9482
+ context.fillRect(0, 0, size, size);
9483
+ for (let haloIndex = 0; haloIndex < 3; haloIndex++) {
9484
+ const radius = size * (0.17 + haloIndex * 0.09);
9485
+ const rotation = haloRotation + haloIndex * 0.85 + timeMs / (4400 + haloIndex * 700);
9486
+ context.beginPath();
9487
+ context.ellipse(centerX, centerY, radius, radius * (0.62 + haloIndex * 0.06), rotation, 0, Math.PI * 2);
9488
+ context.strokeStyle = haloIndex % 2 === 0 ? `${palette.secondary}24` : `${palette.accent}20`;
9489
+ context.lineWidth = size * 0.006;
9490
+ context.stroke();
9491
+ }
9492
+ }
9493
+ /**
9494
+ * Generates the left-right turn sequence for a dragon curve.
9495
+ *
9496
+ * @param order Number of folding iterations.
9497
+ * @returns Turn sequence where `1` means right and `-1` means left.
9498
+ *
9499
+ * @private helper of `fractalAvatarVisual`
9500
+ */
9501
+ function createDragonCurveTurns(order) {
9502
+ let turns = [];
9503
+ for (let iteration = 0; iteration < order; iteration++) {
9504
+ turns = [
9505
+ ...turns,
9506
+ 1,
9507
+ ...turns
9508
+ .slice()
9509
+ .reverse()
9510
+ .map((turn) => (turn === 1 ? -1 : 1)),
9511
+ ];
9512
+ }
9513
+ return turns;
9514
+ }
9515
+ /**
9516
+ * Converts a dragon-curve turn sequence into a raw grid polyline.
9517
+ *
9518
+ * @param turnSequence Ordered turn sequence.
9519
+ * @returns Unscaled polyline points.
9520
+ *
9521
+ * @private helper of `fractalAvatarVisual`
9522
+ */
9523
+ function createDragonCurvePoints(turnSequence) {
9524
+ const points = [{ x: 0, y: 0 }];
9525
+ const directions = [
9526
+ { x: 1, y: 0 },
9527
+ { x: 0, y: 1 },
9528
+ { x: -1, y: 0 },
9529
+ { x: 0, y: -1 },
9530
+ ];
9531
+ let directionIndex = 0;
9532
+ for (let segmentIndex = 0; segmentIndex <= turnSequence.length; segmentIndex++) {
9533
+ const currentPoint = points[points.length - 1];
9534
+ const direction = directions[directionIndex];
9535
+ points.push({
9536
+ x: currentPoint.x + direction.x,
9537
+ y: currentPoint.y + direction.y,
9538
+ });
9539
+ if (segmentIndex < turnSequence.length) {
9540
+ directionIndex = (directionIndex + turnSequence[segmentIndex] + directions.length) % directions.length;
9541
+ }
9542
+ }
9543
+ return points;
9544
+ }
9545
+ /**
9546
+ * Normalizes and decorates the dragon-curve polyline for avatar rendering.
9547
+ *
9548
+ * @param points Raw grid polyline points.
9549
+ * @param options Transformation parameters.
9550
+ * @returns Transformed canvas points.
9551
+ *
9552
+ * @private helper of `fractalAvatarVisual`
9553
+ */
9554
+ function transformDragonCurvePoints(points, options) {
9555
+ const { size, centerX, centerY, rotation, scale, horizontalStretch, verticalStretch, warpAmplitude, warpPhase, mirrorX, mirrorY, timeMs, } = options;
9556
+ const bounds = getPointBounds(points);
9557
+ const width = Math.max(1, bounds.maxX - bounds.minX);
9558
+ const height = Math.max(1, bounds.maxY - bounds.minY);
9559
+ const normalizationScale = scale / Math.max(width, height);
9560
+ const cosine = Math.cos(rotation);
9561
+ const sine = Math.sin(rotation);
9562
+ return points.map((point, pointIndex) => {
9563
+ const normalizedX = (point.x - (bounds.minX + width / 2)) * normalizationScale * horizontalStretch * mirrorX;
9564
+ const normalizedY = (point.y - (bounds.minY + height / 2)) * normalizationScale * verticalStretch * mirrorY;
9565
+ const progress = pointIndex / Math.max(1, points.length - 1);
9566
+ const localWarp = Math.sin(progress * Math.PI * 4 + warpPhase + timeMs / 1400) * warpAmplitude +
9567
+ Math.cos(progress * Math.PI * 7 - warpPhase + timeMs / 1800) * warpAmplitude * 0.45;
9568
+ const rotatedX = normalizedX * cosine - normalizedY * sine;
9569
+ const rotatedY = normalizedX * sine + normalizedY * cosine;
9570
+ return {
9571
+ x: centerX + rotatedX + Math.sin(progress * Math.PI * 2 + warpPhase) * localWarp,
9572
+ y: centerY +
9573
+ rotatedY +
9574
+ Math.cos(progress * Math.PI * 3 + warpPhase * 0.6) * localWarp +
9575
+ (progress - 0.5) * size * 0.02,
9576
+ };
9577
+ });
9578
+ }
9579
+ /**
9580
+ * Returns the bounding box of a point cloud.
9581
+ *
9582
+ * @param points Point cloud to inspect.
9583
+ * @returns Bounding box.
9584
+ *
9585
+ * @private helper of `fractalAvatarVisual`
9586
+ */
9587
+ function getPointBounds(points) {
9588
+ return points.reduce((bounds, point) => ({
9589
+ minX: Math.min(bounds.minX, point.x),
9590
+ maxX: Math.max(bounds.maxX, point.x),
9591
+ minY: Math.min(bounds.minY, point.y),
9592
+ maxY: Math.max(bounds.maxY, point.y),
9593
+ }), {
9594
+ minX: Number.POSITIVE_INFINITY,
9595
+ maxX: Number.NEGATIVE_INFINITY,
9596
+ minY: Number.POSITIVE_INFINITY,
9597
+ maxY: Number.NEGATIVE_INFINITY,
9598
+ });
9599
+ }
9600
+ /**
9601
+ * Draws one stylized dragon-curve ribbon with glow and spark nodes.
9602
+ *
9603
+ * @param context Canvas 2D context.
9604
+ * @param points Transformed polyline points.
9605
+ * @param options Layer styling options.
9606
+ *
9607
+ * @private helper of `fractalAvatarVisual`
9608
+ */
9609
+ function drawDragonCurveLayer(context, points, options) {
9610
+ const { size, primaryColor, secondaryColor, tertiaryColor, shadowColor, strokeWidth, timeMs, layerIndex } = options;
9611
+ const firstPoint = points[0];
9612
+ const lastPoint = points[points.length - 1];
9613
+ const ribbonGradient = context.createLinearGradient(firstPoint.x, firstPoint.y, lastPoint.x, lastPoint.y);
9614
+ ribbonGradient.addColorStop(0, `${primaryColor}f2`);
9615
+ ribbonGradient.addColorStop(0.5, `${secondaryColor}e6`);
9616
+ ribbonGradient.addColorStop(1, `${tertiaryColor}f2`);
9617
+ context.save();
9618
+ context.beginPath();
9619
+ tracePolyline(context, points);
9620
+ context.strokeStyle = `${shadowColor}82`;
9621
+ context.lineWidth = strokeWidth * 1.8;
9622
+ context.lineJoin = 'round';
9623
+ context.lineCap = 'round';
9624
+ context.filter = `blur(${size * 0.022}px)`;
9625
+ context.stroke();
9626
+ context.restore();
9627
+ context.beginPath();
9628
+ tracePolyline(context, points);
9629
+ context.strokeStyle = ribbonGradient;
9630
+ context.lineWidth = strokeWidth;
9631
+ context.lineJoin = 'round';
9632
+ context.lineCap = 'round';
9633
+ context.stroke();
9634
+ context.beginPath();
9635
+ tracePolyline(context, points);
9636
+ context.strokeStyle = 'rgba(255,255,255,0.22)';
9637
+ context.lineWidth = Math.max(1.2, strokeWidth * 0.28);
9638
+ context.lineJoin = 'round';
9639
+ context.lineCap = 'round';
9640
+ context.stroke();
9641
+ const sparkStride = Math.max(24, Math.floor(points.length / 18));
9642
+ for (let pointIndex = sparkStride; pointIndex < points.length; pointIndex += sparkStride) {
9643
+ const point = points[pointIndex];
9644
+ const pulse = 0.7 + 0.3 * Math.sin(timeMs / 700 + pointIndex * 0.12 + layerIndex);
9645
+ const radius = strokeWidth * (0.24 + pulse * 0.22);
9646
+ context.beginPath();
9647
+ context.arc(point.x, point.y, radius * 1.8, 0, Math.PI * 2);
9648
+ context.fillStyle = `${secondaryColor}20`;
9649
+ context.fill();
9650
+ context.beginPath();
9651
+ context.arc(point.x, point.y, radius, 0, Math.PI * 2);
9652
+ context.fillStyle = tertiaryColor;
9653
+ context.fill();
9654
+ }
9655
+ }
9656
+ /**
9657
+ * Traces a polyline through the provided points.
9658
+ *
9659
+ * @param context Canvas 2D context.
9660
+ * @param points Polyline points.
9661
+ *
9662
+ * @private helper of `fractalAvatarVisual`
9663
+ */
9664
+ function tracePolyline(context, points) {
9665
+ const firstPoint = points[0];
9666
+ context.moveTo(firstPoint.x, firstPoint.y);
9667
+ for (let pointIndex = 1; pointIndex < points.length; pointIndex++) {
9668
+ const point = points[pointIndex];
9669
+ context.lineTo(point.x, point.y);
9670
+ }
9671
+ }
9672
+ /**
9673
+ * Draws the central crystalline accent tying the dragon-curve layers together.
9674
+ *
9675
+ * @param context Canvas 2D context.
9676
+ * @param size Canvas size in CSS pixels.
9677
+ * @param palette Derived avatar palette.
9678
+ * @param timeMs Current animation time in milliseconds.
9679
+ * @param corePhase Seed-based phase offset.
9680
+ *
9681
+ * @private helper of `fractalAvatarVisual`
9682
+ */
9683
+ function drawFractalCore(context, size, palette, timeMs, corePhase) {
9684
+ const centerX = size * 0.5;
9685
+ const centerY = size * 0.5;
9686
+ const radius = size * 0.082;
9687
+ const rotation = corePhase * Math.PI * 2 + timeMs / 2200;
9688
+ const innerRotation = -rotation * 1.35;
9689
+ context.save();
9690
+ context.translate(centerX, centerY);
9691
+ context.rotate(rotation);
9692
+ context.beginPath();
9693
+ for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
9694
+ const angle = (pointIndex / 4) * Math.PI * 2;
9695
+ const x = Math.cos(angle) * radius;
9696
+ const y = Math.sin(angle) * radius;
9697
+ if (pointIndex === 0) {
9698
+ context.moveTo(x, y);
9699
+ }
9700
+ else {
9701
+ context.lineTo(x, y);
9702
+ }
9703
+ }
9704
+ context.closePath();
9705
+ context.fillStyle = `${palette.highlight}88`;
9706
+ context.shadowColor = `${palette.highlight}77`;
9707
+ context.shadowBlur = size * 0.05;
9708
+ context.fill();
9709
+ context.restore();
9710
+ context.save();
9711
+ context.translate(centerX, centerY);
9712
+ context.rotate(innerRotation);
9713
+ context.beginPath();
9714
+ for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
9715
+ const angle = Math.PI / 4 + (pointIndex / 4) * Math.PI * 2;
9716
+ const x = Math.cos(angle) * radius * 0.55;
9717
+ const y = Math.sin(angle) * radius * 0.55;
9718
+ if (pointIndex === 0) {
9719
+ context.moveTo(x, y);
9720
+ }
9721
+ else {
9722
+ context.lineTo(x, y);
9723
+ }
9724
+ }
9725
+ context.closePath();
9726
+ context.fillStyle = `${palette.ink}cc`;
9727
+ context.fill();
9728
+ context.restore();
9729
+ }
9730
+
9731
+ /* eslint-disable no-magic-numbers */
9732
+ /**
9733
+ * Minecraft-style 3D avatar visual.
9734
+ *
9735
+ * @private built-in avatar visual
9736
+ */
9737
+ const minecraftAvatarVisual = {
9738
+ id: 'minecraft',
9739
+ title: 'Minecraft 3D',
9740
+ description: 'Blocky 3D portrait with deterministic pixel textures, shoulders, and hovering depth.',
9741
+ isAnimated: true,
9742
+ render({ context, size, palette, createRandom, timeMs }) {
9743
+ const random = createRandom('minecraft');
9744
+ const bob = Math.sin(timeMs / 880) * size * 0.015;
9745
+ const headSize = size * 0.34;
9746
+ const depth = headSize * 0.22;
9747
+ const headX = size * 0.31;
9748
+ const headY = size * 0.18 + bob;
9749
+ const bodyWidth = headSize * 0.86;
9750
+ const bodyHeight = headSize * 0.82;
9751
+ const bodyDepth = depth * 0.8;
9752
+ const bodyX = size * 0.33;
9753
+ const bodyY = headY + headSize * 0.96;
9754
+ const hasHeadband = random() < 0.5;
9755
+ const faceTexture = createMinecraftFaceTexture(createRandom('minecraft-face'), palette, hasHeadband);
9756
+ const shirtTexture = createMinecraftShirtTexture(createRandom('minecraft-shirt'), palette);
9757
+ drawAvatarFrame(context, size, palette);
9758
+ const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
9759
+ spotlight.addColorStop(0, `${palette.highlight}66`);
9760
+ spotlight.addColorStop(1, `${palette.highlight}00`);
9761
+ context.fillStyle = spotlight;
9762
+ context.fillRect(0, 0, size, size);
9763
+ context.save();
9764
+ context.fillStyle = 'rgba(0, 0, 0, 0.22)';
9765
+ context.filter = `blur(${size * 0.018}px)`;
9766
+ context.beginPath();
9767
+ context.ellipse(size * 0.5, size * 0.86, size * 0.2, size * 0.06, 0, 0, Math.PI * 2);
9768
+ context.fill();
9769
+ context.restore();
9770
+ drawVoxelCuboid(context, {
9771
+ x: bodyX,
9772
+ y: bodyY,
9773
+ width: bodyWidth,
9774
+ height: bodyHeight,
9775
+ depth: bodyDepth,
9776
+ frontTexture: shirtTexture,
9777
+ topColor: `${palette.highlight}cc`,
9778
+ sideColor: `${palette.secondary}dd`,
9779
+ outlineColor: `${palette.shadow}aa`,
9780
+ });
9781
+ drawVoxelCuboid(context, {
9782
+ x: headX,
9783
+ y: headY,
9784
+ width: headSize,
9785
+ height: headSize,
9786
+ depth,
9787
+ frontTexture: faceTexture,
9788
+ topColor: `${palette.highlight}ee`,
9789
+ sideColor: `${palette.secondary}ee`,
9790
+ outlineColor: `${palette.shadow}cc`,
9791
+ });
9792
+ },
9793
+ };
9794
+ /**
9795
+ * Draws a stylized voxel cuboid with a front pixel texture.
9796
+ *
9797
+ * @param context Canvas 2D context.
9798
+ * @param cuboid Cuboid settings.
9799
+ *
9800
+ * @private helper of `minecraftAvatarVisual`
9801
+ */
9802
+ function drawVoxelCuboid(context, cuboid) {
9803
+ var _a;
9804
+ const { x, y, width, height, depth, frontTexture, topColor, sideColor, outlineColor } = cuboid;
9805
+ const lift = depth * 0.6;
9806
+ context.save();
9807
+ context.beginPath();
9808
+ context.moveTo(x, y);
9809
+ context.lineTo(x + depth, y - lift);
9810
+ context.lineTo(x + width + depth, y - lift);
9811
+ context.lineTo(x + width, y);
9812
+ context.closePath();
9813
+ context.fillStyle = topColor;
9814
+ context.fill();
9815
+ context.restore();
9816
+ context.save();
9817
+ context.beginPath();
9818
+ context.moveTo(x + width, y);
9819
+ context.lineTo(x + width + depth, y - lift);
9820
+ context.lineTo(x + width + depth, y + height - lift);
9821
+ context.lineTo(x + width, y + height);
9822
+ context.closePath();
9823
+ context.fillStyle = sideColor;
9824
+ context.fill();
9825
+ context.restore();
9826
+ const rows = frontTexture.length;
9827
+ const columns = ((_a = frontTexture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
9828
+ const pixelWidth = width / Math.max(columns, 1);
9829
+ const pixelHeight = height / Math.max(rows, 1);
9830
+ context.save();
9831
+ createRoundedRectPath(context, x, y, width, height, width * 0.03);
9832
+ context.clip();
9833
+ for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
9834
+ for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
9835
+ context.fillStyle = frontTexture[rowIndex][columnIndex];
9836
+ context.fillRect(x + columnIndex * pixelWidth, y + rowIndex * pixelHeight, pixelWidth, pixelHeight);
9837
+ }
9838
+ }
9839
+ context.restore();
9840
+ context.strokeStyle = outlineColor;
9841
+ context.lineWidth = Math.max(1.2, width * 0.025);
9842
+ context.beginPath();
9843
+ context.moveTo(x, y);
9844
+ context.lineTo(x + depth, y - lift);
9845
+ context.lineTo(x + width + depth, y - lift);
9846
+ context.lineTo(x + width + depth, y + height - lift);
9847
+ context.lineTo(x + width, y + height);
9848
+ context.lineTo(x, y + height);
9849
+ context.closePath();
9850
+ context.stroke();
9851
+ }
9852
+ /**
9853
+ * Creates the front-face pixel texture for the cube head.
9854
+ *
9855
+ * @param random Seeded random generator.
9856
+ * @param palette Derived avatar palette.
9857
+ * @param hasHeadband Whether the avatar should render a headband row.
9858
+ * @returns 8x8 pixel texture.
9859
+ *
9860
+ * @private helper of `minecraftAvatarVisual`
9861
+ */
9862
+ function createMinecraftFaceTexture(random, palette, hasHeadband) {
9863
+ const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.highlight));
9864
+ const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
9865
+ const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
9866
+ for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
9867
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
9868
+ texture[rowIndex][columnIndex] = hairlineColor;
9869
+ }
9870
+ }
9871
+ texture[2][0] = hairlineColor;
9872
+ texture[2][7] = hairlineColor;
9873
+ texture[3][0] = hairlineColor;
9874
+ texture[3][7] = hairlineColor;
9875
+ if (hasHeadband) {
9876
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
9877
+ texture[2][columnIndex] = palette.accent;
9878
+ }
9879
+ }
9880
+ texture[3][2] = palette.ink;
9881
+ texture[3][5] = palette.ink;
9882
+ texture[4][2] = '#ffffff';
9883
+ texture[4][5] = '#ffffff';
9884
+ texture[5][1] = cheekColor;
9885
+ texture[5][6] = cheekColor;
9886
+ texture[5][3] = palette.shadow;
9887
+ texture[5][4] = palette.shadow;
9888
+ texture[6][3] = palette.shadow;
9889
+ texture[6][4] = palette.shadow;
9890
+ return texture;
9891
+ }
9892
+ /**
9893
+ * Creates the front-face pixel texture for the torso.
9894
+ *
9895
+ * @param random Seeded random generator.
9896
+ * @param palette Derived avatar palette.
9897
+ * @returns 8x8 torso texture.
9898
+ *
9899
+ * @private helper of `minecraftAvatarVisual`
9900
+ */
9901
+ function createMinecraftShirtTexture(random, palette) {
9902
+ const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.primary));
9903
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
9904
+ for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
9905
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
9906
+ texture[rowIndex][columnIndex] = palette.shadow;
9907
+ }
9908
+ }
9909
+ for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
9910
+ texture[rowIndex][3] = stripeColor;
9911
+ texture[rowIndex][4] = stripeColor;
9912
+ }
9913
+ texture[4][1] = palette.accent;
9914
+ texture[4][6] = palette.accent;
9915
+ texture[5][2] = palette.highlight;
9916
+ texture[5][5] = palette.highlight;
9917
+ return texture;
9918
+ }
9919
+
9920
+ /* eslint-disable no-magic-numbers */
9921
+ /**
9922
+ * Octopus avatar visual.
9923
+ *
9924
+ * @private built-in avatar visual
9925
+ */
9926
+ const octopusAvatarVisual = {
9927
+ id: 'octopus',
9928
+ title: 'Octopus',
9929
+ description: 'Playful underwater mascot with cursor-following eyes, animated tentacles, bubbles, and seeded markings.',
9930
+ isAnimated: true,
9931
+ supportsPointerTracking: true,
9932
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
9933
+ const staticRandom = createRandom('octopus-static');
9934
+ const bubbleRandom = createRandom('octopus-bubbles');
9935
+ const bubbleCount = 8;
9936
+ const bubbleRadiusBase = size * 0.02;
9937
+ const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.035;
9938
+ const centerY = size * 0.42 + interaction.bodyOffsetY * size * 0.024;
9939
+ const headRadius = size * (0.19 + staticRandom() * 0.03);
9940
+ const mantleHeight = headRadius * 1.18;
9941
+ const tentacleLength = size * (0.18 + staticRandom() * 0.06);
9942
+ const tentaclePhases = Array.from({ length: 8 }, () => staticRandom() * Math.PI * 2);
9943
+ const spotCount = 3 + Math.floor(staticRandom() * 4);
9944
+ const spotColors = [palette.secondary, palette.accent, palette.highlight];
9945
+ drawAvatarFrame(context, size, palette);
9946
+ const waterGlow = context.createRadialGradient(centerX, size * 0.22, size * 0.06, centerX, size * 0.22, size * 0.58);
9947
+ waterGlow.addColorStop(0, `${palette.highlight}66`);
9948
+ waterGlow.addColorStop(1, `${palette.highlight}00`);
9949
+ context.fillStyle = waterGlow;
9950
+ context.fillRect(0, 0, size, size);
9951
+ for (let bubbleIndex = 0; bubbleIndex < bubbleCount; bubbleIndex++) {
9952
+ const x = size * (0.15 + bubbleRandom() * 0.7);
9953
+ const y = size * (0.12 + bubbleRandom() * 0.68);
9954
+ const radius = bubbleRadiusBase * (0.6 + bubbleRandom() * 2.3);
9955
+ context.beginPath();
9956
+ context.arc(x, y, radius, 0, Math.PI * 2);
9957
+ context.fillStyle = 'rgba(255,255,255,0.08)';
9958
+ context.fill();
9959
+ context.beginPath();
9960
+ context.arc(x - radius * 0.22, y - radius * 0.22, radius * 0.25, 0, Math.PI * 2);
9961
+ context.fillStyle = 'rgba(255,255,255,0.28)';
9962
+ context.fill();
9963
+ }
9964
+ for (let tentacleIndex = 0; tentacleIndex < 8; tentacleIndex++) {
9965
+ const startX = centerX + (tentacleIndex - 3.5) * headRadius * 0.19;
9966
+ const startY = centerY + headRadius * 0.62;
9967
+ const animationPhase = tentaclePhases[tentacleIndex];
9968
+ const sway = Math.sin(timeMs / 520 + animationPhase) * size * 0.03;
9969
+ const endX = startX + (tentacleIndex - 3.5) * size * 0.025 + sway;
9970
+ const endY = startY + tentacleLength + Math.cos(timeMs / 700 + animationPhase) * size * 0.01;
9971
+ const controlX = (startX + endX) / 2 + sway * 0.8;
9972
+ const controlY = startY + tentacleLength * 0.45;
9973
+ const lineWidth = size * (0.042 - tentacleIndex * 0.0022);
9974
+ context.beginPath();
9975
+ context.moveTo(startX, startY);
9976
+ context.quadraticCurveTo(controlX, controlY, endX, endY);
9977
+ context.lineCap = 'round';
9978
+ context.strokeStyle = palette.primary;
9979
+ context.lineWidth = lineWidth;
9980
+ context.stroke();
9981
+ for (let cupIndex = 1; cupIndex <= 3; cupIndex++) {
9982
+ const cupT = cupIndex / 4;
9983
+ const cupX = (1 - cupT) * (1 - cupT) * startX + 2 * (1 - cupT) * cupT * controlX + cupT * cupT * endX;
9984
+ const cupY = (1 - cupT) * (1 - cupT) * startY + 2 * (1 - cupT) * cupT * controlY + cupT * cupT * endY;
9985
+ context.beginPath();
9986
+ context.arc(cupX, cupY, lineWidth * 0.18, 0, Math.PI * 2);
9987
+ context.fillStyle = `${palette.highlight}cc`;
9988
+ context.fill();
9989
+ }
9990
+ }
9991
+ context.save();
9992
+ context.fillStyle = palette.primary;
9993
+ context.shadowColor = `${palette.shadow}88`;
9994
+ context.shadowBlur = size * 0.08;
9995
+ context.beginPath();
9996
+ context.ellipse(centerX, centerY, headRadius, mantleHeight, 0, Math.PI, 0, true);
9997
+ context.lineTo(centerX + headRadius, centerY);
9998
+ context.ellipse(centerX, centerY, headRadius, headRadius * 0.82, 0, 0, Math.PI);
9999
+ context.closePath();
10000
+ context.fill();
10001
+ context.restore();
10002
+ context.beginPath();
10003
+ context.ellipse(centerX, centerY - headRadius * 0.22, headRadius * 0.74, headRadius * 0.42, 0, Math.PI, Math.PI * 2);
10004
+ context.fillStyle = `${palette.highlight}55`;
10005
+ context.fill();
10006
+ for (let spotIndex = 0; spotIndex < spotCount; spotIndex++) {
10007
+ const spotRandom = createRandom(`octopus-spot-${spotIndex}`);
10008
+ const spotX = centerX + (spotRandom() - 0.5) * headRadius * 1.1;
10009
+ const spotY = centerY - headRadius * 0.05 + (spotRandom() - 0.5) * headRadius * 0.9;
10010
+ const spotRadius = headRadius * (0.07 + spotRandom() * 0.07);
10011
+ context.beginPath();
10012
+ context.arc(spotX, spotY, spotRadius, 0, Math.PI * 2);
10013
+ context.fillStyle = pickRandomItem(spotColors, spotRandom);
10014
+ context.fill();
10015
+ }
10016
+ const eyeOffsetX = headRadius * 0.42;
10017
+ const eyeY = centerY + headRadius * 0.04;
10018
+ const eyeRadius = headRadius * 0.22;
10019
+ drawEye(context, centerX - eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, 0);
10020
+ drawEye(context, centerX + eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, Math.PI / 5);
10021
+ context.beginPath();
10022
+ context.arc(centerX - headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
10023
+ context.arc(centerX + headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
10024
+ context.fillStyle = `${palette.accent}44`;
10025
+ context.fill();
10026
+ context.beginPath();
10027
+ context.moveTo(centerX - headRadius * 0.18, centerY + headRadius * 0.24);
10028
+ context.quadraticCurveTo(centerX, centerY + headRadius * 0.42, centerX + headRadius * 0.18, centerY + headRadius * 0.24);
10029
+ context.strokeStyle = palette.shadow;
10030
+ context.lineWidth = size * 0.016;
10031
+ context.lineCap = 'round';
10032
+ context.stroke();
10033
+ },
10034
+ };
10035
+ /**
10036
+ * Draws one expressive octopus eye.
10037
+ *
10038
+ * @param context Canvas 2D context.
10039
+ * @param centerX Eye center X coordinate.
10040
+ * @param centerY Eye center Y coordinate.
10041
+ * @param radius Eye radius.
10042
+ * @param palette Derived avatar palette.
10043
+ * @param timeMs Current animation time in milliseconds.
10044
+ * @param interaction Smoothed avatar interaction state.
10045
+ * @param phase Seed-based phase offset.
10046
+ *
10047
+ * @private helper of `octopusAvatarVisual`
10048
+ */
10049
+ function drawEye(context, centerX, centerY, radius, palette, timeMs, interaction, phase) {
10050
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
10051
+ radiusX: radius,
10052
+ radiusY: radius,
10053
+ timeMs,
10054
+ phase,
10055
+ interaction,
10056
+ autonomousDriftRatioX: 0.05,
10057
+ autonomousDriftRatioY: 0.03,
10058
+ });
10059
+ context.beginPath();
10060
+ context.arc(centerX, centerY, radius, 0, Math.PI * 2);
10061
+ context.fillStyle = '#ffffff';
10062
+ context.fill();
10063
+ context.beginPath();
10064
+ context.arc(centerX + pupilOffsetX, centerY + pupilOffsetY, radius * 0.45, 0, Math.PI * 2);
10065
+ context.fillStyle = palette.ink;
10066
+ context.fill();
10067
+ context.beginPath();
10068
+ context.arc(centerX + pupilOffsetX - radius * 0.12, centerY + pupilOffsetY - radius * 0.12, radius * 0.15, 0, Math.PI * 2);
10069
+ context.fillStyle = '#ffffff';
10070
+ context.fill();
10071
+ context.beginPath();
10072
+ context.arc(centerX, centerY, radius, 0, Math.PI * 2);
10073
+ context.strokeStyle = palette.shadow;
10074
+ context.lineWidth = radius * 0.18;
10075
+ context.stroke();
10076
+ }
10077
+
10078
+ /* eslint-disable no-magic-numbers */
10079
+ /**
10080
+ * Octopus2 avatar visual.
10081
+ *
10082
+ * @private built-in avatar visual
10083
+ */
10084
+ const octopus2AvatarVisual = {
10085
+ id: 'octopus2',
10086
+ title: 'Octopus2',
10087
+ description: 'Organic alien octopus rendered as one continuously morphing blob with responsive luminous eyes.',
10088
+ isAnimated: true,
10089
+ supportsPointerTracking: true,
10090
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
10091
+ const staticRandom = createRandom('octopus2-static');
10092
+ const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.042;
10093
+ const centerY = size * (0.48 + staticRandom() * 0.03) + interaction.bodyOffsetY * size * 0.028;
10094
+ const bodyRadius = size * (0.25 + staticRandom() * 0.035);
10095
+ const horizontalStretch = 1.04 + staticRandom() * 0.16;
10096
+ const verticalStretch = 0.94 + staticRandom() * 0.12;
10097
+ const mantleLift = size * (0.075 + staticRandom() * 0.025);
10098
+ const lowerDrop = size * (0.05 + staticRandom() * 0.02);
10099
+ const tentacleDepth = size * (0.08 + staticRandom() * 0.03);
10100
+ const wobbleAmplitude = size * (0.014 + staticRandom() * 0.008);
10101
+ const lobeCount = 6 + Math.floor(staticRandom() * 3);
10102
+ const shapePhase = staticRandom() * Math.PI * 2;
10103
+ const bodyPoints = createOrganicOctopusBodyPoints({
10104
+ centerX,
10105
+ centerY,
10106
+ bodyRadius,
10107
+ horizontalStretch,
10108
+ verticalStretch,
10109
+ mantleLift,
10110
+ lowerDrop,
10111
+ tentacleDepth,
10112
+ wobbleAmplitude,
10113
+ lobeCount,
10114
+ shapePhase,
10115
+ timeMs,
10116
+ });
10117
+ drawAvatarFrame(context, size, palette);
10118
+ const hazeGradient = context.createRadialGradient(centerX, size * 0.22, size * 0.05, centerX, centerY, size * 0.6);
10119
+ hazeGradient.addColorStop(0, `${palette.highlight}4d`);
10120
+ hazeGradient.addColorStop(0.45, `${palette.accent}24`);
10121
+ hazeGradient.addColorStop(1, `${palette.highlight}00`);
10122
+ context.fillStyle = hazeGradient;
10123
+ context.fillRect(0, 0, size, size);
10124
+ const rimGlowGradient = context.createRadialGradient(centerX, centerY + size * 0.08, size * 0.14, centerX, centerY, size * 0.5);
10125
+ rimGlowGradient.addColorStop(0, `${palette.secondary}26`);
10126
+ rimGlowGradient.addColorStop(1, `${palette.secondary}00`);
10127
+ context.fillStyle = rimGlowGradient;
10128
+ context.fillRect(0, 0, size, size);
10129
+ context.save();
10130
+ traceSmoothClosedPath(context, bodyPoints);
10131
+ const bodyGradient = context.createRadialGradient(centerX - size * 0.09, centerY - size * 0.18, size * 0.06, centerX, centerY + size * 0.14, size * 0.5);
10132
+ bodyGradient.addColorStop(0, palette.highlight);
10133
+ bodyGradient.addColorStop(0.25, palette.secondary);
10134
+ bodyGradient.addColorStop(0.68, palette.primary);
10135
+ bodyGradient.addColorStop(1, palette.shadow);
10136
+ context.fillStyle = bodyGradient;
10137
+ context.shadowColor = `${palette.shadow}aa`;
10138
+ context.shadowBlur = size * 0.08;
10139
+ context.shadowOffsetY = size * 0.018;
10140
+ context.fill();
10141
+ context.restore();
10142
+ context.save();
10143
+ traceSmoothClosedPath(context, bodyPoints);
10144
+ context.clip();
10145
+ const interiorGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.22, centerX, centerY + size * 0.36);
10146
+ interiorGlowGradient.addColorStop(0, `${palette.highlight}59`);
10147
+ interiorGlowGradient.addColorStop(0.45, `${palette.accent}1a`);
10148
+ interiorGlowGradient.addColorStop(1, `${palette.shadow}00`);
10149
+ context.fillStyle = interiorGlowGradient;
10150
+ context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.76);
10151
+ drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase);
10152
+ drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs);
10153
+ context.restore();
10154
+ context.save();
10155
+ traceSmoothClosedPath(context, bodyPoints);
10156
+ context.strokeStyle = `${palette.highlight}59`;
10157
+ context.lineWidth = size * 0.014;
10158
+ context.stroke();
10159
+ context.restore();
10160
+ const eyeOffsetX = size * 0.13;
10161
+ const eyeCenterY = centerY - size * 0.02;
10162
+ const eyeRadiusX = size * 0.072;
10163
+ const eyeRadiusY = size * 0.086;
10164
+ drawAlienEye(context, centerX - eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase, interaction);
10165
+ drawAlienEye(context, centerX + eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase + Math.PI / 5, interaction);
10166
+ context.beginPath();
10167
+ context.moveTo(centerX - size * 0.08, centerY + size * 0.12);
10168
+ context.quadraticCurveTo(centerX, centerY + size * (0.175 + Math.sin(timeMs / 520 + shapePhase) * 0.012) + interaction.gazeY * size * 0.01, centerX + size * 0.08, centerY + size * 0.12);
10169
+ context.strokeStyle = `${palette.ink}b3`;
10170
+ context.lineWidth = size * 0.013;
10171
+ context.lineCap = 'round';
10172
+ context.stroke();
10173
+ context.beginPath();
10174
+ context.ellipse(centerX, centerY - size * 0.13, size * 0.16, size * 0.065, 0, Math.PI, Math.PI * 2);
10175
+ context.fillStyle = `${palette.highlight}33`;
10176
+ context.fill();
10177
+ },
10178
+ };
10179
+ /**
10180
+ * Draws translucent inner filaments clipped inside the main body mesh.
10181
+ *
10182
+ * @param context Canvas 2D context.
10183
+ * @param centerX Body center X coordinate.
10184
+ * @param centerY Body center Y coordinate.
10185
+ * @param size Canvas size in CSS pixels.
10186
+ * @param palette Derived avatar palette.
10187
+ * @param timeMs Current animation time in milliseconds.
10188
+ * @param shapePhase Seed-based phase offset.
10189
+ *
10190
+ * @private helper of `octopus2AvatarVisual`
10191
+ */
10192
+ function drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase) {
10193
+ for (let filamentIndex = 0; filamentIndex < 5; filamentIndex++) {
10194
+ const horizontalOffset = (filamentIndex - 2) * size * 0.075;
10195
+ const sway = Math.sin(timeMs / 720 + filamentIndex * 0.8 + shapePhase) * size * 0.028;
10196
+ context.beginPath();
10197
+ context.moveTo(centerX + horizontalOffset * 0.35, centerY - size * 0.11);
10198
+ context.bezierCurveTo(centerX + horizontalOffset - sway * 0.35, centerY - size * 0.01, centerX + horizontalOffset + sway, centerY + size * 0.13, centerX + horizontalOffset * 0.85 + sway * 0.55, centerY + size * 0.3);
10199
+ context.strokeStyle = filamentIndex % 2 === 0 ? `${palette.highlight}29` : `${palette.accent}24`;
10200
+ context.lineWidth = size * (0.01 + filamentIndex * 0.0008);
10201
+ context.lineCap = 'round';
10202
+ context.stroke();
10203
+ }
10204
+ }
10205
+ /**
10206
+ * Draws soft sucker-like highlights in the lower body area.
10207
+ *
10208
+ * @param context Canvas 2D context.
10209
+ * @param centerX Body center X coordinate.
10210
+ * @param centerY Body center Y coordinate.
10211
+ * @param size Canvas size in CSS pixels.
10212
+ * @param palette Derived avatar palette.
10213
+ * @param createRandom Seeded random factory scoped to the avatar.
10214
+ * @param timeMs Current animation time in milliseconds.
10215
+ *
10216
+ * @private helper of `octopus2AvatarVisual`
10217
+ */
10218
+ function drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs) {
10219
+ const suckerRandom = createRandom('octopus2-suckers');
10220
+ for (let suckerIndex = 0; suckerIndex < 12; suckerIndex++) {
10221
+ const x = centerX + (suckerRandom() - 0.5) * size * 0.36;
10222
+ const y = centerY + size * (0.11 + suckerRandom() * 0.22);
10223
+ const radiusX = size * (0.015 + suckerRandom() * 0.012);
10224
+ const radiusY = radiusX * (0.72 + suckerRandom() * 0.34);
10225
+ const rotation = suckerRandom() * Math.PI + Math.sin(timeMs / 1100 + suckerIndex) * 0.08;
10226
+ context.beginPath();
10227
+ context.ellipse(x, y, radiusX, radiusY, rotation, 0, Math.PI * 2);
10228
+ context.fillStyle = `${palette.highlight}24`;
10229
+ context.fill();
10230
+ context.strokeStyle = `${palette.highlight}40`;
10231
+ context.lineWidth = Math.max(1, size * 0.005);
10232
+ context.stroke();
10233
+ }
10234
+ }
10235
+ /**
10236
+ * Draws one luminous alien eye on top of the organic octopus mesh.
10237
+ *
10238
+ * @param context Canvas 2D context.
10239
+ * @param centerX Eye center X coordinate.
10240
+ * @param centerY Eye center Y coordinate.
10241
+ * @param radiusX Eye horizontal radius.
10242
+ * @param radiusY Eye vertical radius.
10243
+ * @param palette Derived avatar palette.
10244
+ * @param timeMs Current animation time in milliseconds.
10245
+ * @param phase Seed-based animation phase.
10246
+ * @param interaction Smoothed avatar interaction state.
10247
+ *
10248
+ * @private helper of `octopus2AvatarVisual`
10249
+ */
10250
+ function drawAlienEye(context, centerX, centerY, radiusX, radiusY, palette, timeMs, phase, interaction) {
10251
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
10252
+ radiusX,
10253
+ radiusY,
10254
+ timeMs,
10255
+ phase,
10256
+ interaction,
10257
+ autonomousDriftRatioY: 0.1,
10258
+ });
10259
+ context.save();
10260
+ context.beginPath();
10261
+ context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
10262
+ context.fillStyle = '#f8fbff';
10263
+ context.fill();
10264
+ context.clip();
10265
+ const irisGradient = context.createRadialGradient(centerX - radiusX * 0.18, centerY - radiusY * 0.22, radiusX * 0.05, centerX, centerY, radiusX * 0.9);
10266
+ irisGradient.addColorStop(0, palette.highlight);
10267
+ irisGradient.addColorStop(0.55, palette.secondary);
10268
+ irisGradient.addColorStop(1, palette.shadow);
10269
+ context.beginPath();
10270
+ context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.68, radiusY * 0.72, 0, 0, Math.PI * 2);
10271
+ context.fillStyle = irisGradient;
10272
+ context.fill();
10273
+ context.beginPath();
10274
+ context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.16, radiusY * 0.48, 0, 0, Math.PI * 2);
10275
+ context.fillStyle = palette.ink;
10276
+ context.fill();
10277
+ context.beginPath();
10278
+ context.ellipse(centerX + pupilOffsetX - radiusX * 0.18, centerY + pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
10279
+ context.fillStyle = '#ffffff';
10280
+ context.fill();
10281
+ context.restore();
10282
+ context.beginPath();
10283
+ context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
10284
+ context.strokeStyle = `${palette.shadow}cc`;
10285
+ context.lineWidth = radiusX * 0.2;
10286
+ context.stroke();
10287
+ }
10288
+
10289
+ /* eslint-disable no-magic-numbers */
10290
+ /**
10291
+ * Builds one deterministic morphology profile for `Octopus3`.
10292
+ *
10293
+ * @param createRandom Seeded random factory scoped to the current avatar.
10294
+ * @returns Stable morphology profile.
10295
+ *
10296
+ * @private helper of `octopus3AvatarVisual`
10297
+ */
10298
+ function createOctopus3MorphologyProfile(createRandom) {
10299
+ const bodyRandom = createRandom('octopus3-body-profile');
10300
+ const faceRandom = createRandom('octopus3-face-profile');
10301
+ const detailRandom = createRandom('octopus3-detail-profile');
10302
+ const bodyFamilyRoll = bodyRandom();
10303
+ let bodyFamily;
10304
+ let body;
10305
+ let tentacles;
10306
+ if (bodyFamilyRoll < 0.34) {
10307
+ bodyFamily = 'lantern';
10308
+ body = {
10309
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.018, 0.018),
10310
+ centerYRatio: resolveSeededRange(bodyRandom, 0.39, 0.435),
10311
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.19, 0.23),
10312
+ horizontalStretch: resolveSeededRange(bodyRandom, 0.94, 1.08),
10313
+ verticalStretch: resolveSeededRange(bodyRandom, 1.02, 1.18),
10314
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.115, 0.148),
10315
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.042, 0.066),
10316
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.018, 0.03),
10317
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.009, 0.017),
10318
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 4, 6),
10319
+ pointCount: resolveSeededIntegerRange(bodyRandom, 38, 42),
10320
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.18, 0.23),
10321
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.075),
10322
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.14, 0.18),
10323
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.045, 0.062),
10324
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.165, -0.135),
10325
+ };
10326
+ tentacles = {
10327
+ count: resolveSeededIntegerRange(bodyRandom, 7, 10),
10328
+ flowLengthScale: resolveSeededRange(bodyRandom, 1.08, 1.34),
10329
+ lateralReachScale: resolveSeededRange(bodyRandom, 0.72, 0.94),
10330
+ tipReachScale: resolveSeededRange(bodyRandom, 0.82, 1.06),
10331
+ baseWidthScale: resolveSeededRange(bodyRandom, 0.82, 0.98),
10332
+ tipWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
10333
+ rootSpreadScale: resolveSeededRange(bodyRandom, 0.76, 0.94),
10334
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.82, 1),
10335
+ swayScale: resolveSeededRange(bodyRandom, 0.82, 1.02),
10336
+ };
10337
+ }
10338
+ else if (bodyFamilyRoll < 0.68) {
10339
+ bodyFamily = 'drifter';
10340
+ body = {
10341
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.025, 0.025),
10342
+ centerYRatio: resolveSeededRange(bodyRandom, 0.425, 0.46),
10343
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.175, 0.215),
10344
+ horizontalStretch: resolveSeededRange(bodyRandom, 1.22, 1.42),
10345
+ verticalStretch: resolveSeededRange(bodyRandom, 0.82, 0.92),
10346
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.092, 0.115),
10347
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.02, 0.036),
10348
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
10349
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.013, 0.022),
10350
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 7, 9),
10351
+ pointCount: resolveSeededIntegerRange(bodyRandom, 40, 46),
10352
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.24, 0.28),
10353
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.06, 0.082),
10354
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.17, 0.22),
10355
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.038, 0.055),
10356
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.14, -0.11),
10357
+ };
10358
+ tentacles = {
10359
+ count: resolveSeededIntegerRange(bodyRandom, 10, 13),
10360
+ flowLengthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
10361
+ lateralReachScale: resolveSeededRange(bodyRandom, 1.18, 1.42),
10362
+ tipReachScale: resolveSeededRange(bodyRandom, 1.12, 1.42),
10363
+ baseWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.06),
10364
+ tipWidthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
10365
+ rootSpreadScale: resolveSeededRange(bodyRandom, 1.12, 1.32),
10366
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.92, 1.14),
10367
+ swayScale: resolveSeededRange(bodyRandom, 1.04, 1.22),
10368
+ };
10369
+ }
10370
+ else {
10371
+ bodyFamily = 'rounded';
10372
+ body = {
10373
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.02, 0.02),
10374
+ centerYRatio: resolveSeededRange(bodyRandom, 0.398, 0.442),
10375
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.208, 0.248),
10376
+ horizontalStretch: resolveSeededRange(bodyRandom, 1.06, 1.22),
10377
+ verticalStretch: resolveSeededRange(bodyRandom, 0.9, 1.01),
10378
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.1, 0.128),
10379
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
10380
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.038, 0.06),
10381
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.014, 0.024),
10382
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 5, 8),
10383
+ pointCount: resolveSeededIntegerRange(bodyRandom, 39, 44),
10384
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.2, 0.25),
10385
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.08),
10386
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.16, 0.2),
10387
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.05, 0.07),
10388
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.155, -0.122),
10389
+ };
10390
+ tentacles = {
10391
+ count: resolveSeededIntegerRange(bodyRandom, 8, 12),
10392
+ flowLengthScale: resolveSeededRange(bodyRandom, 0.94, 1.16),
10393
+ lateralReachScale: resolveSeededRange(bodyRandom, 0.9, 1.14),
10394
+ tipReachScale: resolveSeededRange(bodyRandom, 0.96, 1.22),
10395
+ baseWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.2),
10396
+ tipWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.22),
10397
+ rootSpreadScale: resolveSeededRange(bodyRandom, 0.94, 1.08),
10398
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
10399
+ swayScale: resolveSeededRange(bodyRandom, 0.9, 1.1),
10400
+ };
10401
+ }
10402
+ const faceFamilyRoll = faceRandom();
10403
+ let faceFamily;
10404
+ let face;
10405
+ if (faceFamilyRoll < 0.34) {
10406
+ faceFamily = 'watchful';
10407
+ face = {
10408
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.118, 0.152),
10409
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.026, -0.002),
10410
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.05, 0.062),
10411
+ eyeHeightRatio: resolveSeededRange(faceRandom, 1.18, 1.38),
10412
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.16, 0.28),
10413
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.02, 0.06),
10414
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
10415
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.086, 0.104),
10416
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.126, 0.15),
10417
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.006, 0.006),
10418
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.002, 0.002),
10419
+ eyeStyle: {
10420
+ irisScale: resolveSeededRange(faceRandom, 1, 1.1),
10421
+ pupilWidthScale: resolveSeededRange(faceRandom, 0.86, 1.02),
10422
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.94, 1.08),
10423
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.96, 1.12),
10424
+ upperLidInsetRatio: resolveSeededRange(faceRandom, 0.08, 0.14),
10425
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.12, 0.22),
10426
+ },
10427
+ };
10428
+ }
10429
+ else if (faceFamilyRoll < 0.68) {
10430
+ faceFamily = 'sleepy';
10431
+ face = {
10432
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.092, 0.124),
10433
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.002, 0.024),
10434
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
10435
+ eyeHeightRatio: resolveSeededRange(faceRandom, 0.96, 1.14),
10436
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.1, 0.22),
10437
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.01, 0.05),
10438
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.066, 0.086),
10439
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.094, 0.118),
10440
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.118, 0.145),
10441
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
10442
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
10443
+ eyeStyle: {
10444
+ irisScale: resolveSeededRange(faceRandom, 0.9, 1),
10445
+ pupilWidthScale: resolveSeededRange(faceRandom, 1, 1.18),
10446
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.78, 0.92),
10447
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.7, 0.88),
10448
+ upperLidInsetRatio: resolveSeededRange(faceRandom, -0.02, 0.06),
10449
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.22, 0.34),
10450
+ },
10451
+ };
10452
+ }
10453
+ else {
10454
+ faceFamily = 'mischief';
10455
+ face = {
10456
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.086, 0.114),
10457
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.01),
10458
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.046, 0.06),
10459
+ eyeHeightRatio: resolveSeededRange(faceRandom, 1.08, 1.28),
10460
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.28, 0.44),
10461
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.12, 0.22),
10462
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.052, 0.074),
10463
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.082, 0.1),
10464
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.116, 0.15),
10465
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.018),
10466
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.01, 0.01),
10467
+ eyeStyle: {
10468
+ irisScale: resolveSeededRange(faceRandom, 1.04, 1.12),
10469
+ pupilWidthScale: resolveSeededRange(faceRandom, 0.72, 0.9),
10470
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.96, 1.14),
10471
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.88, 1.02),
10472
+ upperLidInsetRatio: resolveSeededRange(faceRandom, 0.04, 0.12),
10473
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.08, 0.18),
10474
+ },
10475
+ };
10476
+ }
10477
+ return {
10478
+ bodyFamily,
10479
+ faceFamily,
10480
+ body,
10481
+ tentacles,
10482
+ face,
10483
+ details: {
10484
+ mantleCurrentCount: resolveSeededIntegerRange(detailRandom, 4, 8),
10485
+ mantleNodeCount: resolveSeededIntegerRange(detailRandom, 3, 7),
10486
+ },
10487
+ };
10488
+ }
10489
+ /**
10490
+ * Resolves one seeded floating-point number inside the provided range.
10491
+ *
10492
+ * @param random Seeded random generator.
10493
+ * @param minimumValue Inclusive lower bound.
10494
+ * @param maximumValue Inclusive upper bound.
10495
+ * @returns Seeded number within the range.
10496
+ *
10497
+ * @private helper of `octopus3AvatarVisual`
10498
+ */
10499
+ function resolveSeededRange(random, minimumValue, maximumValue) {
10500
+ return minimumValue + random() * (maximumValue - minimumValue);
10501
+ }
10502
+ /**
10503
+ * Resolves one seeded integer inside the provided inclusive range.
10504
+ *
10505
+ * @param random Seeded random generator.
10506
+ * @param minimumValue Inclusive lower bound.
10507
+ * @param maximumValue Inclusive upper bound.
10508
+ * @returns Seeded integer within the range.
10509
+ *
10510
+ * @private helper of `octopus3AvatarVisual`
10511
+ */
10512
+ function resolveSeededIntegerRange(random, minimumValue, maximumValue) {
10513
+ return minimumValue + Math.floor(random() * (maximumValue - minimumValue + 1));
10514
+ }
10515
+ /**
10516
+ * Converts an opacity ratio into a two-digit hexadecimal alpha suffix.
10517
+ *
10518
+ * @param opacity Opacity ratio in the range `[0, 1]`.
10519
+ * @returns Two-digit hexadecimal alpha string.
10520
+ *
10521
+ * @private helper of `octopus3AvatarVisual`
10522
+ */
10523
+ function formatAlphaHex(opacity) {
10524
+ return Math.round(Math.min(1, Math.max(0, opacity)) * 255)
10525
+ .toString(16)
10526
+ .padStart(2, '0');
10527
+ }
10528
+ /**
10529
+ * Octopus3 avatar visual.
10530
+ *
10531
+ * @private built-in avatar visual
10532
+ */
10533
+ const octopus3AvatarVisual = {
10534
+ id: 'octopus3',
10535
+ title: 'Octopus3',
10536
+ description: 'Gelatinous alien octopus with a morphing mantle, responsive eyes, and visible ribbon tentacles.',
10537
+ isAnimated: true,
10538
+ supportsPointerTracking: true,
10539
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
10540
+ const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
10541
+ const animationRandom = createRandom('octopus3-animation-profile');
10542
+ const eyeRandom = createRandom('octopus3-eye-profile');
10543
+ const centerX = size * (0.5 + morphologyProfile.body.centerXJitterRatio) + interaction.bodyOffsetX * size * 0.05;
10544
+ const centerY = size * morphologyProfile.body.centerYRatio + interaction.bodyOffsetY * size * 0.035;
10545
+ const bodyRadius = size * morphologyProfile.body.bodyRadiusRatio;
10546
+ const horizontalStretch = morphologyProfile.body.horizontalStretch;
10547
+ const verticalStretch = morphologyProfile.body.verticalStretch;
10548
+ const mantleLift = size * morphologyProfile.body.mantleLiftRatio;
10549
+ const lowerDrop = size * morphologyProfile.body.lowerDropRatio;
10550
+ const tentacleDepth = size * morphologyProfile.body.tentacleDepthRatio;
10551
+ const wobbleAmplitude = size * morphologyProfile.body.wobbleAmplitudeRatio;
10552
+ const lobeCount = morphologyProfile.body.lobeCount;
10553
+ const shapePhase = animationRandom() * Math.PI * 2;
10554
+ const eyeSpacing = size * morphologyProfile.face.eyeSpacingRatio;
10555
+ const eyeCenterY = centerY + size * morphologyProfile.face.eyeCenterYOffsetRatio;
10556
+ const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio;
10557
+ const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio;
10558
+ const bodyPoints = createOrganicOctopusBodyPoints({
10559
+ centerX,
10560
+ centerY,
10561
+ bodyRadius,
10562
+ horizontalStretch,
10563
+ verticalStretch,
10564
+ mantleLift,
10565
+ lowerDrop,
10566
+ tentacleDepth,
10567
+ wobbleAmplitude,
10568
+ lobeCount,
10569
+ shapePhase,
10570
+ timeMs,
10571
+ pointCount: morphologyProfile.body.pointCount,
10572
+ });
10573
+ const tentacleShapes = createOrganicOctopusTentacleShapes({
10574
+ size,
10575
+ centerX,
10576
+ centerY,
10577
+ bodyRadius,
10578
+ horizontalStretch,
10579
+ tentacleCount: morphologyProfile.tentacles.count,
10580
+ shapePhase,
10581
+ createRandom,
10582
+ timeMs,
10583
+ saltPrefix: 'octopus3',
10584
+ bodyPoints,
10585
+ variation: {
10586
+ flowLengthScale: morphologyProfile.tentacles.flowLengthScale,
10587
+ lateralReachScale: morphologyProfile.tentacles.lateralReachScale,
10588
+ tipReachScale: morphologyProfile.tentacles.tipReachScale,
10589
+ baseWidthScale: morphologyProfile.tentacles.baseWidthScale,
10590
+ tipWidthScale: morphologyProfile.tentacles.tipWidthScale,
10591
+ rootSpreadScale: morphologyProfile.tentacles.rootSpreadScale,
10592
+ startYOffsetScale: morphologyProfile.tentacles.startYOffsetScale,
10593
+ swayScale: morphologyProfile.tentacles.swayScale,
10594
+ },
10595
+ });
10596
+ drawAvatarFrame(context, size, palette);
10597
+ drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile);
10598
+ context.beginPath();
10599
+ context.ellipse(centerX, centerY + size * 0.25, size * morphologyProfile.body.shadowWidthRatio, size * morphologyProfile.body.shadowHeightRatio, 0, 0, Math.PI * 2);
10600
+ context.fillStyle = `${palette.shadow}33`;
10601
+ context.fill();
10602
+ for (const tentacleShape of tentacleShapes) {
10603
+ drawTentacleRibbon(context, tentacleShape, palette);
10604
+ }
10605
+ context.save();
10606
+ traceSmoothClosedPath(context, bodyPoints);
10607
+ const bodyGradient = context.createRadialGradient(centerX - size * 0.1, centerY - size * 0.18, size * 0.04, centerX, centerY + size * 0.16, size * 0.54);
10608
+ bodyGradient.addColorStop(0, palette.highlight);
10609
+ bodyGradient.addColorStop(0.18, palette.secondary);
10610
+ bodyGradient.addColorStop(0.55, palette.primary);
10611
+ bodyGradient.addColorStop(1, palette.shadow);
10612
+ context.fillStyle = bodyGradient;
10613
+ context.shadowColor = `${palette.shadow}aa`;
10614
+ context.shadowBlur = size * 0.08;
10615
+ context.shadowOffsetY = size * 0.02;
10616
+ context.fill();
10617
+ context.restore();
10618
+ context.save();
10619
+ traceSmoothClosedPath(context, bodyPoints);
10620
+ context.clip();
10621
+ const innerGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.24, centerX, centerY + size * 0.26);
10622
+ innerGlowGradient.addColorStop(0, `${palette.highlight}66`);
10623
+ innerGlowGradient.addColorStop(0.4, `${palette.secondary}26`);
10624
+ innerGlowGradient.addColorStop(1, `${palette.shadow}00`);
10625
+ context.fillStyle = innerGlowGradient;
10626
+ context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.72);
10627
+ drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile);
10628
+ drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile);
10629
+ context.restore();
10630
+ context.save();
10631
+ traceSmoothClosedPath(context, bodyPoints);
10632
+ context.strokeStyle = `${palette.highlight}73`;
10633
+ context.lineWidth = size * 0.013;
10634
+ context.stroke();
10635
+ context.restore();
10636
+ context.beginPath();
10637
+ context.ellipse(centerX, centerY + size * morphologyProfile.body.crownHighlightYOffsetRatio, size * morphologyProfile.body.crownHighlightWidthRatio, size * morphologyProfile.body.crownHighlightHeightRatio, 0, Math.PI, Math.PI * 2);
10638
+ context.fillStyle = `${palette.highlight}3d`;
10639
+ context.fill();
10640
+ drawSeededEye(context, centerX - eyeSpacing, eyeCenterY, eyeRadiusX, eyeRadiusY, -morphologyProfile.face.eyeTiltBias + (eyeRandom() - 0.5) * morphologyProfile.face.eyeRotationRange, palette, timeMs, shapePhase, interaction, morphologyProfile.face.eyeStyle);
10641
+ drawSeededEye(context, centerX + eyeSpacing, eyeCenterY, eyeRadiusX, eyeRadiusY, morphologyProfile.face.eyeTiltBias + (eyeRandom() - 0.5) * morphologyProfile.face.eyeRotationRange, palette, timeMs, shapePhase + Math.PI / 4, interaction, morphologyProfile.face.eyeStyle);
10642
+ const mouthHalfWidth = size * morphologyProfile.face.mouthWidthRatio;
10643
+ const mouthY = centerY + size * morphologyProfile.face.mouthYOffsetRatio;
10644
+ const mouthCornerTilt = size * morphologyProfile.face.mouthCornerTiltRatio;
10645
+ context.beginPath();
10646
+ context.moveTo(centerX - mouthHalfWidth, mouthY - mouthCornerTilt);
10647
+ context.quadraticCurveTo(centerX + size * morphologyProfile.face.mouthCenterOffsetRatio, centerY +
10648
+ size * (morphologyProfile.face.mouthCurveDepthRatio + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
10649
+ interaction.gazeY * size * 0.012, centerX + mouthHalfWidth, mouthY + mouthCornerTilt);
10650
+ context.strokeStyle = `${palette.ink}b3`;
10651
+ context.lineWidth = size * 0.012;
10652
+ context.lineCap = 'round';
10653
+ context.stroke();
10654
+ },
10655
+ };
10656
+ /**
10657
+ * Draws the deep-sea glow around the Octopus3 silhouette.
10658
+ *
10659
+ * @param context Canvas 2D context.
10660
+ * @param size Canvas size in CSS pixels.
10661
+ * @param palette Derived avatar palette.
10662
+ * @param centerX Body center X coordinate.
10663
+ * @param centerY Body center Y coordinate.
10664
+ * @param timeMs Current animation time in milliseconds.
10665
+ * @param shapePhase Seed-based phase offset.
10666
+ * @param morphologyProfile Seeded morphology profile.
10667
+ *
10668
+ * @private helper of `octopus3AvatarVisual`
10669
+ */
10670
+ function drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile) {
10671
+ const haloGradient = context.createRadialGradient(centerX, centerY - size * (0.07 + (morphologyProfile.body.verticalStretch - 0.9) * 0.05), size * 0.06, centerX, centerY, size * (0.56 + morphologyProfile.body.bodyRadiusRatio * 0.45));
10672
+ haloGradient.addColorStop(0, `${palette.highlight}5c`);
10673
+ haloGradient.addColorStop(0.35, `${palette.accent}26`);
10674
+ haloGradient.addColorStop(1, `${palette.highlight}00`);
10675
+ context.fillStyle = haloGradient;
10676
+ context.fillRect(0, 0, size, size);
10677
+ const lowerGlowGradient = context.createRadialGradient(centerX + Math.sin(timeMs / 1600 + shapePhase) * size * 0.04, centerY + size * (0.18 + morphologyProfile.tentacles.flowLengthScale * 0.025), size * 0.04, centerX, centerY + size * (0.18 + morphologyProfile.tentacles.flowLengthScale * 0.025), size * (0.42 + morphologyProfile.tentacles.lateralReachScale * 0.06));
10678
+ lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
10679
+ lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
10680
+ context.fillStyle = lowerGlowGradient;
10681
+ context.fillRect(0, 0, size, size);
10682
+ }
10683
+ /**
10684
+ * Draws one ribbon tentacle with a filled organic profile and visible sucker highlights.
10685
+ *
10686
+ * @param context Canvas 2D context.
10687
+ * @param tentacleShape Deterministic tentacle descriptor.
10688
+ * @param palette Derived avatar palette.
10689
+ *
10690
+ * @private helper of `octopus3AvatarVisual`
10691
+ */
10692
+ function drawTentacleRibbon(context, tentacleShape, palette) {
10693
+ const ribbonPoints = sampleOrganicTentacleRibbonPoints(tentacleShape);
10694
+ const gradient = context.createLinearGradient(tentacleShape.startPoint.x, tentacleShape.startPoint.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
10695
+ gradient.addColorStop(0, tentacleShape.colorBias < 0.35 ? palette.secondary : palette.primary);
10696
+ gradient.addColorStop(0.58, palette.primary);
10697
+ gradient.addColorStop(1, tentacleShape.colorBias > 0.65 ? palette.highlight : palette.accent);
10698
+ context.save();
10699
+ traceTentacleRibbonPath(context, ribbonPoints);
10700
+ context.fillStyle = gradient;
10701
+ context.shadowColor = `${palette.shadow}80`;
10702
+ context.shadowBlur = tentacleShape.baseWidth * 1.2;
10703
+ context.shadowOffsetY = tentacleShape.baseWidth * 0.2;
10704
+ context.fill();
10705
+ context.restore();
10706
+ context.save();
10707
+ traceTentacleRibbonPath(context, ribbonPoints);
10708
+ context.strokeStyle = tentacleShape.highlightBias > 0.5 ? `${palette.highlight}52` : `${palette.highlight}38`;
10709
+ context.lineWidth = Math.max(1, tentacleShape.baseWidth * 0.12);
10710
+ context.stroke();
10711
+ context.restore();
10712
+ context.beginPath();
10713
+ context.moveTo(tentacleShape.startPoint.x, tentacleShape.startPoint.y);
10714
+ context.bezierCurveTo(tentacleShape.controlPointOne.x, tentacleShape.controlPointOne.y, tentacleShape.controlPointTwo.x, tentacleShape.controlPointTwo.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
10715
+ context.strokeStyle = `${palette.highlight}2e`;
10716
+ context.lineWidth = Math.max(1, tentacleShape.tipWidth * 0.9);
10717
+ context.lineCap = 'round';
10718
+ context.stroke();
10719
+ drawTentacleSuckers(context, tentacleShape, palette);
10720
+ }
10721
+ /**
10722
+ * Traces a closed ribbon path from sampled tentacle points.
10723
+ *
10724
+ * @param context Canvas 2D context.
10725
+ * @param ribbonPoints Sampled ribbon points.
10726
+ *
10727
+ * @private helper of `octopus3AvatarVisual`
10728
+ */
10729
+ function traceTentacleRibbonPath(context, ribbonPoints) {
10730
+ const firstRibbonPoint = ribbonPoints[0];
10731
+ context.beginPath();
10732
+ context.moveTo(firstRibbonPoint.x + firstRibbonPoint.normalX * firstRibbonPoint.width, firstRibbonPoint.y + firstRibbonPoint.normalY * firstRibbonPoint.width);
10733
+ for (const ribbonPoint of ribbonPoints.slice(1)) {
10734
+ context.lineTo(ribbonPoint.x + ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y + ribbonPoint.normalY * ribbonPoint.width);
10735
+ }
10736
+ for (const ribbonPoint of [...ribbonPoints].reverse()) {
10737
+ context.lineTo(ribbonPoint.x - ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y - ribbonPoint.normalY * ribbonPoint.width);
10738
+ }
10739
+ context.closePath();
10740
+ }
10741
+ /**
10742
+ * Draws a row of soft sucker highlights along one side of the ribbon tentacle.
10743
+ *
10744
+ * @param context Canvas 2D context.
10745
+ * @param tentacleShape Deterministic tentacle descriptor.
10746
+ * @param palette Derived avatar palette.
10747
+ *
10748
+ * @private helper of `octopus3AvatarVisual`
10749
+ */
10750
+ function drawTentacleSuckers(context, tentacleShape, palette) {
10751
+ const undersideDirection = tentacleShape.endPoint.x >= tentacleShape.startPoint.x ? -1 : 1;
10752
+ for (let suckerIndex = 0; suckerIndex < 4; suckerIndex++) {
10753
+ const progress = 0.22 + suckerIndex * 0.17;
10754
+ const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
10755
+ const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.03));
10756
+ const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.03));
10757
+ const tangentX = nextPoint.x - previousPoint.x;
10758
+ const tangentY = nextPoint.y - previousPoint.y;
10759
+ const tangentLength = Math.hypot(tangentX, tangentY) || 1;
10760
+ const normalX = (-tangentY / tangentLength) * undersideDirection;
10761
+ const normalY = (tangentX / tangentLength) * undersideDirection;
10762
+ const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
10763
+ const suckerX = point.x + normalX * width * 0.52;
10764
+ const suckerY = point.y + normalY * width * 0.52;
10765
+ const rotation = Math.atan2(normalY, normalX);
10766
+ context.beginPath();
10767
+ context.ellipse(suckerX, suckerY, width * 0.22, width * 0.11, rotation, 0, Math.PI * 2);
10768
+ context.fillStyle = `${palette.highlight}73`;
10769
+ context.fill();
10770
+ context.strokeStyle = `${palette.highlight}99`;
10771
+ context.lineWidth = Math.max(1, width * 0.08);
10772
+ context.stroke();
10773
+ }
10774
+ }
10775
+ /**
10776
+ * Draws slow inner currents inside the clipped Octopus3 mantle.
10777
+ *
10778
+ * @param context Canvas 2D context.
10779
+ * @param centerX Body center X coordinate.
10780
+ * @param centerY Body center Y coordinate.
10781
+ * @param size Canvas size in CSS pixels.
10782
+ * @param palette Derived avatar palette.
10783
+ * @param timeMs Current animation time in milliseconds.
10784
+ * @param shapePhase Seed-based phase offset.
10785
+ * @param morphologyProfile Seeded morphology profile.
10786
+ *
10787
+ * @private helper of `octopus3AvatarVisual`
10788
+ */
10789
+ function drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile) {
10790
+ const centeredCurrentIndex = (morphologyProfile.details.mantleCurrentCount - 1) / 2;
10791
+ for (let currentIndex = 0; currentIndex < morphologyProfile.details.mantleCurrentCount; currentIndex++) {
10792
+ const horizontalOffset = (currentIndex - centeredCurrentIndex) *
10793
+ size *
10794
+ (0.05 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.025);
10795
+ const sway = Math.sin(timeMs / 680 + currentIndex * 0.78 + shapePhase) * size * 0.024;
10796
+ context.beginPath();
10797
+ context.moveTo(centerX + horizontalOffset * 0.3, centerY - size * (0.11 + morphologyProfile.body.verticalStretch * 0.02));
10798
+ context.bezierCurveTo(centerX + horizontalOffset - sway * 0.25, centerY - size * 0.04, centerX + horizontalOffset + sway, centerY + size * 0.06, centerX + horizontalOffset * 0.7 + sway * 0.46, centerY + size * (0.16 + morphologyProfile.body.verticalStretch * 0.035));
10799
+ context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}30` : `${palette.accent}26`;
10800
+ context.lineWidth =
10801
+ size * (0.0075 + currentIndex * 0.00065 + morphologyProfile.tentacles.baseWidthScale * 0.0005);
10802
+ context.lineCap = 'round';
10803
+ context.stroke();
10804
+ }
10805
+ }
10806
+ /**
10807
+ * Draws seeded luminous nodes inside the Octopus3 mantle.
10808
+ *
10809
+ * @param context Canvas 2D context.
10810
+ * @param centerX Body center X coordinate.
10811
+ * @param centerY Body center Y coordinate.
10812
+ * @param size Canvas size in CSS pixels.
10813
+ * @param palette Derived avatar palette.
10814
+ * @param createRandom Seeded random factory scoped to the avatar.
10815
+ * @param morphologyProfile Seeded morphology profile.
10816
+ *
10817
+ * @private helper of `octopus3AvatarVisual`
10818
+ */
10819
+ function drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile) {
10820
+ for (let nodeIndex = 0; nodeIndex < morphologyProfile.details.mantleNodeCount; nodeIndex++) {
10821
+ const nodeRandom = createRandom(`octopus3-node-${nodeIndex}`);
10822
+ const nodeX = centerX + (nodeRandom() - 0.5) * size * (0.2 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.16);
10823
+ const nodeY = centerY -
10824
+ size * 0.03 +
10825
+ (nodeRandom() - 0.5) * size * (0.16 + (morphologyProfile.body.verticalStretch - 0.82) * 0.1);
10826
+ const nodeRadius = size * (0.016 + nodeRandom() * 0.016);
10827
+ context.beginPath();
10828
+ context.arc(nodeX, nodeY, nodeRadius, 0, Math.PI * 2);
10829
+ context.fillStyle = nodeIndex % 2 === 0 ? `${palette.highlight}40` : `${palette.accent}33`;
10830
+ context.fill();
10831
+ }
10832
+ }
10833
+ /**
10834
+ * Draws one expressive seeded eye with a slit pupil and slightly tilted eyelids.
10835
+ *
10836
+ * @param context Canvas 2D context.
10837
+ * @param centerX Eye center X coordinate.
10838
+ * @param centerY Eye center Y coordinate.
10839
+ * @param radiusX Eye horizontal radius.
10840
+ * @param radiusY Eye vertical radius.
10841
+ * @param rotation Eye rotation in radians.
10842
+ * @param palette Derived avatar palette.
10843
+ * @param timeMs Current animation time in milliseconds.
10844
+ * @param phase Seed-based animation phase.
10845
+ * @param interaction Smoothed avatar interaction state.
10846
+ * @param eyeStyle Seeded eye-style traits.
10847
+ *
10848
+ * @private helper of `octopus3AvatarVisual`
10849
+ */
10850
+ function drawSeededEye(context, centerX, centerY, radiusX, radiusY, rotation, palette, timeMs, phase, interaction, eyeStyle) {
10851
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
10852
+ radiusX,
10853
+ radiusY,
10854
+ timeMs,
10855
+ phase,
10856
+ interaction,
10857
+ });
10858
+ context.save();
10859
+ context.translate(centerX, centerY);
10860
+ context.rotate(rotation);
10861
+ context.beginPath();
10862
+ context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
10863
+ context.fillStyle = '#f8fbff';
10864
+ context.fill();
10865
+ context.clip();
10866
+ const irisGradient = context.createRadialGradient(-radiusX * 0.18, -radiusY * 0.24, radiusX * 0.05, 0, 0, radiusX * 0.92);
10867
+ irisGradient.addColorStop(0, palette.highlight);
10868
+ irisGradient.addColorStop(0.58, palette.secondary);
10869
+ irisGradient.addColorStop(1, palette.shadow);
10870
+ context.beginPath();
10871
+ context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.66 * eyeStyle.irisScale, radiusY * 0.74 * eyeStyle.irisScale, 0, 0, Math.PI * 2);
10872
+ context.fillStyle = irisGradient;
10873
+ context.fill();
10874
+ context.beginPath();
10875
+ context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.14 * eyeStyle.pupilWidthScale, radiusY * 0.5 * eyeStyle.pupilHeightScale, 0, 0, Math.PI * 2);
10876
+ context.fillStyle = palette.ink;
10877
+ context.fill();
10878
+ context.beginPath();
10879
+ context.ellipse(pupilOffsetX - radiusX * 0.22, pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
10880
+ context.fillStyle = '#ffffff';
10881
+ context.fill();
10882
+ context.restore();
10883
+ context.save();
10884
+ context.translate(centerX, centerY);
10885
+ context.rotate(rotation);
10886
+ context.beginPath();
10887
+ context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
10888
+ context.strokeStyle = `${palette.shadow}d9`;
10889
+ context.lineWidth = radiusX * 0.18;
10890
+ context.stroke();
10891
+ context.beginPath();
10892
+ context.moveTo(-radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
10893
+ context.quadraticCurveTo(0, -radiusY * (eyeStyle.upperLidArchRatio - interaction.gazeY * 0.16 + interaction.intensity * 0.08), radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
10894
+ context.strokeStyle = `${palette.shadow}73`;
10895
+ context.lineWidth = radiusX * 0.16;
10896
+ context.lineCap = 'round';
10897
+ context.stroke();
10898
+ if (eyeStyle.lowerLidOpacity > 0) {
10899
+ context.beginPath();
10900
+ context.moveTo(-radiusX * 0.74, radiusY * 0.2);
10901
+ context.quadraticCurveTo(0, radiusY * 0.38, radiusX * 0.74, radiusY * 0.2);
10902
+ context.strokeStyle = `${palette.highlight}${formatAlphaHex(eyeStyle.lowerLidOpacity)}`;
10903
+ context.lineWidth = radiusX * 0.08;
10904
+ context.lineCap = 'round';
10905
+ context.stroke();
10906
+ }
10907
+ context.restore();
10908
+ }
10909
+
10910
+ /* eslint-disable no-magic-numbers */
10911
+ /**
10912
+ * Family variants used by the orb renderer.
10913
+ *
10914
+ * @private helper of `orbAvatarVisual`
10915
+ */
10916
+ const ORB_FAMILIES = ['pearl', 'nebula', 'ember', 'glacier'];
10917
+ /**
10918
+ * Built-in Orb avatar visual.
10919
+ *
10920
+ * @private built-in avatar visual
10921
+ */
10922
+ const orbAvatarVisual = {
10923
+ id: 'orb',
10924
+ title: 'Orb',
10925
+ description: 'Glowing morphing circle-orb with seeded gradients, smooth deformations, and luminous layered depth.',
10926
+ isAnimated: true,
10927
+ render({ context, size, palette, createRandom, timeMs }) {
10928
+ const profile = createOrbMorphologyProfile(createRandom);
10929
+ const colorSet = resolveOrbColorSet(palette, profile.family);
10930
+ const centerX = size * 0.5 + profile.coreShiftX * size * 0.06 + Math.sin(timeMs / 2600) * size * 0.009;
10931
+ const centerY = size * 0.5 +
10932
+ profile.coreShiftY * size * 0.06 +
10933
+ Math.cos(timeMs / 3100 + profile.highlightAngle) * size * 0.01;
10934
+ const radius = size * profile.baseRadiusRatio;
10935
+ const silhouettePoints = createOrbSilhouettePoints({
10936
+ centerX,
10937
+ centerY,
10938
+ radius,
10939
+ profile,
10940
+ timeMs,
10941
+ });
10942
+ drawAvatarFrame(context, size, palette);
10943
+ drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs);
10944
+ drawOrbBody(context, silhouettePoints, centerX, centerY, radius, colorSet, profile, size);
10945
+ context.save();
10946
+ traceSmoothClosedPath(context, silhouettePoints);
10947
+ context.clip();
10948
+ drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
10949
+ drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs);
10950
+ drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
10951
+ drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
10952
+ context.restore();
10953
+ drawOrbRim(context, silhouettePoints, colorSet, size);
10954
+ },
10955
+ };
10956
+ /**
10957
+ * Builds the deterministic orb profile from the seeded avatar random factory.
10958
+ *
10959
+ * @param createRandom Seeded random factory.
10960
+ * @returns Stable orb morphology profile.
10961
+ *
10962
+ * @private helper of `orbAvatarVisual`
10963
+ */
10964
+ function createOrbMorphologyProfile(createRandom) {
10965
+ const family = pickRandomItem(ORB_FAMILIES, createRandom('orb-family'));
10966
+ const familyAdjustment = resolveOrbFamilyAdjustment(family);
10967
+ const layoutRandom = createRandom('orb-layout');
10968
+ const effectRandom = createRandom('orb-effects');
10969
+ return {
10970
+ family,
10971
+ baseRadiusRatio: clampNumber(0.255 + layoutRandom() * 0.055 + familyAdjustment.baseRadiusRatio, 0.22, 0.335),
10972
+ horizontalStretch: clampNumber(0.93 + layoutRandom() * 0.13 + familyAdjustment.horizontalStretch, 0.88, 1.16),
10973
+ verticalStretch: clampNumber(0.91 + layoutRandom() * 0.13 + familyAdjustment.verticalStretch, 0.88, 1.15),
10974
+ wobbleAmplitude: clampNumber(0.038 + effectRandom() * 0.042 + familyAdjustment.wobbleAmplitude, 0.022, 0.12),
10975
+ wobbleFrequencyOne: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 2, 7),
10976
+ wobbleFrequencyTwo: clampInteger(3 + Math.floor(layoutRandom() * 3) + familyAdjustment.wobbleFrequency, 3, 8),
10977
+ wobbleFrequencyThree: clampInteger(5 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 4, 9),
10978
+ ringCount: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.ringCount, 2, 5),
10979
+ sparkleCount: clampInteger(6 + Math.floor(effectRandom() * 7) + familyAdjustment.sparkleCount, 4, 16),
10980
+ haloCount: clampInteger(2 + Math.floor(layoutRandom() * 2) + familyAdjustment.haloCount, 1, 4),
10981
+ coreShiftX: (layoutRandom() - 0.5) * 0.08,
10982
+ coreShiftY: (effectRandom() - 0.5) * 0.08,
10983
+ highlightAngle: layoutRandom() * Math.PI * 2,
10984
+ bandRotation: effectRandom() * Math.PI * 2,
10985
+ pulseSpeed: 0.82 + effectRandom() * 0.72,
10986
+ haloBlurRatio: clampNumber(0.18 + layoutRandom() * 0.12 + familyAdjustment.haloBlurRatio, 0.16, 0.34),
10987
+ sheenStrength: clampNumber(0.46 + effectRandom() * 0.28 + familyAdjustment.sheenStrength, 0.38, 0.88),
10988
+ };
10989
+ }
10990
+ /**
10991
+ * Resolves the family-specific adjustments that keep the orb surface varied while still circular.
10992
+ *
10993
+ * @param family Selected orb family.
10994
+ * @returns Family-specific profile adjustments.
10995
+ *
10996
+ * @private helper of `orbAvatarVisual`
10997
+ */
10998
+ function resolveOrbFamilyAdjustment(family) {
10999
+ switch (family) {
11000
+ case 'nebula':
11001
+ return {
11002
+ baseRadiusRatio: 0.006,
11003
+ horizontalStretch: 0.05,
11004
+ verticalStretch: -0.01,
11005
+ wobbleAmplitude: 0.012,
11006
+ wobbleFrequency: 1,
11007
+ ringCount: 1,
11008
+ sparkleCount: 2,
11009
+ haloCount: 0,
11010
+ haloBlurRatio: 0.02,
11011
+ sheenStrength: 0.08,
11012
+ };
11013
+ case 'ember':
11014
+ return {
11015
+ baseRadiusRatio: -0.004,
11016
+ horizontalStretch: -0.03,
11017
+ verticalStretch: 0.03,
11018
+ wobbleAmplitude: 0.02,
11019
+ wobbleFrequency: 1,
11020
+ ringCount: 0,
11021
+ sparkleCount: 3,
11022
+ haloCount: 0,
11023
+ haloBlurRatio: 0.04,
11024
+ sheenStrength: 0.06,
11025
+ };
11026
+ case 'glacier':
11027
+ return {
11028
+ baseRadiusRatio: 0.012,
11029
+ horizontalStretch: 0.01,
11030
+ verticalStretch: 0.02,
11031
+ wobbleAmplitude: -0.006,
11032
+ wobbleFrequency: -1,
11033
+ ringCount: 0,
11034
+ sparkleCount: 0,
11035
+ haloCount: 0,
11036
+ haloBlurRatio: -0.01,
11037
+ sheenStrength: 0.12,
11038
+ };
11039
+ case 'pearl':
11040
+ default:
11041
+ return {
11042
+ baseRadiusRatio: 0.02,
11043
+ horizontalStretch: 0.025,
11044
+ verticalStretch: 0.02,
11045
+ wobbleAmplitude: -0.01,
11046
+ wobbleFrequency: 0,
11047
+ ringCount: 0,
11048
+ sparkleCount: -1,
11049
+ haloCount: 1,
11050
+ haloBlurRatio: 0.02,
11051
+ sheenStrength: 0.1,
11052
+ };
11053
+ }
11054
+ }
11055
+ /**
11056
+ * Resolves the color set used by the orb renderer.
11057
+ *
11058
+ * @param palette Base avatar palette.
11059
+ * @param family Selected orb family.
11060
+ * @returns Derived orb-specific color set.
11061
+ *
11062
+ * @private helper of `orbAvatarVisual`
11063
+ */
11064
+ function resolveOrbColorSet(palette, family) {
11065
+ const primaryColor = Color.fromSafe(palette.primary);
11066
+ const secondaryColor = Color.fromSafe(palette.secondary);
11067
+ const accentColor = Color.fromSafe(palette.accent);
11068
+ const highlightColor = Color.fromSafe(palette.highlight);
11069
+ const shadowColor = Color.fromSafe(palette.shadow);
11070
+ switch (family) {
11071
+ case 'nebula':
11072
+ return {
11073
+ core: accentColor.then(lighten(0.16)).then(saturate(0.14)).toHex(),
11074
+ mid: secondaryColor.then(lighten(0.08)).then(saturate(0.08)).toHex(),
11075
+ outer: primaryColor.then(darken(0.03)).then(saturate(0.04)).toHex(),
11076
+ rim: shadowColor.then(lighten(0.08)).toHex(),
11077
+ highlight: highlightColor.then(lighten(0.14)).toHex(),
11078
+ aura: secondaryColor.then(lighten(0.18)).toHex(),
11079
+ };
11080
+ case 'ember':
11081
+ return {
11082
+ core: accentColor.then(lighten(0.2)).then(saturate(0.16)).toHex(),
11083
+ mid: primaryColor.then(lighten(0.1)).then(saturate(0.08)).toHex(),
11084
+ outer: secondaryColor.then(darken(0.04)).then(saturate(0.04)).toHex(),
11085
+ rim: shadowColor.then(lighten(0.08)).toHex(),
11086
+ highlight: highlightColor.then(lighten(0.18)).toHex(),
11087
+ aura: accentColor.then(lighten(0.12)).toHex(),
11088
+ };
11089
+ case 'glacier':
11090
+ return {
11091
+ core: highlightColor.then(lighten(0.18)).then(saturate(-0.04)).toHex(),
11092
+ mid: secondaryColor.then(lighten(0.1)).then(saturate(-0.06)).toHex(),
11093
+ outer: primaryColor.then(lighten(0.06)).toHex(),
11094
+ rim: shadowColor.then(lighten(0.12)).toHex(),
11095
+ highlight: highlightColor.then(lighten(0.26)).toHex(),
11096
+ aura: primaryColor.then(lighten(0.18)).toHex(),
11097
+ };
11098
+ case 'pearl':
11099
+ default:
11100
+ return {
11101
+ core: highlightColor.then(lighten(0.2)).then(saturate(-0.06)).toHex(),
11102
+ mid: primaryColor.then(lighten(0.12)).then(saturate(-0.02)).toHex(),
11103
+ outer: secondaryColor.then(lighten(0.08)).then(saturate(-0.04)).toHex(),
11104
+ rim: shadowColor.then(lighten(0.12)).toHex(),
11105
+ highlight: highlightColor.then(lighten(0.3)).toHex(),
11106
+ aura: highlightColor.then(lighten(0.18)).toHex(),
11107
+ };
11108
+ }
11109
+ }
11110
+ /**
11111
+ * Creates the orb silhouette points from the deterministic profile.
11112
+ *
11113
+ * @param options Orb geometry options.
11114
+ * @returns Smoothly varying orb outline.
11115
+ *
11116
+ * @private helper of `orbAvatarVisual`
11117
+ */
11118
+ function createOrbSilhouettePoints(options) {
11119
+ const { centerX, centerY, radius, profile, timeMs } = options;
11120
+ const pointCount = 48;
11121
+ return Array.from({ length: pointCount }, (_, pointIndex) => {
11122
+ const progress = pointIndex / pointCount;
11123
+ const angle = -Math.PI / 2 + progress * Math.PI * 2;
11124
+ const breathing = Math.sin(timeMs / (1450 / profile.pulseSpeed) + profile.bandRotation) * profile.wobbleAmplitude;
11125
+ const surfaceWaveOne = Math.sin(angle * profile.wobbleFrequencyOne + profile.highlightAngle + timeMs / (980 / profile.pulseSpeed)) * profile.wobbleAmplitude;
11126
+ const surfaceWaveTwo = Math.cos(angle * profile.wobbleFrequencyTwo - profile.bandRotation * 0.8 + timeMs / (1320 / profile.pulseSpeed)) *
11127
+ profile.wobbleAmplitude *
11128
+ 0.62;
11129
+ const surfaceWaveThree = Math.sin(angle * profile.wobbleFrequencyThree +
11130
+ profile.highlightAngle * 1.4 -
11131
+ timeMs / (1710 / profile.pulseSpeed)) *
11132
+ profile.wobbleAmplitude *
11133
+ 0.38;
11134
+ const surfaceTaper = Math.sin(angle * 2 + profile.highlightAngle) * profile.wobbleAmplitude * 0.2;
11135
+ const localRadius = radius * (1 + breathing * 0.12 + surfaceWaveOne + surfaceWaveTwo + surfaceWaveThree + surfaceTaper);
11136
+ return {
11137
+ x: centerX +
11138
+ Math.cos(angle) * localRadius * profile.horizontalStretch +
11139
+ Math.sin(angle * 3 + profile.highlightAngle + timeMs / 2100) * radius * 0.012,
11140
+ y: centerY +
11141
+ Math.sin(angle) * localRadius * profile.verticalStretch +
11142
+ Math.cos(angle * 2 - profile.highlightAngle + timeMs / 2400) * radius * 0.01,
11143
+ };
11144
+ });
11145
+ }
11146
+ /**
11147
+ * Draws the atmospheric glow behind the orb.
11148
+ *
11149
+ * @param context Canvas 2D context.
11150
+ * @param size Canvas size in CSS pixels.
11151
+ * @param centerX Orb center X coordinate.
11152
+ * @param centerY Orb center Y coordinate.
11153
+ * @param radius Orb base radius.
11154
+ * @param colorSet Derived orb color set.
11155
+ * @param profile Deterministic orb profile.
11156
+ * @param timeMs Current animation time in milliseconds.
11157
+ *
11158
+ * @private helper of `orbAvatarVisual`
11159
+ */
11160
+ function drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs) {
11161
+ const atmosphereGradient = context.createRadialGradient(centerX, centerY, radius * 0.08, centerX, centerY, radius * (1.9 + profile.haloBlurRatio));
11162
+ atmosphereGradient.addColorStop(0, `${colorSet.highlight}26`);
11163
+ atmosphereGradient.addColorStop(0.32, `${colorSet.aura}16`);
11164
+ atmosphereGradient.addColorStop(1, `${colorSet.aura}00`);
11165
+ context.save();
11166
+ context.globalCompositeOperation = 'screen';
11167
+ context.fillStyle = atmosphereGradient;
11168
+ context.fillRect(0, 0, size, size);
11169
+ for (let haloIndex = 0; haloIndex < profile.haloCount; haloIndex++) {
11170
+ const haloPulse = Math.sin(timeMs / (1200 + haloIndex * 180) + profile.highlightAngle) * radius * 0.025;
11171
+ const haloRadiusX = radius * (1.18 + haloIndex * 0.18) + haloPulse;
11172
+ const haloRadiusY = radius * (0.98 + haloIndex * 0.16) + haloPulse * 0.82;
11173
+ const haloGradient = context.createRadialGradient(centerX, centerY, radius * 0.12, centerX, centerY, haloRadiusX * 1.12);
11174
+ haloGradient.addColorStop(0, `${colorSet.aura}${haloIndex === 0 ? '38' : '24'}`);
11175
+ haloGradient.addColorStop(0.5, `${colorSet.highlight}${haloIndex === 0 ? '1f' : '12'}`);
11176
+ haloGradient.addColorStop(1, `${colorSet.aura}00`);
11177
+ context.beginPath();
11178
+ context.ellipse(centerX, centerY, haloRadiusX, haloRadiusY, profile.highlightAngle * 0.12 + haloIndex * 0.2 + Math.sin(timeMs / 3800) * 0.04, 0, Math.PI * 2);
11179
+ context.fillStyle = haloGradient;
11180
+ context.fill();
11181
+ }
11182
+ context.restore();
11183
+ }
11184
+ /**
11185
+ * Draws the main orb body using the smooth silhouette path.
11186
+ *
11187
+ * @param context Canvas 2D context.
11188
+ * @param points Smooth orb outline points.
11189
+ * @param centerX Orb center X coordinate.
11190
+ * @param centerY Orb center Y coordinate.
11191
+ * @param radius Orb base radius.
11192
+ * @param colorSet Derived orb color set.
11193
+ * @param profile Deterministic orb profile.
11194
+ * @param size Canvas size in CSS pixels.
11195
+ *
11196
+ * @private helper of `orbAvatarVisual`
11197
+ */
11198
+ function drawOrbBody(context, points, centerX, centerY, radius, colorSet, profile, size) {
11199
+ const bodyGradient = context.createRadialGradient(centerX - radius * 0.22, centerY - radius * 0.24, radius * 0.05, centerX + radius * 0.02, centerY + radius * 0.1, radius * (1.14 + profile.haloBlurRatio * 0.3));
11200
+ bodyGradient.addColorStop(0, `${colorSet.highlight}f8`);
11201
+ bodyGradient.addColorStop(0.22, `${colorSet.core}f2`);
11202
+ bodyGradient.addColorStop(0.58, `${colorSet.mid}e8`);
11203
+ bodyGradient.addColorStop(0.86, `${colorSet.outer}dc`);
11204
+ bodyGradient.addColorStop(1, `${colorSet.rim}ea`);
11205
+ context.save();
11206
+ traceSmoothClosedPath(context, points);
11207
+ context.shadowColor = `${colorSet.rim}aa`;
11208
+ context.shadowBlur = size * (0.06 + profile.haloBlurRatio * 0.15);
11209
+ context.fillStyle = bodyGradient;
11210
+ context.fill();
11211
+ context.restore();
11212
+ context.save();
11213
+ traceSmoothClosedPath(context, points);
11214
+ context.strokeStyle = `${colorSet.highlight}${profile.family === 'pearl' ? '72' : '58'}`;
11215
+ context.lineWidth = Math.max(1.2, size * 0.012);
11216
+ context.lineJoin = 'round';
11217
+ context.lineCap = 'round';
11218
+ context.stroke();
11219
+ context.restore();
11220
+ }
11221
+ /**
11222
+ * Draws the layered energy rings and soft internal gradients inside the orb.
11223
+ *
11224
+ * @param context Canvas 2D context.
11225
+ * @param centerX Orb center X coordinate.
11226
+ * @param centerY Orb center Y coordinate.
11227
+ * @param radius Orb base radius.
11228
+ * @param colorSet Derived orb color set.
11229
+ * @param profile Deterministic orb profile.
11230
+ * @param size Canvas size in CSS pixels.
11231
+ * @param timeMs Current animation time in milliseconds.
11232
+ *
11233
+ * @private helper of `orbAvatarVisual`
11234
+ */
11235
+ function drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
11236
+ const internalGradient = context.createRadialGradient(centerX - radius * 0.08, centerY - radius * 0.1, radius * 0.06, centerX, centerY, radius * (0.95 + profile.sheenStrength * 0.15));
11237
+ internalGradient.addColorStop(0, `${colorSet.highlight}70`);
11238
+ internalGradient.addColorStop(0.48, `${colorSet.core}22`);
11239
+ internalGradient.addColorStop(1, `${colorSet.rim}00`);
11240
+ context.fillStyle = internalGradient;
11241
+ context.fillRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
11242
+ for (let ringIndex = 0; ringIndex < profile.ringCount; ringIndex++) {
11243
+ const ringProgress = (ringIndex + 1) / (profile.ringCount + 1);
11244
+ const ringRadiusX = radius * (0.34 + ringProgress * 0.44);
11245
+ const ringRadiusY = radius * (0.28 + ringProgress * 0.38);
11246
+ const ringRotation = profile.highlightAngle * 0.24 +
11247
+ ringIndex * 0.4 +
11248
+ Math.sin(timeMs / (1800 + ringIndex * 180) + profile.bandRotation) * 0.08;
11249
+ context.beginPath();
11250
+ context.ellipse(centerX + Math.cos(profile.highlightAngle) * radius * 0.03, centerY + Math.sin(profile.highlightAngle) * radius * 0.02, ringRadiusX, ringRadiusY, ringRotation, 0, Math.PI * 2);
11251
+ context.strokeStyle = ringIndex % 2 === 0 ? `${colorSet.highlight}32` : `${colorSet.aura}24`;
11252
+ context.lineWidth = Math.max(1.2, size * (0.007 - ringIndex * 0.001));
11253
+ context.shadowColor = `${colorSet.highlight}55`;
11254
+ context.shadowBlur = size * 0.02;
11255
+ context.stroke();
11256
+ }
11257
+ }
11258
+ /**
11259
+ * Draws soft sparkles and seeded dust inside the orb.
11260
+ *
11261
+ * @param context Canvas 2D context.
11262
+ * @param centerX Orb center X coordinate.
11263
+ * @param centerY Orb center Y coordinate.
11264
+ * @param radius Orb base radius.
11265
+ * @param colorSet Derived orb color set.
11266
+ * @param profile Deterministic orb profile.
11267
+ * @param size Canvas size in CSS pixels.
11268
+ * @param createRandom Seeded random factory.
11269
+ * @param timeMs Current animation time in milliseconds.
11270
+ *
11271
+ * @private helper of `orbAvatarVisual`
11272
+ */
11273
+ function drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs) {
11274
+ const sparkleStride = Math.max(1, Math.floor(profile.sparkleCount / 6));
11275
+ for (let sparkleIndex = 0; sparkleIndex < profile.sparkleCount; sparkleIndex++) {
11276
+ const sparkleRandom = createRandom(`orb-sparkle-${sparkleIndex}`);
11277
+ const sparkleAngle = sparkleRandom() * Math.PI * 2 + profile.highlightAngle * 0.4;
11278
+ const sparkleOrbitRadius = radius * (0.42 + sparkleRandom() * 0.55);
11279
+ const sparkleOrbitPulse = 0.92 + Math.sin(timeMs / (700 + sparkleIndex * 70) + profile.bandRotation) * 0.08;
11280
+ const sparkleCenterX = centerX + Math.cos(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
11281
+ const sparkleCenterY = centerY + Math.sin(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
11282
+ const sparkleRadius = size * (0.0028 + sparkleRandom() * 0.0058) * sparkleOrbitPulse;
11283
+ context.beginPath();
11284
+ context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius * 2, 0, Math.PI * 2);
11285
+ context.fillStyle = `${colorSet.highlight}14`;
11286
+ context.fill();
11287
+ context.beginPath();
11288
+ context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius, 0, Math.PI * 2);
11289
+ context.fillStyle = sparkleIndex % sparkleStride === 0 ? `${colorSet.highlight}d2` : `${colorSet.aura}c8`;
11290
+ context.shadowColor = `${colorSet.highlight}66`;
11291
+ context.shadowBlur = size * 0.012;
11292
+ context.fill();
11293
+ }
11294
+ }
11295
+ /**
11296
+ * Draws the specular sweep that makes the orb feel glossy and dimensional.
11297
+ *
11298
+ * @param context Canvas 2D context.
11299
+ * @param centerX Orb center X coordinate.
11300
+ * @param centerY Orb center Y coordinate.
11301
+ * @param radius Orb base radius.
11302
+ * @param colorSet Derived orb color set.
11303
+ * @param profile Deterministic orb profile.
11304
+ * @param size Canvas size in CSS pixels.
11305
+ * @param timeMs Current animation time in milliseconds.
11306
+ *
11307
+ * @private helper of `orbAvatarVisual`
11308
+ */
11309
+ function drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
11310
+ const sheenAngle = profile.bandRotation + timeMs / (2400 / profile.pulseSpeed);
11311
+ const sheenDirectionX = Math.cos(sheenAngle);
11312
+ const sheenDirectionY = Math.sin(sheenAngle);
11313
+ const sheenGradient = context.createLinearGradient(centerX - sheenDirectionX * radius, centerY - sheenDirectionY * radius, centerX + sheenDirectionX * radius, centerY + sheenDirectionY * radius);
11314
+ sheenGradient.addColorStop(0, `${colorSet.highlight}00`);
11315
+ sheenGradient.addColorStop(0.24, `${colorSet.highlight}0e`);
11316
+ sheenGradient.addColorStop(0.43, `${colorSet.highlight}${profile.sheenStrength > 0.65 ? '66' : '48'}`);
11317
+ sheenGradient.addColorStop(0.57, `${colorSet.core}${profile.sheenStrength > 0.65 ? '42' : '2e'}`);
11318
+ sheenGradient.addColorStop(0.75, `${colorSet.aura}1e`);
11319
+ sheenGradient.addColorStop(1, `${colorSet.highlight}00`);
11320
+ context.fillStyle = sheenGradient;
11321
+ context.fillRect(centerX - radius * 1.6, centerY - radius * 1.6, radius * 3.2, radius * 3.2);
11322
+ context.beginPath();
11323
+ context.ellipse(centerX - radius * 0.18, centerY - radius * 0.2, radius * 0.44, radius * 0.24, profile.highlightAngle * 0.32, 0, Math.PI * 2);
11324
+ context.fillStyle = `${colorSet.highlight}${profile.family === 'ember' ? '26' : '2e'}`;
11325
+ context.shadowColor = `${colorSet.highlight}55`;
11326
+ context.shadowBlur = size * 0.02;
11327
+ context.fill();
11328
+ }
11329
+ /**
11330
+ * Draws the bright nucleus that gives the orb a recognisable center.
11331
+ *
11332
+ * @param context Canvas 2D context.
11333
+ * @param centerX Orb center X coordinate.
11334
+ * @param centerY Orb center Y coordinate.
11335
+ * @param radius Orb base radius.
11336
+ * @param colorSet Derived orb color set.
11337
+ * @param profile Deterministic orb profile.
11338
+ * @param size Canvas size in CSS pixels.
11339
+ * @param timeMs Current animation time in milliseconds.
11340
+ *
11341
+ * @private helper of `orbAvatarVisual`
11342
+ */
11343
+ function drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
11344
+ const coreRadiusX = radius * (0.18 + profile.sheenStrength * 0.06);
11345
+ const coreRadiusY = radius * (0.15 + profile.sheenStrength * 0.045);
11346
+ const corePulse = 1 + Math.sin(timeMs / (1100 / profile.pulseSpeed) + profile.bandRotation) * 0.04;
11347
+ context.beginPath();
11348
+ context.ellipse(centerX + profile.coreShiftX * radius * 0.18, centerY + profile.coreShiftY * radius * 0.18, coreRadiusX * corePulse, coreRadiusY * corePulse, profile.highlightAngle * 0.12, 0, Math.PI * 2);
11349
+ context.fillStyle = `${colorSet.core}f0`;
11350
+ context.shadowColor = `${colorSet.highlight}88`;
11351
+ context.shadowBlur = size * 0.03;
11352
+ context.fill();
11353
+ context.beginPath();
11354
+ context.arc(centerX - radius * 0.06, centerY - radius * 0.07, radius * 0.06, 0, Math.PI * 2);
11355
+ context.fillStyle = `${colorSet.highlight}d6`;
11356
+ context.fill();
11357
+ }
11358
+ /**
11359
+ * Draws the final rim stroke so the orb stays crisp against busy backgrounds.
11360
+ *
11361
+ * @param context Canvas 2D context.
11362
+ * @param points Smooth orb outline points.
11363
+ * @param colorSet Derived orb color set.
11364
+ * @param size Canvas size in CSS pixels.
11365
+ *
11366
+ * @private helper of `orbAvatarVisual`
11367
+ */
11368
+ function drawOrbRim(context, points, colorSet, size) {
11369
+ context.save();
11370
+ traceSmoothClosedPath(context, points);
11371
+ context.strokeStyle = `${colorSet.rim}c0`;
11372
+ context.lineWidth = Math.max(1.25, size * 0.013);
11373
+ context.lineJoin = 'round';
11374
+ context.lineCap = 'round';
11375
+ context.shadowColor = `${colorSet.highlight}4f`;
11376
+ context.shadowBlur = size * 0.018;
11377
+ context.stroke();
11378
+ context.restore();
11379
+ }
11380
+ /**
11381
+ * Clamps a number into the provided range.
11382
+ *
11383
+ * @param value Number to clamp.
11384
+ * @param minimum Minimum accepted value.
11385
+ * @param maximum Maximum accepted value.
11386
+ * @returns Clamped number.
11387
+ *
11388
+ * @private helper of `orbAvatarVisual`
11389
+ */
11390
+ function clampNumber(value, minimum, maximum) {
11391
+ return Math.min(maximum, Math.max(minimum, value));
11392
+ }
11393
+ /**
11394
+ * Clamps a number into the provided integer range.
11395
+ *
11396
+ * @param value Number to clamp.
11397
+ * @param minimum Minimum accepted value.
11398
+ * @param maximum Maximum accepted value.
11399
+ * @returns Clamped integer.
11400
+ *
11401
+ * @private helper of `orbAvatarVisual`
11402
+ */
11403
+ function clampInteger(value, minimum, maximum) {
11404
+ return Math.min(maximum, Math.max(minimum, Math.round(value)));
11405
+ }
11406
+
11407
+ /* eslint-disable no-magic-numbers */
11408
+ /**
11409
+ * Pixel-art avatar visual.
11410
+ *
11411
+ * @private built-in avatar visual
11412
+ */
11413
+ const pixelArtAvatarVisual = {
11414
+ id: 'pixel-art',
11415
+ title: 'Pixel art',
11416
+ description: 'Symmetric retro badge with a deterministic face and palette-driven pixels.',
11417
+ isAnimated: false,
11418
+ render({ context, size, palette, createRandom, avatarDefinition }) {
11419
+ const random = createRandom('pixel-art');
11420
+ const panelSize = size * 0.62;
11421
+ const panelX = (size - panelSize) / 2;
11422
+ const panelY = size * 0.19;
11423
+ const pixelGridSize = 10;
11424
+ const pixelSize = panelSize / pixelGridSize;
11425
+ const halfColumns = Math.ceil(pixelGridSize / 2);
11426
+ const colorStops = [palette.primary, palette.secondary, palette.accent, palette.highlight];
11427
+ const foreheadRowCount = 2 + Math.floor(random() * 2);
11428
+ const cheekInset = 1 + Math.floor(random() * 2);
11429
+ const emblemHeight = 2 + Math.floor(random() * 2);
11430
+ drawAvatarFrame(context, size, palette);
11431
+ const glow = context.createRadialGradient(size * 0.5, size * 0.32, size * 0.05, size * 0.5, size * 0.32, size * 0.5);
11432
+ glow.addColorStop(0, `${palette.highlight}aa`);
11433
+ glow.addColorStop(1, `${palette.highlight}00`);
11434
+ context.fillStyle = glow;
11435
+ context.fillRect(0, 0, size, size);
11436
+ context.save();
11437
+ createRoundedRectPath(context, panelX, panelY, panelSize, panelSize, panelSize * 0.16);
11438
+ context.fillStyle = palette.shadow;
11439
+ context.shadowColor = `${palette.shadow}66`;
11440
+ context.shadowBlur = size * 0.08;
11441
+ context.fill();
11442
+ context.restore();
11443
+ for (let rowIndex = 0; rowIndex < pixelGridSize; rowIndex++) {
11444
+ for (let columnIndex = 0; columnIndex < halfColumns; columnIndex++) {
11445
+ const mirroredColumnIndex = pixelGridSize - columnIndex - 1;
11446
+ const normalizedRowDistance = Math.abs(rowIndex - pixelGridSize / 2) / (pixelGridSize / 2);
11447
+ const normalizedColumnDistance = columnIndex / halfColumns;
11448
+ const fillChance = 0.85 - normalizedRowDistance * 0.32 - normalizedColumnDistance * 0.08;
11449
+ if (random() > fillChance) {
11450
+ continue;
11451
+ }
11452
+ const color = colorStops[Math.min(colorStops.length - 1, Math.floor(random() *
11453
+ (rowIndex < foreheadRowCount
11454
+ ? 2
11455
+ : rowIndex > pixelGridSize - emblemHeight - 1
11456
+ ? colorStops.length
11457
+ : 3)))];
11458
+ if (columnIndex === 0 &&
11459
+ rowIndex >= cheekInset &&
11460
+ rowIndex <= pixelGridSize - cheekInset - 1 &&
11461
+ random() < 0.4) {
11462
+ continue;
11463
+ }
11464
+ drawPixel(context, panelX + columnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
11465
+ if (mirroredColumnIndex !== columnIndex) {
11466
+ drawPixel(context, panelX + mirroredColumnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
11467
+ }
11468
+ }
11469
+ }
11470
+ const eyeRowIndex = 3 + Math.floor(random() * 2);
11471
+ const eyeColumnOffset = 2 + Math.floor(random() * 2);
11472
+ drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
11473
+ drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
11474
+ drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
11475
+ drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
11476
+ const mouthRowIndex = eyeRowIndex + 3;
11477
+ const mouthWidth = 2 + Math.floor(random() * 2);
11478
+ for (let mouthOffset = 0; mouthOffset < mouthWidth; mouthOffset++) {
11479
+ drawPixel(context, panelX + (4 + mouthOffset) * pixelSize, panelY + mouthRowIndex * pixelSize, pixelSize, palette.shadow);
11480
+ }
11481
+ context.save();
11482
+ context.fillStyle = `${palette.highlight}44`;
11483
+ context.font = `${Math.round(size * 0.12)}px sans-serif`;
11484
+ context.textAlign = 'center';
11485
+ context.fillText(avatarDefinition.agentName.charAt(0).toUpperCase(), size * 0.5, size * 0.88);
11486
+ context.restore();
11487
+ },
11488
+ };
11489
+ /**
11490
+ * Draws one pixel-art block with a tiny inner highlight.
11491
+ *
11492
+ * @param context Canvas 2D context.
11493
+ * @param x Left coordinate.
11494
+ * @param y Top coordinate.
11495
+ * @param size Pixel size.
11496
+ * @param color Pixel fill color.
11497
+ *
11498
+ * @private helper of `pixelArtAvatarVisual`
11499
+ */
11500
+ function drawPixel(context, x, y, size, color) {
11501
+ const normalizedSize = size * 0.9;
11502
+ const offset = (size - normalizedSize) / 2;
11503
+ context.fillStyle = color;
11504
+ context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize);
11505
+ context.fillStyle = 'rgba(255,255,255,0.18)';
11506
+ context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize * 0.14);
11507
+ }
11508
+
11509
+ // Note: [💞] Ignore a discrepancy between file name and entity name
11510
+ /**
11511
+ * Built-in avatar visuals available to the app.
11512
+ *
11513
+ * @private shared registry for the avatar rendering system
11514
+ */
11515
+ const AVATAR_VISUALS = [
11516
+ pixelArtAvatarVisual,
11517
+ octopusAvatarVisual,
11518
+ octopus2AvatarVisual,
11519
+ octopus3AvatarVisual,
11520
+ asciiOctopusAvatarVisual,
11521
+ minecraftAvatarVisual,
11522
+ fractalAvatarVisual,
11523
+ orbAvatarVisual,
11524
+ ];
11525
+ /**
11526
+ * Normalizes user-facing avatar visual names so ids can be matched case-insensitively
11527
+ * across spaces, hyphens, underscores, and future separator variants.
11528
+ *
11529
+ * @param value Raw avatar visual id or title.
11530
+ * @returns Stable lookup key.
11531
+ *
11532
+ * @private shared registry for the avatar rendering system
11533
+ */
11534
+ function normalizeAvatarVisualLookupKey(value) {
11535
+ return value
11536
+ .trim()
11537
+ .toLowerCase()
11538
+ .replace(/[^a-z0-9]+/g, '');
11539
+ }
11540
+ /**
11541
+ * Resolves a user-facing avatar visual value to a supported built-in visual id.
11542
+ *
11543
+ * The lookup is derived from `AVATAR_VISUALS`, so new visuals become selectable by
11544
+ * adding them to the registry rather than updating parser-specific option lists.
11545
+ *
11546
+ * @param value Raw visual id/title, for example `PIXEL_ART`, `pixel art`, or `pixel-art`.
11547
+ * @returns Matching visual id or `null` when the value is empty/unknown.
11548
+ *
11549
+ * @private shared registry for the avatar rendering system
11550
+ */
11551
+ function resolveAvatarVisualId(value) {
11552
+ if (!value) {
11553
+ return null;
11554
+ }
11555
+ const normalizedValue = normalizeAvatarVisualLookupKey(value);
11556
+ if (!normalizedValue) {
11557
+ return null;
11558
+ }
11559
+ const avatarVisual = AVATAR_VISUALS.find((candidateAvatarVisual) => normalizeAvatarVisualLookupKey(candidateAvatarVisual.id) === normalizedValue ||
11560
+ normalizeAvatarVisualLookupKey(candidateAvatarVisual.title) === normalizedValue);
11561
+ return (avatarVisual === null || avatarVisual === void 0 ? void 0 : avatarVisual.id) || null;
11562
+ }
11563
+
11564
+ /**
11565
+ * META AVATAR commitment definition
11566
+ *
11567
+ * The `META AVATAR` commitment sets the built-in default avatar visual used when
11568
+ * the agent does not provide an explicit `META IMAGE`.
11569
+ *
11570
+ * @private [đŸĒ”] Maybe export the commitments through some package
11571
+ */
11572
+ class MetaAvatarCommitmentDefinition extends BaseCommitmentDefinition {
11573
+ constructor() {
11574
+ super('META AVATAR');
11575
+ }
11576
+ /**
11577
+ * Short one-line description of META AVATAR.
11578
+ */
11579
+ get description() {
11580
+ return "Set the agent's built-in avatar visual.";
8217
11581
  }
8218
11582
  /**
8219
11583
  * Icon for this commitment.
8220
11584
  */
8221
11585
  get icon() {
8222
- return 'â„šī¸';
11586
+ return '👤';
8223
11587
  }
8224
11588
  /**
8225
- * Markdown documentation for META commitment.
11589
+ * Markdown documentation for META AVATAR commitment.
8226
11590
  */
8227
11591
  get documentation() {
11592
+ const supportedVisuals = AVATAR_VISUALS.map((avatarVisual) => `\`${avatarVisual.id}\``).join(', ');
8228
11593
  return spacetrim.spaceTrim(`
8229
- # META
8230
-
8231
- Sets meta-information about the agent that is used for display and attribution purposes.
8232
-
8233
- ## Supported META types
11594
+ # META AVATAR
8234
11595
 
8235
- - **META IMAGE** - Sets the agent's avatar/profile image URL
8236
- - **META LINK** - Provides profile/source links for the person the agent models
8237
- - **META DOMAIN** - Sets the canonical custom domain/host of the agent
8238
- - **META TITLE** - Sets the agent's display title
8239
- - **META DESCRIPTION** - Sets the agent's description
8240
- - **META INPUT PLACEHOLDER** - Sets chat input placeholder text
8241
- - **META [ANYTHING]** - Any other meta information in uppercase format
11596
+ Sets the built-in avatar visual used for the agent when no explicit \`META IMAGE\` is provided.
8242
11597
 
8243
11598
  ## Key aspects
8244
11599
 
8245
- - Does not modify the agent's behavior or responses
8246
- - Used for visual representation and attribution in user interfaces
8247
- - Multiple META commitments of different types can be used
8248
- - Multiple META LINK commitments can be used for different social profiles
8249
- - If multiple META commitments of the same type are specified, the last one takes precedence (except for LINK)
11600
+ - Does not modify the agent's behavior or responses.
11601
+ - Only one \`META AVATAR\` should be used per agent.
11602
+ - If multiple are specified, the last one takes precedence.
11603
+ - Values are matched case-insensitively and spaces, hyphens, and underscores are normalized.
11604
+ - Supported visuals are derived from the shared avatar registry: ${supportedVisuals}.
8250
11605
 
8251
11606
  ## Examples
8252
11607
 
8253
- ### Basic meta information
8254
-
8255
- \`\`\`book
8256
- Professional Assistant
8257
-
8258
- META IMAGE https://example.com/professional-avatar.jpg
8259
- META TITLE Senior Business Consultant
8260
- META DESCRIPTION Specialized in strategic planning and project management
8261
- META LINK https://linkedin.com/in/professional
8262
- \`\`\`
8263
-
8264
- ### Multiple links and custom meta
8265
-
8266
11608
  \`\`\`book
8267
- Open Source Developer
11609
+ Pixel Assistant
8268
11610
 
8269
- META IMAGE /assets/dev-avatar.png
8270
- META LINK https://github.com/developer
8271
- META LINK https://twitter.com/devhandle
8272
- META AUTHOR Jane Smith
8273
- META VERSION 2.1
8274
- META LICENSE MIT
11611
+ META AVATAR PIXEL_ART
11612
+ GOAL Help users with concise answers.
8275
11613
  \`\`\`
8276
11614
 
8277
- ### Creative assistant
8278
-
8279
11615
  \`\`\`book
8280
- Creative Helper
11616
+ Orb Assistant
8281
11617
 
8282
- META IMAGE https://example.com/creative-bot.jpg
8283
- META TITLE Creative Writing Assistant
8284
- META DESCRIPTION Helps with brainstorming, storytelling, and creative projects
8285
- META INSPIRATION Books, movies, and real-world experiences
11618
+ META AVATAR orb
11619
+ GOAL Answer in a calm and focused way.
8286
11620
  \`\`\`
8287
11621
  `);
8288
11622
  }
8289
11623
  applyToAgentModelRequirements(requirements, content) {
8290
- // META commitments don't modify the system message or model requirements
8291
- // They are handled separately in the parsing logic for meta information extraction
8292
- // This method exists for consistency with the CommitmentDefinition interface
11624
+ // META AVATAR doesn't modify the system message or model requirements.
11625
+ // It's handled separately in the parsing logic for profile avatar resolution.
8293
11626
  return requirements;
8294
11627
  }
8295
- /**
8296
- * Extracts meta information from the content based on the meta type
8297
- * This is used by the parsing logic
8298
- */
8299
- extractMetaValue(metaType, content) {
8300
- const trimmedContent = content.trim();
8301
- return trimmedContent || null;
8302
- }
8303
- /**
8304
- * Validates if the provided content is a valid URL (for IMAGE and LINK types)
8305
- */
8306
- isValidUrl(content) {
8307
- try {
8308
- new URL(content.trim());
8309
- return true;
8310
- }
8311
- catch (_a) {
8312
- return false;
8313
- }
8314
- }
8315
- /**
8316
- * Checks if this is a known meta type
8317
- */
8318
- isKnownMetaType(metaType) {
8319
- const knownTypes = ['IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
8320
- return knownTypes.includes(metaType.toUpperCase());
8321
- }
8322
11628
  }
8323
11629
  // Note: [💞] Ignore a discrepancy between file name and entity name
8324
11630
 
@@ -8991,7 +12297,13 @@
8991
12297
  * Short one-line description of MODEL.
8992
12298
  */
8993
12299
  get description() {
8994
- return 'Enforce AI model requirements including name and technical parameters.';
12300
+ return 'Low-level commitment for explicit model selection and technical parameters. Use carefully.';
12301
+ }
12302
+ /**
12303
+ * Marks MODEL as a low-level commitment surfaced with caution.
12304
+ */
12305
+ get isLowLevel() {
12306
+ return true;
8995
12307
  }
8996
12308
  /**
8997
12309
  * Icon for this commitment.
@@ -9006,11 +12318,17 @@
9006
12318
  return spacetrim.spaceTrim(`
9007
12319
  # ${this.type}
9008
12320
 
9009
- Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
12321
+ Low-level commitment for explicit AI model selection and technical parameters.
12322
+
12323
+ ## Status
12324
+
12325
+ - This commitment is low-level and not used by most of the users.
12326
+ - Use it when you need to pin a specific model or fine-tune model parameters directly.
12327
+ - Prefer automatic model selection when you do not need manual control.
9010
12328
 
9011
12329
  ## Key aspects
9012
12330
 
9013
- - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments
12331
+ - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments.
9014
12332
  - Multiple \`MODEL\` commitments can be used to specify different parameters
9015
12333
  - Both \`MODEL\` and \`MODELS\` terms work identically and can be used interchangeably
9016
12334
  - Parameters control the randomness, creativity, and technical aspects of model responses
@@ -9539,6 +12857,12 @@
9539
12857
  get description() {
9540
12858
  return 'Add behavioral rules the agent must follow.';
9541
12859
  }
12860
+ /**
12861
+ * Marks RULE as one of the priority commitments surfaced first in catalogues.
12862
+ */
12863
+ get isImportant() {
12864
+ return true;
12865
+ }
9542
12866
  /**
9543
12867
  * Icon for this commitment.
9544
12868
  */
@@ -10158,6 +13482,46 @@
10158
13482
  }
10159
13483
  // Note: [💞] Ignore a discrepancy between file name and entity name
10160
13484
 
13485
+ /**
13486
+ * Header used for same-server TEAM calls that may access private teammate agents.
13487
+ *
13488
+ * @private internal Agents Server access wiring
13489
+ */
13490
+ const TEAM_INTERNAL_AGENT_ACCESS_HEADER = 'x-promptbook-team-agent-access-token';
13491
+ /**
13492
+ * Creates request headers for same-server TEAM calls.
13493
+ *
13494
+ * @param options - Target agent URL, local server URL, and resolved access token.
13495
+ * @returns Header map when the target is same-origin; otherwise an empty map.
13496
+ *
13497
+ * @private internal Agents Server access wiring
13498
+ */
13499
+ function createTeamInternalAgentAccessHeaders(options) {
13500
+ if (!options.accessToken || !isSameOriginAgentUrl(options.agentUrl, options.localServerUrl)) {
13501
+ return {};
13502
+ }
13503
+ return {
13504
+ [TEAM_INTERNAL_AGENT_ACCESS_HEADER]: options.accessToken,
13505
+ };
13506
+ }
13507
+ /**
13508
+ * Checks whether a teammate URL points back to the current Agents Server origin.
13509
+ *
13510
+ * @private internal Agents Server access wiring
13511
+ */
13512
+ function isSameOriginAgentUrl(agentUrl, localServerUrl) {
13513
+ if (!localServerUrl) {
13514
+ return false;
13515
+ }
13516
+ try {
13517
+ return new URL(agentUrl).origin === new URL(localServerUrl).origin;
13518
+ }
13519
+ catch (_a) {
13520
+ return false;
13521
+ }
13522
+ }
13523
+ // Note: [💞] Ignore a discrepancy between file name and entity name
13524
+
10161
13525
  /**
10162
13526
  * Map of team tool functions.
10163
13527
  */
@@ -10203,11 +13567,17 @@
10203
13567
  get description() {
10204
13568
  return 'Enable the agent to consult teammate agents via dedicated tools.';
10205
13569
  }
13570
+ /**
13571
+ * Marks TEAM as one of the priority commitments surfaced first in catalogues.
13572
+ */
13573
+ get isImportant() {
13574
+ return true;
13575
+ }
10206
13576
  /**
10207
13577
  * Icon for this commitment.
10208
13578
  */
10209
13579
  get icon() {
10210
- return '??';
13580
+ return 'đŸ‘Ĩ';
10211
13581
  }
10212
13582
  /**
10213
13583
  * Markdown documentation for TEAM commitment.
@@ -10509,21 +13879,28 @@
10509
13879
  /**
10510
13880
  * Resolves a RemoteAgent for the given teammate URL, caching the connection.
10511
13881
  */
10512
- async function getRemoteTeammateAgent(agentUrl) {
10513
- const cached = remoteAgentsByUrl.get(agentUrl);
13882
+ async function getRemoteTeammateAgent(agentUrl, runtimeContext) {
13883
+ var _a, _b;
13884
+ const requestHeaders = createTeamInternalAgentAccessHeaders({
13885
+ agentUrl,
13886
+ localServerUrl: (_a = runtimeContext.agentsServer) === null || _a === void 0 ? void 0 : _a.localServerUrl,
13887
+ accessToken: (_b = runtimeContext.agentsServer) === null || _b === void 0 ? void 0 : _b.teamInternalAccessToken,
13888
+ });
13889
+ const cacheKey = `${agentUrl}|${requestHeaders[TEAM_INTERNAL_AGENT_ACCESS_HEADER] || ''}`;
13890
+ const cached = remoteAgentsByUrl.get(cacheKey);
10514
13891
  if (cached) {
10515
13892
  return cached;
10516
13893
  }
10517
13894
  const connection = (async () => {
10518
13895
  const { RemoteAgent } = await Promise.resolve().then(function () { return RemoteAgent$1; });
10519
- return RemoteAgent.connect({ agentUrl });
13896
+ return RemoteAgent.connect({ agentUrl, requestHeaders });
10520
13897
  })();
10521
- remoteAgentsByUrl.set(agentUrl, connection);
13898
+ remoteAgentsByUrl.set(cacheKey, connection);
10522
13899
  try {
10523
13900
  return await connection;
10524
13901
  }
10525
13902
  catch (error) {
10526
- remoteAgentsByUrl.delete(agentUrl);
13903
+ remoteAgentsByUrl.delete(cacheKey);
10527
13904
  throw error;
10528
13905
  }
10529
13906
  }
@@ -10553,8 +13930,9 @@
10553
13930
  let error = null;
10554
13931
  let toolCalls;
10555
13932
  try {
10556
- const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url);
10557
- const prompt = buildTeammatePrompt(request, createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]));
13933
+ const runtimeContext = createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
13934
+ const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url, runtimeContext);
13935
+ const prompt = buildTeammatePrompt(request, runtimeContext);
10558
13936
  const teammateResult = await remoteAgent.callChatModel(prompt);
10559
13937
  response = teammateResult.content || '';
10560
13938
  toolCalls =
@@ -10593,11 +13971,10 @@
10593
13971
  /**
10594
13972
  * TEMPLATE commitment definition
10595
13973
  *
10596
- * The TEMPLATE commitment enforces a specific response structure or template
10597
- * that the agent must follow when generating responses. This helps ensure
10598
- * consistent message formatting across all agent interactions.
13974
+ * Deprecated legacy commitment for response templates and output structure.
13975
+ * New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
10599
13976
  *
10600
- * Example usage in agent source:
13977
+ * Legacy example usage in agent source:
10601
13978
  *
10602
13979
  * ```book
10603
13980
  * TEMPLATE Always structure your response with: 1) Summary, 2) Details, 3) Next steps
@@ -10617,7 +13994,16 @@
10617
13994
  * Short one-line description of TEMPLATE.
10618
13995
  */
10619
13996
  get description() {
10620
- return 'Enforce a specific message structure or response template.';
13997
+ return 'Deprecated legacy template commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
13998
+ }
13999
+ /**
14000
+ * Optional UI/docs-only deprecation metadata.
14001
+ */
14002
+ get deprecation() {
14003
+ return {
14004
+ message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
14005
+ replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
14006
+ };
10621
14007
  }
10622
14008
  /**
10623
14009
  * Icon for this commitment.
@@ -10632,38 +14018,32 @@
10632
14018
  return spacetrim.spaceTrim(`
10633
14019
  # ${this.type}
10634
14020
 
10635
- Enforces a specific response structure or template that the agent must follow when generating responses.
14021
+ Deprecated legacy commitment for response structure and templates.
10636
14022
 
10637
- ## Key aspects
14023
+ ## Migration
10638
14024
 
10639
- - Both terms work identically and can be used interchangeably.
10640
- - Can be used with or without content.
10641
- - When used without content, enables template mode for structured responses.
10642
- - When used with content, defines the specific template structure to follow.
10643
- - Multiple templates can be combined, with later ones taking precedence.
14025
+ - Existing \`${this.type}\` and \`TEMPLATES\` books still parse and compile.
14026
+ - New books should use \`WRITING SAMPLE\` for concrete response exemplars and \`WRITING RULES\` for structure or formatting constraints.
14027
+ - Runtime behavior is intentionally unchanged for backward compatibility.
10644
14028
 
10645
- ## Examples
14029
+ ## Preferred replacement
10646
14030
 
10647
14031
  \`\`\`book
10648
14032
  Customer Support Agent
10649
14033
 
10650
- PERSONA You are a helpful customer support representative
10651
- TEMPLATE Always structure your response with: 1) Acknowledgment, 2) Solution, 3) Follow-up question
10652
- WRITING RULES Be professional and empathetic
14034
+ GOAL Help the user with support questions.
14035
+ WRITING SAMPLE
14036
+ Thanks for reaching out. Here is the summary, details, and next step.
14037
+ WRITING RULES Keep the response structured as: summary, details, next step.
10653
14038
  \`\`\`
10654
14039
 
10655
- \`\`\`book
10656
- Technical Documentation Assistant
10657
-
10658
- PERSONA You are a technical writing expert
10659
- TEMPLATE Use the following format: **Topic:** [topic] | **Explanation:** [details] | **Example:** [code]
10660
- FORMAT Use markdown with clear headings
10661
- \`\`\`
14040
+ ## Legacy compatibility example
10662
14041
 
10663
14042
  \`\`\`book
10664
- Simple Agent
14043
+ Customer Support Agent
10665
14044
 
10666
- PERSONA You are a virtual assistant
14045
+ GOAL Help the user with support questions.
14046
+ TEMPLATE Always structure your response with: 1) Acknowledgment, 2) Solution, 3) Follow-up question
10667
14047
  TEMPLATE
10668
14048
  \`\`\`
10669
14049
  `);
@@ -10711,120 +14091,6 @@
10711
14091
  }
10712
14092
  // Note: [💞] Ignore a discrepancy between file name and entity name
10713
14093
 
10714
- /**
10715
- * USE commitment definition
10716
- *
10717
- * The USE commitment indicates that the agent should utilize specific tools or capabilities
10718
- * to access and interact with external systems when necessary.
10719
- *
10720
- * Supported USE types:
10721
- * - USE BROWSER: Enables the agent to use a web browser tool
10722
- * - USE SEARCH ENGINE (future): Enables search engine access
10723
- * - USE DEEPSEARCH: Enables deeper research-oriented search access
10724
- * - USE FILE SYSTEM (future): Enables file system operations
10725
- * - USE MCP (future): Enables MCP server connections
10726
- *
10727
- * The content following the USE commitment is ignored (similar to NOTE).
10728
- *
10729
- * Example usage in agent source:
10730
- *
10731
- * ```book
10732
- * USE BROWSER
10733
- * USE SEARCH ENGINE
10734
- * ```
10735
- *
10736
- * @private [đŸĒ”] Maybe export the commitments through some package
10737
- */
10738
- class UseCommitmentDefinition extends BaseCommitmentDefinition {
10739
- constructor() {
10740
- super('USE');
10741
- }
10742
- /**
10743
- * Short one-line description of USE commitments.
10744
- */
10745
- get description() {
10746
- return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, DEEPSEARCH, etc.).';
10747
- }
10748
- /**
10749
- * Icon for this commitment.
10750
- */
10751
- get icon() {
10752
- return '🔧';
10753
- }
10754
- /**
10755
- * Markdown documentation for USE commitment.
10756
- */
10757
- get documentation() {
10758
- return spacetrim.spaceTrim(`
10759
- # USE
10760
-
10761
- Enables the agent to use specific tools or capabilities for interacting with external systems.
10762
-
10763
- ## Supported USE types
10764
-
10765
- - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
10766
- - **USE SEARCH ENGINE** (future) - Enables search engine access
10767
- - **USE DEEPSEARCH** - Enables deeper research-oriented search access
10768
- - **USE FILE SYSTEM** (future) - Enables file system operations
10769
- - **USE MCP** (future) - Enables MCP server connections
10770
-
10771
- ## Key aspects
10772
-
10773
- - The content following the USE commitment is ignored (similar to NOTE)
10774
- - Multiple USE commitments can be specified to enable multiple capabilities
10775
- - The actual tool usage is handled by the agent runtime
10776
-
10777
- ## Examples
10778
-
10779
- ### Basic browser usage
10780
-
10781
- \`\`\`book
10782
- Research Assistant
10783
-
10784
- PERSONA You are a helpful research assistant
10785
- USE BROWSER
10786
- KNOWLEDGE Can search the web for up-to-date information
10787
- \`\`\`
10788
-
10789
- ### Multiple tools
10790
-
10791
- \`\`\`book
10792
- Data Analyst
10793
-
10794
- PERSONA You are a data analyst assistant
10795
- USE BROWSER
10796
- USE FILE SYSTEM
10797
- ACTION Can analyze data from various sources
10798
- \`\`\`
10799
- `);
10800
- }
10801
- applyToAgentModelRequirements(requirements, content) {
10802
- // USE commitments don't modify the system message or model requirements directly
10803
- // They are handled separately in the parsing logic for capability extraction
10804
- // This method exists for consistency with the CommitmentDefinition interface
10805
- return requirements;
10806
- }
10807
- /**
10808
- * Extracts the tool type from the USE commitment
10809
- * This is used by the parsing logic
10810
- */
10811
- extractToolType(content) {
10812
- var _a, _b;
10813
- const trimmedContent = content.trim();
10814
- // The tool type is the first word after USE (already stripped)
10815
- const match = trimmedContent.match(/^(\w+)/);
10816
- return (_b = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : null;
10817
- }
10818
- /**
10819
- * Checks if this is a known USE type
10820
- */
10821
- isKnownUseType(useType) {
10822
- const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'DEEPSEARCH', 'FILE SYSTEM', 'MCP'];
10823
- return knownTypes.includes(useType.toUpperCase());
10824
- }
10825
- }
10826
- // Note: [💞] Ignore a discrepancy between file name and entity name
10827
-
10828
14094
  /**
10829
14095
  * All `USE` commitment types currently participating in final system-message aggregation.
10830
14096
  *
@@ -16810,10 +20076,10 @@
16810
20076
  new MemoryCommitmentDefinition('MEMORIES'),
16811
20077
  new StyleCommitmentDefinition('STYLE'),
16812
20078
  new StyleCommitmentDefinition('STYLES'),
16813
- new RuleCommitmentDefinition('RULES'),
16814
20079
  new RuleCommitmentDefinition('RULE'),
16815
- new LanguageCommitmentDefinition('LANGUAGES'),
20080
+ new RuleCommitmentDefinition('RULES'),
16816
20081
  new LanguageCommitmentDefinition('LANGUAGE'),
20082
+ new LanguageCommitmentDefinition('LANGUAGES'),
16817
20083
  new WritingSampleCommitmentDefinition(),
16818
20084
  new WritingRulesCommitmentDefinition(),
16819
20085
  new SampleCommitmentDefinition('SAMPLE'),
@@ -16830,6 +20096,7 @@
16830
20096
  new ActionCommitmentDefinition('ACTION'),
16831
20097
  new ActionCommitmentDefinition('ACTIONS'),
16832
20098
  new ComponentCommitmentDefinition(),
20099
+ new MetaAvatarCommitmentDefinition(),
16833
20100
  new MetaImageCommitmentDefinition(),
16834
20101
  new MetaColorCommitmentDefinition(),
16835
20102
  new MetaFontCommitmentDefinition(),
@@ -16877,7 +20144,6 @@
16877
20144
  new UseMcpCommitmentDefinition(),
16878
20145
  new UsePrivacyCommitmentDefinition(),
16879
20146
  new UseProjectCommitmentDefinition(),
16880
- new UseCommitmentDefinition(),
16881
20147
  // Not yet implemented commitments (using placeholder)
16882
20148
  new NotYetImplementedCommitmentDefinition('EXPECT'),
16883
20149
  new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
@@ -16890,6 +20156,92 @@
16890
20156
  // TODO: [🧠] Maybe create through standardized $register
16891
20157
  // Note: [💞] Ignore a discrepancy between file name and entity name
16892
20158
 
20159
+ /**
20160
+ * Priority order for the important commitments shown first in catalogues and intellisense.
20161
+ *
20162
+ * Canonical singular names stay ahead of their plural aliases so the most important
20163
+ * commitments remain easy to scan.
20164
+ *
20165
+ * @private internal constant of commitment catalog sorting
20166
+ */
20167
+ const IMPORTANT_COMMITMENT_TYPE_SORT_ORDER = new Map([
20168
+ ['GOAL', 0],
20169
+ ['GOALS', 1],
20170
+ ['RULE', 2],
20171
+ ['RULES', 3],
20172
+ ['KNOWLEDGE', 4],
20173
+ ['TEAM', 5],
20174
+ ]);
20175
+ /**
20176
+ * Sort rank used when unfinished, low-level, and deprecated commitments should be grouped last.
20177
+ *
20178
+ * @private internal constant of commitment catalog sorting
20179
+ */
20180
+ const COMMITMENT_STATUS_SORT_ORDER = {
20181
+ normal: 0,
20182
+ deprecated: 1,
20183
+ unfinished: 2,
20184
+ lowLevel: 3,
20185
+ };
20186
+ /**
20187
+ * Resolves the relative sort rank of one commitment status.
20188
+ *
20189
+ * @param definition - Commitment definition to rank.
20190
+ * @param options - Sorting options.
20191
+ * @returns Relative sort rank for the definition.
20192
+ *
20193
+ * @private internal helper of commitment catalog sorting
20194
+ */
20195
+ function resolveCommitmentStatusSortRank(definition, options) {
20196
+ let statusSortRank = COMMITMENT_STATUS_SORT_ORDER.normal;
20197
+ if (options.isDeprecatedLast && definition.deprecation) {
20198
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.deprecated);
20199
+ }
20200
+ if (options.isUnfinishedLast && definition.isUnfinished) {
20201
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.unfinished);
20202
+ }
20203
+ if (options.isLowLevelLast && definition.isLowLevel) {
20204
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.lowLevel);
20205
+ }
20206
+ return statusSortRank;
20207
+ }
20208
+ /**
20209
+ * Sorts commitment definitions so the important ones stay at the top.
20210
+ *
20211
+ * @param commitmentDefinitions - Definitions to sort.
20212
+ * @param options - Sorting options.
20213
+ * @returns Sorted commitment definitions.
20214
+ *
20215
+ * @private internal helper of commitment catalog sorting
20216
+ */
20217
+ function sortCommitmentDefinitions(commitmentDefinitions, options = {}) {
20218
+ return [...commitmentDefinitions]
20219
+ .map((definition, index) => ({
20220
+ definition,
20221
+ index,
20222
+ }))
20223
+ .sort((left, right) => {
20224
+ var _a, _b;
20225
+ if (left.definition.isImportant !== right.definition.isImportant) {
20226
+ return left.definition.isImportant ? -1 : 1;
20227
+ }
20228
+ if (left.definition.isImportant && right.definition.isImportant) {
20229
+ const leftPriority = (_a = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(left.definition.type)) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
20230
+ const rightPriority = (_b = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(right.definition.type)) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER;
20231
+ if (leftPriority !== rightPriority) {
20232
+ return leftPriority - rightPriority;
20233
+ }
20234
+ }
20235
+ const leftStatusSortRank = resolveCommitmentStatusSortRank(left.definition, options);
20236
+ const rightStatusSortRank = resolveCommitmentStatusSortRank(right.definition, options);
20237
+ if (leftStatusSortRank !== rightStatusSortRank) {
20238
+ return leftStatusSortRank - rightStatusSortRank;
20239
+ }
20240
+ return left.index - right.index;
20241
+ })
20242
+ .map(({ definition }) => definition);
20243
+ }
20244
+
16893
20245
  /**
16894
20246
  * Gets all available commitment definitions
16895
20247
  *
@@ -16898,7 +20250,7 @@
16898
20250
  * @public exported from `@promptbook/core`
16899
20251
  */
16900
20252
  function getAllCommitmentDefinitions() {
16901
- return $deepFreeze([...COMMITMENT_REGISTRY]);
20253
+ return $deepFreeze(sortCommitmentDefinitions(COMMITMENT_REGISTRY, { isUnfinishedLast: true, isLowLevelLast: true }));
16902
20254
  }
16903
20255
 
16904
20256
  /**
@@ -17810,6 +21162,7 @@
17810
21162
  * @private internal utility of `parseAgentSource`
17811
21163
  */
17812
21164
  const META_COMMITMENT_APPLIERS = {
21165
+ 'META AVATAR': applyMetaAvatarContent,
17813
21166
  'META LINK': applyMetaLinkContent,
17814
21167
  'META DOMAIN': applyMetaDomainContent,
17815
21168
  'META IMAGE': applyMetaImageContent,
@@ -18173,9 +21526,26 @@
18173
21526
  if (metaTypeRaw === 'LINK') {
18174
21527
  state.links.push(metaValue);
18175
21528
  }
21529
+ if (metaTypeRaw.toUpperCase() === 'AVATAR') {
21530
+ applyMetaAvatarContent(state, metaValue);
21531
+ return;
21532
+ }
18176
21533
  const metaType = normalizeTo_camelCase(metaTypeRaw);
18177
21534
  state.meta[metaType] = metaValue;
18178
21535
  }
21536
+ /**
21537
+ * Applies META AVATAR content into the canonical `meta.avatar` field.
21538
+ *
21539
+ * @private internal utility of `parseAgentSource`
21540
+ */
21541
+ function applyMetaAvatarContent(state, content) {
21542
+ const avatarVisualId = resolveAvatarVisualId(content);
21543
+ if (avatarVisualId) {
21544
+ state.meta.avatar = avatarVisualId;
21545
+ return;
21546
+ }
21547
+ delete state.meta.avatar;
21548
+ }
18179
21549
  /**
18180
21550
  * Applies META LINK content into links and the canonical `meta.link` field.
18181
21551
  *
@@ -18899,7 +22269,7 @@
18899
22269
  lastPreparationIndex = index;
18900
22270
  }
18901
22271
  else {
18902
- // Remove earlier duplicate — keep only the last (most recent) one.
22272
+ // Remove earlier duplicate - keep only the last (most recent) one.
18903
22273
  toolCalls.splice(index, 1);
18904
22274
  }
18905
22275
  }
@@ -24523,7 +27893,7 @@
24523
27893
  // Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
24524
27894
 
24525
27895
  /**
24526
- * Change dash-like characters to regular dashes `—` -> `-` and remove soft hyphens
27896
+ * Change dash-like characters to regular dashes `-` -> `-` and remove soft hyphens
24527
27897
  *
24528
27898
  * Note: [🔂] This function is idempotent.
24529
27899
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
@@ -24531,7 +27901,7 @@
24531
27901
  * @public exported from `@promptbook/markdown-utils`
24532
27902
  */
24533
27903
  function humanizeAiTextEmdashed(aiText) {
24534
- return aiText.replace(/\u00AD/g, '').replace(/[â€â€‘â€’â€“â€”â€•âˆ’âƒīšŖīŧ]/g, '-');
27904
+ return aiText.replace(/\u00AD/g, '').replace(/[‐‑‒–-â€•âˆ’âƒīšŖīŧ]/g, '-');
24535
27905
  }
24536
27906
  // Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
24537
27907
 
@@ -31244,6 +34614,7 @@
31244
34614
  const isMetaImageExplicit = profile.isMetaImageExplicit !== false;
31245
34615
  const metaLines = [
31246
34616
  formatMetaLine('FULLNAME', meta === null || meta === void 0 ? void 0 : meta.fullname),
34617
+ formatMetaLine('AVATAR', meta === null || meta === void 0 ? void 0 : meta.avatar),
31247
34618
  formatMetaLine('IMAGE', isMetaImageExplicit ? meta === null || meta === void 0 ? void 0 : meta.image : undefined),
31248
34619
  formatMetaLine('DESCRIPTION', meta === null || meta === void 0 ? void 0 : meta.description),
31249
34620
  formatMetaLine('COLOR', meta === null || meta === void 0 ? void 0 : meta.color),
@@ -31284,7 +34655,7 @@
31284
34655
  var _a, _b, _c;
31285
34656
  const agentProfileUrl = `${options.agentUrl}/api/profile`;
31286
34657
  const profileResponse = await fetch(agentProfileUrl, {
31287
- headers: attachClientVersionHeader(),
34658
+ headers: attachClientVersionHeader(options.requestHeaders),
31288
34659
  });
31289
34660
  // <- TODO: [🐱‍🚀] What about closed-source agents?
31290
34661
  // <- TODO: [🐱‍🚀] Maybe use promptbookFetch
@@ -31364,6 +34735,7 @@
31364
34735
  this.avatarVisualId = undefined;
31365
34736
  this.knowledgeSources = [];
31366
34737
  this.agentUrl = options.agentUrl;
34738
+ this.requestHeaders = options.requestHeaders || {};
31367
34739
  }
31368
34740
  get agentName() {
31369
34741
  return this._remoteAgentName || super.agentName;
@@ -31400,7 +34772,7 @@
31400
34772
  }
31401
34773
  const response = await fetch(`${this.agentUrl}/api/voice`, {
31402
34774
  method: 'POST',
31403
- headers: attachClientVersionHeader(),
34775
+ headers: attachClientVersionHeader(this.requestHeaders),
31404
34776
  body: formData,
31405
34777
  });
31406
34778
  if (!response.ok) {
@@ -31431,6 +34803,7 @@
31431
34803
  const bookResponse = await fetch(`${this.agentUrl}/api/chat`, {
31432
34804
  method: 'POST',
31433
34805
  headers: attachClientVersionHeader({
34806
+ ...this.requestHeaders,
31434
34807
  'Content-Type': 'application/json',
31435
34808
  }),
31436
34809
  body: JSON.stringify({