@promptbook/node 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 +3577 -204
  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 +3577 -204
  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/esm/index.es.js CHANGED
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
35
35
  * @generated
36
36
  * @see https://github.com/webgptorg/promptbook
37
37
  */
38
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-53';
38
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-56';
39
39
  /**
40
40
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
41
41
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -14386,6 +14386,24 @@ class BaseCommitmentDefinition {
14386
14386
  get requiresContent() {
14387
14387
  return true;
14388
14388
  }
14389
+ /**
14390
+ * Whether this commitment should be prioritized in menus, documentation, and intellisense.
14391
+ */
14392
+ get isImportant() {
14393
+ return false;
14394
+ }
14395
+ /**
14396
+ * Whether this commitment is unfinished and not ready to use.
14397
+ */
14398
+ get isUnfinished() {
14399
+ return false;
14400
+ }
14401
+ /**
14402
+ * Whether this commitment is low-level and should be surfaced with caution.
14403
+ */
14404
+ get isLowLevel() {
14405
+ return false;
14406
+ }
14389
14407
  /**
14390
14408
  * Optional UI/docs-only deprecation metadata.
14391
14409
  */
@@ -14502,8 +14520,8 @@ class BaseCommitmentDefinition {
14502
14520
  /**
14503
14521
  * ACTION commitment definition
14504
14522
  *
14505
- * The ACTION commitment defines specific actions or capabilities that the agent can perform.
14506
- * This helps define what the agent is capable of doing and how it should approach tasks.
14523
+ * Deprecated legacy commitment for broad capability notes.
14524
+ * New books should prefer the appropriate `USE*` commitment instead.
14507
14525
  *
14508
14526
  * Example usage in agent source:
14509
14527
  *
@@ -14522,7 +14540,15 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
14522
14540
  * Short one-line description of ACTION.
14523
14541
  */
14524
14542
  get description() {
14525
- return 'Define agent capabilities and actions it can perform.';
14543
+ return 'Deprecated legacy capability commitment. Prefer concrete `USE*` commitments.';
14544
+ }
14545
+ /**
14546
+ * Optional UI/docs-only deprecation metadata.
14547
+ */
14548
+ get deprecation() {
14549
+ return {
14550
+ message: 'Use a concrete `USE*` commitment instead.',
14551
+ };
14526
14552
  }
14527
14553
  /**
14528
14554
  * Icon for this commitment.
@@ -14537,33 +14563,43 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
14537
14563
  return spaceTrim$1(`
14538
14564
  # ${this.type}
14539
14565
 
14540
- Defines specific actions or capabilities that the agent can perform.
14566
+ Deprecated legacy commitment for broad capability notes.
14541
14567
 
14542
- ## Key aspects
14568
+ ## Migration
14543
14569
 
14544
- - Both terms work identically and can be used interchangeably.
14545
- - Each action adds to the agent's capability list.
14546
- - Actions help users understand what the agent can do.
14570
+ - Existing \`${this.type}\` and \`ACTIONS\` books still parse and compile.
14571
+ - New books should prefer the appropriate \`USE*\` commitment instead.
14572
+ - Keep \`${this.type}\` only when maintaining older books that already rely on it.
14547
14573
 
14548
- ## Examples
14574
+ ## Preferred replacement
14549
14575
 
14550
14576
  \`\`\`book
14551
- Code Assistant
14577
+ Research Assistant
14552
14578
 
14553
- PERSONA You are a programming assistant
14554
- ACTION Can generate code snippets and explain programming concepts
14555
- ACTION Able to debug existing code and suggest improvements
14556
- ACTION Can create unit tests for functions
14579
+ PERSONA You are a helpful research assistant
14580
+ USE SEARCH ENGINE
14581
+ RULE Always cite your sources when providing information from the web
14582
+ \`\`\`
14583
+
14584
+ ## Legacy compatibility example
14585
+
14586
+ \`\`\`book
14587
+ Research Assistant
14588
+
14589
+ PERSONA You are a helpful research assistant
14590
+ ACTION Can search for current information and summarize findings
14591
+ RULE Always cite your sources when providing information from the web
14557
14592
  \`\`\`
14558
14593
 
14594
+ ## Legacy compatibility example with additional tools
14595
+
14559
14596
  \`\`\`book
14560
- Data Scientist
14597
+ Code Assistant
14561
14598
 
14562
- PERSONA You are a data analysis expert
14563
- ACTION Able to analyze data and provide insights
14564
- ACTION Can create visualizations and charts
14565
- ACTION Capable of statistical analysis and modeling
14566
- KNOWLEDGE Data analysis best practices and statistical methods
14599
+ PERSONA You are a programming assistant
14600
+ USE BROWSER
14601
+ USE SEARCH ENGINE
14602
+ RULE Prefer the narrowest useful capability for the task.
14567
14603
  \`\`\`
14568
14604
  `);
14569
14605
  }
@@ -14572,7 +14608,7 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
14572
14608
  if (!trimmedContent) {
14573
14609
  return requirements;
14574
14610
  }
14575
- // Add action capability to the system message
14611
+ // Keep the legacy capability note for backward compatibility.
14576
14612
  const actionSection = `Capability: ${trimmedContent}`;
14577
14613
  return this.appendToSystemMessage(requirements, actionSection, '\n\n');
14578
14614
  }
@@ -14707,9 +14743,9 @@ class ComponentCommitmentDefinition extends BaseCommitmentDefinition {
14707
14743
  /**
14708
14744
  * DELETE commitment definition
14709
14745
  *
14710
- * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is used to
14711
- * remove or disregard certain information or context. This can be useful for
14712
- * overriding previous commitments or removing unwanted behaviors.
14746
+ * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is a low-level
14747
+ * unfinished commitment used to remove or disregard certain information or context.
14748
+ * It is intentionally surfaced with caution because it is not ready for broad use yet.
14713
14749
  *
14714
14750
  * Example usage in agent source:
14715
14751
  *
@@ -14730,7 +14766,13 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
14730
14766
  * Short one-line description of DELETE/CANCEL/DISCARD/REMOVE.
14731
14767
  */
14732
14768
  get description() {
14733
- return 'Remove or **disregard** certain information, context, or previous commitments.';
14769
+ return 'Unfinished low-level commitment for removing or disregarding information. Use carefully.';
14770
+ }
14771
+ /**
14772
+ * Marks DELETE as unfinished and not ready to use.
14773
+ */
14774
+ get isUnfinished() {
14775
+ return true;
14734
14776
  }
14735
14777
  /**
14736
14778
  * Icon for this commitment.
@@ -14745,7 +14787,13 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
14745
14787
  return spaceTrim$1(`
14746
14788
  # DELETE (CANCEL, DISCARD, REMOVE)
14747
14789
 
14748
- A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
14790
+ 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.
14791
+
14792
+ ## Status
14793
+
14794
+ - This commitment is unfinished and not ready to use yet.
14795
+ - Treat it as a low-level prompt-surgery tool rather than a general-purpose commitment.
14796
+ - Prefer higher-level commitments when a clearer dedicated commitment exists.
14749
14797
 
14750
14798
  ## Aliases
14751
14799
 
@@ -14760,6 +14808,7 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
14760
14808
  - Useful for overriding previous commitments in the same agent definition.
14761
14809
  - Can be used to remove inherited behaviors from base personas.
14762
14810
  - Helps fine-tune agent behavior by explicitly removing unwanted elements.
14811
+ - Because this commitment is unfinished, keep an eye on future changes before relying on it in production books.
14763
14812
 
14764
14813
  ## Use cases
14765
14814
 
@@ -14767,6 +14816,7 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
14767
14816
  - Removing conflicting or outdated instructions
14768
14817
  - Disabling specific response patterns
14769
14818
  - Canceling previous formatting or style requirements
14819
+ - Experimenting with low-level prompt rewrites when you know exactly what needs to be removed
14770
14820
 
14771
14821
  ## Examples
14772
14822
 
@@ -14933,11 +14983,10 @@ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
14933
14983
  /**
14934
14984
  * FORMAT commitment definition
14935
14985
  *
14936
- * The FORMAT commitment defines the specific output structure and formatting
14937
- * that the agent should use in its responses. This includes data formats,
14938
- * response templates, and structural requirements.
14986
+ * Deprecated legacy commitment for output formatting and response structure.
14987
+ * New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
14939
14988
  *
14940
- * Example usage in agent source:
14989
+ * Legacy example usage in agent source:
14941
14990
  *
14942
14991
  * ```book
14943
14992
  * FORMAT Always respond in JSON format with 'status' and 'data' fields
@@ -14954,7 +15003,16 @@ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
14954
15003
  * Short one-line description of FORMAT.
14955
15004
  */
14956
15005
  get description() {
14957
- return 'Specify output structure or formatting requirements.';
15006
+ return 'Deprecated legacy formatting commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
15007
+ }
15008
+ /**
15009
+ * Optional UI/docs-only deprecation metadata.
15010
+ */
15011
+ get deprecation() {
15012
+ return {
15013
+ message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
15014
+ replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
15015
+ };
14958
15016
  }
14959
15017
  /**
14960
15018
  * Icon for this commitment.
@@ -14969,31 +15027,39 @@ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
14969
15027
  return spaceTrim$1(`
14970
15028
  # ${this.type}
14971
15029
 
14972
- Defines the specific output structure and formatting for responses (data formats, templates, structure).
15030
+ Deprecated legacy commitment for output formatting and response structure.
14973
15031
 
14974
- ## Key aspects
15032
+ ## Migration
14975
15033
 
14976
- - Both terms work identically and can be used interchangeably.
14977
- - If they are in conflict, the last one takes precedence.
14978
- - You can specify both data formats and presentation styles.
15034
+ - Existing \`${this.type}\` and \`FORMATS\` books still parse and compile.
15035
+ - New books should use \`WRITING RULES\` for formatting or structure constraints and \`WRITING SAMPLE\` when a concrete example communicates the target shape better.
15036
+ - Runtime behavior is intentionally unchanged for backward compatibility.
14979
15037
 
14980
- ## Examples
15038
+ ## Preferred replacement
14981
15039
 
14982
15040
  \`\`\`book
14983
- Customer Support Bot
15041
+ Data Analyst
14984
15042
 
14985
- PERSONA You are a helpful customer support agent
14986
- FORMAT Always respond in JSON format with 'status' and 'data' fields
14987
- FORMAT Use markdown formatting for all code blocks
15043
+ GOAL Present results in a clean, readable structure.
15044
+ WRITING RULES Use markdown headings for sections and bullet points for lists.
15045
+ WRITING RULES Keep tables narrow and readable.
15046
+ WRITING SAMPLE
15047
+ Summary
15048
+ - ...
15049
+ Details
15050
+ - ...
15051
+ Next steps
15052
+ - ...
14988
15053
  \`\`\`
14989
15054
 
15055
+ ## Legacy compatibility example
15056
+
14990
15057
  \`\`\`book
14991
15058
  Data Analyst
14992
15059
 
14993
- PERSONA You are a data analysis expert
15060
+ GOAL Present results in a clean structure.
14994
15061
  FORMAT Present results in structured tables
14995
15062
  FORMAT Include confidence scores for all predictions
14996
- WRITING RULES Be concise and precise in explanations
14997
15063
  \`\`\`
14998
15064
  `);
14999
15065
  }
@@ -15344,6 +15410,12 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
15344
15410
  get description() {
15345
15411
  return 'Define the effective agent **goal**; when multiple goals exist, only the last one stays effective.';
15346
15412
  }
15413
+ /**
15414
+ * Marks GOAL as one of the priority commitments surfaced first in catalogues.
15415
+ */
15416
+ get isImportant() {
15417
+ return true;
15418
+ }
15347
15419
  /**
15348
15420
  * Icon for this commitment.
15349
15421
  */
@@ -15755,6 +15827,12 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
15755
15827
  get description() {
15756
15828
  return 'Add domain **knowledge** via direct text or external sources (RAG).';
15757
15829
  }
15830
+ /**
15831
+ * Marks KNOWLEDGE as one of the priority commitments surfaced first in catalogues.
15832
+ */
15833
+ get isImportant() {
15834
+ return true;
15835
+ }
15758
15836
  /**
15759
15837
  * Icon for this commitment.
15760
15838
  */
@@ -17042,6 +17120,7 @@ class MessageSuffixCommitmentDefinition extends BaseCommitmentDefinition {
17042
17120
  * META commitment definition
17043
17121
  *
17044
17122
  * The META commitment handles all meta-information about the agent such as:
17123
+ * - META AVATAR: Sets the agent's built-in default avatar visual
17045
17124
  * - META IMAGE: Sets the agent's avatar/profile image URL
17046
17125
  * - META LINK: Provides profile/source links for the person the agent models
17047
17126
  * - META DOMAIN: Sets the canonical custom domain/host of the agent
@@ -17056,6 +17135,7 @@ class MessageSuffixCommitmentDefinition extends BaseCommitmentDefinition {
17056
17135
  * Example usage in agent source:
17057
17136
  *
17058
17137
  * ```book
17138
+ * META AVATAR pixel-art
17059
17139
  * META IMAGE https://example.com/avatar.jpg
17060
17140
  * META LINK https://twitter.com/username
17061
17141
  * META DOMAIN my-agent.com
@@ -17095,6 +17175,7 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
17095
17175
 
17096
17176
  ## Supported META types
17097
17177
 
17178
+ - **META AVATAR** - Sets the agent's built-in default avatar visual
17098
17179
  - **META IMAGE** - Sets the agent's avatar/profile image URL
17099
17180
  - **META LINK** - Provides profile/source links for the person the agent models
17100
17181
  - **META DOMAIN** - Sets the canonical custom domain/host of the agent
@@ -17118,6 +17199,7 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
17118
17199
  \`\`\`book
17119
17200
  Professional Assistant
17120
17201
 
17202
+ META AVATAR octopus3
17121
17203
  META IMAGE https://example.com/professional-avatar.jpg
17122
17204
  META TITLE Senior Business Consultant
17123
17205
  META DESCRIPTION Specialized in strategic planning and project management
@@ -17179,12 +17261,3236 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
17179
17261
  * Checks if this is a known meta type
17180
17262
  */
17181
17263
  isKnownMetaType(metaType) {
17182
- const knownTypes = ['IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
17264
+ const knownTypes = ['AVATAR', 'IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
17183
17265
  return knownTypes.includes(metaType.toUpperCase());
17184
17266
  }
17185
17267
  }
17186
17268
  // Note: [💞] Ignore a discrepancy between file name and entity name
17187
17269
 
17270
+ /**
17271
+ * Makes color transformer which darker the given color
17272
+ *
17273
+ * @param amount from 0 to 1
17274
+ *
17275
+ * @public exported from `@promptbook/color`
17276
+ */
17277
+ function darken(amount) {
17278
+ return lighten(-amount);
17279
+ }
17280
+
17281
+ /* eslint-disable no-magic-numbers */
17282
+ /**
17283
+ * Corner radius ratio used for the common rounded card frame.
17284
+ *
17285
+ * @private utility of the avatar rendering system
17286
+ */
17287
+ const FRAME_RADIUS_RATIO = 0.18;
17288
+ /**
17289
+ * Draws the common rounded background frame used by most visuals.
17290
+ *
17291
+ * @param context Canvas 2D context.
17292
+ * @param size Canvas size in CSS pixels.
17293
+ * @param palette Derived avatar palette.
17294
+ *
17295
+ * @private utility of the avatar rendering system
17296
+ */
17297
+ function drawAvatarFrame(context, size, palette) {
17298
+ if (palette.background === 'transparent' && palette.backgroundSecondary === 'transparent') {
17299
+ return;
17300
+ }
17301
+ const gradient = context.createLinearGradient(0, 0, size, size);
17302
+ gradient.addColorStop(0, palette.background);
17303
+ gradient.addColorStop(1, palette.backgroundSecondary);
17304
+ context.save();
17305
+ createRoundedRectPath(context, 0, 0, size, size, size * FRAME_RADIUS_RATIO);
17306
+ context.fillStyle = gradient;
17307
+ context.fill();
17308
+ context.restore();
17309
+ context.save();
17310
+ context.strokeStyle = 'rgba(255,255,255,0.12)';
17311
+ context.lineWidth = Math.max(1.5, size * 0.012);
17312
+ createRoundedRectPath(context, size * 0.02, size * 0.02, size * 0.96, size * 0.96, size * 0.15);
17313
+ context.stroke();
17314
+ context.restore();
17315
+ }
17316
+ /**
17317
+ * Creates a rounded rectangle path on the current canvas context.
17318
+ *
17319
+ * @param context Canvas 2D context.
17320
+ * @param x Left coordinate.
17321
+ * @param y Top coordinate.
17322
+ * @param width Rectangle width.
17323
+ * @param height Rectangle height.
17324
+ * @param radius Corner radius.
17325
+ *
17326
+ * @private utility of the avatar rendering system
17327
+ */
17328
+ function createRoundedRectPath(context, x, y, width, height, radius) {
17329
+ const normalizedRadius = Math.min(radius, width / 2, height / 2);
17330
+ context.beginPath();
17331
+ context.moveTo(x + normalizedRadius, y);
17332
+ context.arcTo(x + width, y, x + width, y + height, normalizedRadius);
17333
+ context.arcTo(x + width, y + height, x, y + height, normalizedRadius);
17334
+ context.arcTo(x, y + height, x, y, normalizedRadius);
17335
+ context.arcTo(x, y, x + width, y, normalizedRadius);
17336
+ context.closePath();
17337
+ }
17338
+ /**
17339
+ * Picks one deterministic element from a non-empty collection.
17340
+ *
17341
+ * @param items Candidate items.
17342
+ * @param random Seeded random generator.
17343
+ * @returns Picked item.
17344
+ *
17345
+ * @private utility of the avatar rendering system
17346
+ */
17347
+ function pickRandomItem(items, random) {
17348
+ return items[Math.floor(random() * items.length)];
17349
+ }
17350
+
17351
+ /* eslint-disable no-magic-numbers */
17352
+ /**
17353
+ * Builds a smoothly morphing octopus-like silhouette from deterministic parameters.
17354
+ *
17355
+ * @param options Shape construction options.
17356
+ * @returns Closed-loop body points.
17357
+ *
17358
+ * @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
17359
+ */
17360
+ function createOrganicOctopusBodyPoints(options) {
17361
+ const { centerX, centerY, bodyRadius, horizontalStretch, verticalStretch, mantleLift, lowerDrop, tentacleDepth, wobbleAmplitude, lobeCount, shapePhase, timeMs, pointCount = 36, } = options;
17362
+ return Array.from({ length: pointCount }, (_, pointIndex) => {
17363
+ const progress = pointIndex / pointCount;
17364
+ const angle = -Math.PI / 2 + progress * Math.PI * 2;
17365
+ const cosine = Math.cos(angle);
17366
+ const sine = Math.sin(angle);
17367
+ const upperFactor = Math.max(0, -sine);
17368
+ const lowerFactor = Math.max(0, sine);
17369
+ const lobeEnvelope = Math.pow(lowerFactor, 1.35);
17370
+ const tentacleWave = Math.max(0, Math.cos(angle * lobeCount + shapePhase + timeMs / 780)) * tentacleDepth * lobeEnvelope;
17371
+ const surfaceWave = Math.sin(angle * 3 + shapePhase + timeMs / 1200) * 0.62 +
17372
+ Math.sin(angle * 5 - shapePhase * 0.7 - timeMs / 910) * 0.38;
17373
+ const breathingWave = Math.sin(timeMs / 960 + shapePhase + angle * 0.45) * wobbleAmplitude;
17374
+ const radius = bodyRadius * (1 + upperFactor * 0.12 + lowerFactor * 0.08 + surfaceWave * 0.05) +
17375
+ tentacleWave +
17376
+ breathingWave;
17377
+ return {
17378
+ x: centerX +
17379
+ cosine * radius * horizontalStretch +
17380
+ Math.sin(angle * 2 + shapePhase) * lobeEnvelope * wobbleAmplitude * 0.7,
17381
+ y: centerY +
17382
+ sine * radius * verticalStretch -
17383
+ upperFactor * mantleLift +
17384
+ lowerFactor * lowerDrop +
17385
+ tentacleWave * 0.28,
17386
+ };
17387
+ });
17388
+ }
17389
+ /**
17390
+ * Traces a smooth closed path through the provided points.
17391
+ *
17392
+ * @param context Canvas 2D context.
17393
+ * @param points Closed-loop points.
17394
+ *
17395
+ * @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
17396
+ */
17397
+ function traceSmoothClosedPath(context, points) {
17398
+ const lastPoint = points[points.length - 1];
17399
+ const firstPoint = points[0];
17400
+ const initialMidpoint = {
17401
+ x: (lastPoint.x + firstPoint.x) / 2,
17402
+ y: (lastPoint.y + firstPoint.y) / 2,
17403
+ };
17404
+ context.beginPath();
17405
+ context.moveTo(initialMidpoint.x, initialMidpoint.y);
17406
+ for (let pointIndex = 0; pointIndex < points.length; pointIndex++) {
17407
+ const point = points[pointIndex];
17408
+ const nextPoint = points[(pointIndex + 1) % points.length];
17409
+ const midpoint = {
17410
+ x: (point.x + nextPoint.x) / 2,
17411
+ y: (point.y + nextPoint.y) / 2,
17412
+ };
17413
+ context.quadraticCurveTo(point.x, point.y, midpoint.x, midpoint.y);
17414
+ }
17415
+ context.closePath();
17416
+ }
17417
+ /**
17418
+ * Creates deterministic ribbon tentacles for the organic octopus visuals.
17419
+ *
17420
+ * @param options Tentacle construction options.
17421
+ * @returns Tentacle descriptors.
17422
+ *
17423
+ * @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
17424
+ */
17425
+ function createOrganicOctopusTentacleShapes(options) {
17426
+ var _a, _b, _c, _d, _e, _f, _g, _h;
17427
+ const { size, centerX, centerY, bodyRadius, horizontalStretch, tentacleCount, shapePhase, createRandom, timeMs, saltPrefix, bodyPoints, variation, } = options;
17428
+ const baseY = centerY + bodyRadius * 0.74;
17429
+ const lowerBodyAnchorPoints = bodyPoints
17430
+ ? resolveTentacleBodyAnchorPoints(bodyPoints, centerY + bodyRadius * 0.04)
17431
+ : null;
17432
+ const flowLengthScale = (_a = variation === null || variation === void 0 ? void 0 : variation.flowLengthScale) !== null && _a !== void 0 ? _a : 1;
17433
+ const lateralReachScale = (_b = variation === null || variation === void 0 ? void 0 : variation.lateralReachScale) !== null && _b !== void 0 ? _b : 1;
17434
+ const tipReachScale = (_c = variation === null || variation === void 0 ? void 0 : variation.tipReachScale) !== null && _c !== void 0 ? _c : 1;
17435
+ const baseWidthScale = (_d = variation === null || variation === void 0 ? void 0 : variation.baseWidthScale) !== null && _d !== void 0 ? _d : 1;
17436
+ const tipWidthScale = (_e = variation === null || variation === void 0 ? void 0 : variation.tipWidthScale) !== null && _e !== void 0 ? _e : 1;
17437
+ const rootSpreadScale = (_f = variation === null || variation === void 0 ? void 0 : variation.rootSpreadScale) !== null && _f !== void 0 ? _f : 1;
17438
+ const startYOffsetScale = (_g = variation === null || variation === void 0 ? void 0 : variation.startYOffsetScale) !== null && _g !== void 0 ? _g : 1;
17439
+ const swayScale = (_h = variation === null || variation === void 0 ? void 0 : variation.swayScale) !== null && _h !== void 0 ? _h : 1;
17440
+ return Array.from({ length: tentacleCount }, (_, tentacleIndex) => {
17441
+ const tentacleRandom = createRandom(`${saltPrefix}-tentacle-${tentacleIndex}`);
17442
+ const spreadProgress = tentacleCount === 1 ? 0.5 : tentacleIndex / (tentacleCount - 1);
17443
+ const centeredProgress = spreadProgress - 0.5;
17444
+ const spreadCenteredProgress = centeredProgress * rootSpreadScale;
17445
+ const spreadAnchorProgress = Math.min(1, Math.max(0, 0.5 + spreadCenteredProgress));
17446
+ const temporalSway = Math.sin(timeMs / (720 + tentacleIndex * 34) + shapePhase + tentacleRandom() * Math.PI * 2) *
17447
+ size *
17448
+ (0.014 + tentacleRandom() * 0.015) *
17449
+ swayScale;
17450
+ const flowLength = size * (0.24 + tentacleRandom() * 0.18) * flowLengthScale;
17451
+ const curlDirection = spreadCenteredProgress === 0 ? (tentacleRandom() < 0.5 ? -1 : 1) : Math.sign(spreadCenteredProgress);
17452
+ const lateralReach = spreadCenteredProgress * size * (0.1 + tentacleRandom() * 0.1) * lateralReachScale + temporalSway;
17453
+ const tipReach = curlDirection * size * (0.025 + tentacleRandom() * 0.07) * tipReachScale;
17454
+ const startYOffset = (Math.abs(spreadCenteredProgress) * size * 0.012 + tentacleRandom() * size * 0.01) * startYOffsetScale;
17455
+ const startPoint = lowerBodyAnchorPoints && lowerBodyAnchorPoints.length >= 2
17456
+ ? createInsetTentacleStartPoint({
17457
+ bodyPoints: lowerBodyAnchorPoints,
17458
+ anchorProgress: spreadAnchorProgress,
17459
+ centerX,
17460
+ centerY,
17461
+ bodyRadius,
17462
+ centeredProgress: spreadCenteredProgress,
17463
+ startYOffset,
17464
+ })
17465
+ : {
17466
+ x: centerX + spreadCenteredProgress * bodyRadius * horizontalStretch * 1.52,
17467
+ y: baseY + startYOffset,
17468
+ };
17469
+ const controlPointOne = {
17470
+ x: startPoint.x + spreadCenteredProgress * size * 0.045 * lateralReachScale + temporalSway * 0.4,
17471
+ y: startPoint.y + flowLength * (0.21 + tentacleRandom() * 0.08),
17472
+ };
17473
+ const controlPointTwo = {
17474
+ x: startPoint.x + lateralReach + tipReach,
17475
+ y: startPoint.y + flowLength * (0.62 + tentacleRandom() * 0.12),
17476
+ };
17477
+ const endPoint = {
17478
+ x: startPoint.x + lateralReach + tipReach * 1.2,
17479
+ y: startPoint.y +
17480
+ flowLength * (0.9 + tentacleRandom() * 0.12) +
17481
+ Math.cos(timeMs / (840 + tentacleIndex * 41) + shapePhase) * size * (0.008 + tentacleRandom() * 0.01),
17482
+ };
17483
+ const baseWidth = size * (0.038 + tentacleRandom() * 0.02) * (1 - Math.abs(spreadCenteredProgress) * 0.18) * baseWidthScale;
17484
+ const tipWidth = baseWidth * Math.min(0.52, (0.18 + tentacleRandom() * 0.2) * tipWidthScale);
17485
+ return {
17486
+ startPoint,
17487
+ controlPointOne,
17488
+ controlPointTwo,
17489
+ endPoint,
17490
+ baseWidth,
17491
+ tipWidth,
17492
+ colorBias: tentacleRandom(),
17493
+ highlightBias: tentacleRandom(),
17494
+ sampleCount: 14 + Math.floor(tentacleRandom() * 6),
17495
+ };
17496
+ });
17497
+ }
17498
+ /**
17499
+ * Narrows the body contour to lower anchor points that can safely host tentacle roots.
17500
+ *
17501
+ * @param bodyPoints Generated closed-loop body points.
17502
+ * @param lowerBodyThresholdY Minimum Y coordinate considered part of the lower mantle.
17503
+ * @returns Body points sorted from left to right across the lower silhouette.
17504
+ *
17505
+ * @private shared geometry helper of `octopus3AvatarVisual`
17506
+ */
17507
+ function resolveTentacleBodyAnchorPoints(bodyPoints, lowerBodyThresholdY) {
17508
+ const lowerBodyPoints = bodyPoints
17509
+ .filter((bodyPoint) => bodyPoint.y >= lowerBodyThresholdY)
17510
+ .sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
17511
+ if (lowerBodyPoints.length >= 2) {
17512
+ return lowerBodyPoints;
17513
+ }
17514
+ return [...bodyPoints].sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
17515
+ }
17516
+ /**
17517
+ * Resolves one tentacle root from the provided lower body contour and nudges it inside the mantle.
17518
+ *
17519
+ * @param options Tentacle anchor options.
17520
+ * @returns Tentacle start point safely embedded inside the body silhouette.
17521
+ *
17522
+ * @private shared geometry helper of `octopus3AvatarVisual`
17523
+ */
17524
+ function createInsetTentacleStartPoint(options) {
17525
+ const { bodyPoints, anchorProgress, centerX, centerY, bodyRadius, centeredProgress, startYOffset } = options;
17526
+ const clampedAnchorProgress = Math.min(0.94, Math.max(0.06, anchorProgress));
17527
+ const bodyAnchorPoint = interpolatePointAlongTentacleAnchors(bodyPoints, clampedAnchorProgress);
17528
+ const inwardX = centerX - bodyAnchorPoint.x;
17529
+ const inwardY = centerY + bodyRadius * 0.08 - bodyAnchorPoint.y;
17530
+ const inwardLength = Math.hypot(inwardX, inwardY) || 1;
17531
+ const insetDistance = bodyRadius * (0.12 + Math.abs(centeredProgress) * 0.05) + startYOffset * 0.32;
17532
+ return {
17533
+ x: bodyAnchorPoint.x + (inwardX / inwardLength) * insetDistance,
17534
+ y: bodyAnchorPoint.y + (inwardY / inwardLength) * insetDistance,
17535
+ };
17536
+ }
17537
+ /**
17538
+ * Interpolates one left-to-right anchor point along the prepared lower body contour.
17539
+ *
17540
+ * @param bodyPoints Lower body contour points sorted from left to right.
17541
+ * @param progress Interpolation progress in the range `[0, 1]`.
17542
+ * @returns Interpolated anchor point.
17543
+ *
17544
+ * @private shared geometry helper of `octopus3AvatarVisual`
17545
+ */
17546
+ function interpolatePointAlongTentacleAnchors(bodyPoints, progress) {
17547
+ if (bodyPoints.length === 1) {
17548
+ return bodyPoints[0];
17549
+ }
17550
+ const anchorIndex = progress * (bodyPoints.length - 1);
17551
+ const startIndex = Math.floor(anchorIndex);
17552
+ const endIndex = Math.min(bodyPoints.length - 1, startIndex + 1);
17553
+ const blend = anchorIndex - startIndex;
17554
+ const startPoint = bodyPoints[startIndex];
17555
+ const endPoint = bodyPoints[endIndex];
17556
+ return {
17557
+ x: startPoint.x + (endPoint.x - startPoint.x) * blend,
17558
+ y: startPoint.y + (endPoint.y - startPoint.y) * blend,
17559
+ };
17560
+ }
17561
+ /**
17562
+ * Samples the cubic tentacle centerline and offsets normals to build a filled ribbon.
17563
+ *
17564
+ * @param tentacleShape Deterministic tentacle descriptor.
17565
+ * @returns Sampled ribbon points.
17566
+ *
17567
+ * @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
17568
+ */
17569
+ function sampleOrganicTentacleRibbonPoints(tentacleShape) {
17570
+ return Array.from({ length: tentacleShape.sampleCount + 1 }, (_, sampleIndex) => {
17571
+ const progress = sampleIndex / tentacleShape.sampleCount;
17572
+ const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
17573
+ const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.04));
17574
+ const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.04));
17575
+ const tangentX = nextPoint.x - previousPoint.x;
17576
+ const tangentY = nextPoint.y - previousPoint.y;
17577
+ const tangentLength = Math.hypot(tangentX, tangentY) || 1;
17578
+ const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
17579
+ return {
17580
+ x: point.x,
17581
+ y: point.y,
17582
+ normalX: -tangentY / tangentLength,
17583
+ normalY: tangentX / tangentLength,
17584
+ width,
17585
+ progress,
17586
+ };
17587
+ });
17588
+ }
17589
+ /**
17590
+ * Resolves smooth pupil offsets that blend autonomous idle drift with live viewer tracking.
17591
+ *
17592
+ * @param options Eye motion options.
17593
+ * @returns Resolved pupil offsets.
17594
+ *
17595
+ * @private shared geometry helper of octopus avatar visuals
17596
+ */
17597
+ function resolveOrganicEyeMotion(options) {
17598
+ const { radiusX, radiusY, timeMs, phase, interaction, autonomousDriftRatioX = 0.12, autonomousDriftRatioY = 0.08, } = options;
17599
+ const autonomousOffsetX = Math.sin(timeMs / 1280 + phase) * radiusX * autonomousDriftRatioX;
17600
+ const autonomousOffsetY = Math.cos(timeMs / 940 + phase) * radiusY * autonomousDriftRatioY;
17601
+ const interactionBlend = Math.min(1, interaction.intensity * 0.9);
17602
+ return {
17603
+ pupilOffsetX: autonomousOffsetX * (1 - interactionBlend) + interaction.gazeX * radiusX * (0.18 + interactionBlend * 0.18),
17604
+ pupilOffsetY: autonomousOffsetY * (1 - interactionBlend) + interaction.gazeY * radiusY * (0.16 + interactionBlend * 0.16),
17605
+ };
17606
+ }
17607
+ /**
17608
+ * Samples one point on a cubic Bezier curve.
17609
+ *
17610
+ * @param startPoint Curve start point.
17611
+ * @param controlPointOne First control point.
17612
+ * @param controlPointTwo Second control point.
17613
+ * @param endPoint Curve end point.
17614
+ * @param progress Sampling progress in the range `[0, 1]`.
17615
+ * @returns Sampled point.
17616
+ *
17617
+ * @private shared geometry helper of `octopus3AvatarVisual`
17618
+ */
17619
+ function getCubicBezierPoint(startPoint, controlPointOne, controlPointTwo, endPoint, progress) {
17620
+ const inverseProgress = 1 - progress;
17621
+ return {
17622
+ x: inverseProgress * inverseProgress * inverseProgress * startPoint.x +
17623
+ 3 * inverseProgress * inverseProgress * progress * controlPointOne.x +
17624
+ 3 * inverseProgress * progress * progress * controlPointTwo.x +
17625
+ progress * progress * progress * endPoint.x,
17626
+ y: inverseProgress * inverseProgress * inverseProgress * startPoint.y +
17627
+ 3 * inverseProgress * inverseProgress * progress * controlPointOne.y +
17628
+ 3 * inverseProgress * progress * progress * controlPointTwo.y +
17629
+ progress * progress * progress * endPoint.y,
17630
+ };
17631
+ }
17632
+
17633
+ /* eslint-disable no-magic-numbers */
17634
+ /**
17635
+ * Glyph ramp used for the main octopus body fill.
17636
+ *
17637
+ * @private helper of `asciiOctopusAvatarVisual`
17638
+ */
17639
+ const BODY_GLYPHS = ['.', ':', '-', '=', '+', '*', '#', '%', '@'];
17640
+ /**
17641
+ * Glyph ramp used on silhouette edges so the ASCII blob stays legible.
17642
+ *
17643
+ * @private helper of `asciiOctopusAvatarVisual`
17644
+ */
17645
+ const OUTLINE_GLYPHS = ['#', '%', '@'];
17646
+ /**
17647
+ * Glyph ramp used in the surrounding atmosphere.
17648
+ *
17649
+ * @private helper of `asciiOctopusAvatarVisual`
17650
+ */
17651
+ const ATMOSPHERE_GLYPHS = ['.', ':', "'", '`'];
17652
+ /**
17653
+ * AsciiOctopus avatar visual.
17654
+ *
17655
+ * @private built-in avatar visual
17656
+ */
17657
+ const asciiOctopusAvatarVisual = {
17658
+ id: 'ascii-octopus',
17659
+ title: 'AsciiOctopus',
17660
+ description: 'Morphing alien octopus translated into animated ASCII glyphs with responsive eyes and seeded geometry.',
17661
+ isAnimated: true,
17662
+ supportsPointerTracking: true,
17663
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
17664
+ const gridRandom = createRandom('ascii-octopus-grid');
17665
+ const staticRandom = createRandom('ascii-octopus-static');
17666
+ const gridMetrics = createAsciiGridMetrics(size, gridRandom);
17667
+ const layout = createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction);
17668
+ drawAvatarFrame(context, size, palette);
17669
+ drawAsciiBackdrop(context, size, palette, layout, timeMs);
17670
+ context.save();
17671
+ context.font = `600 ${gridMetrics.fontSize}px monospace`;
17672
+ context.textAlign = 'center';
17673
+ context.textBaseline = 'middle';
17674
+ // The ASCII renderer samples the morphing octopus field on a low-resolution grid so the shape stays organic
17675
+ // while the glyph layout remains deterministic for the same avatar input.
17676
+ const cellRandom = createRandom('ascii-octopus-cells');
17677
+ for (let rowIndex = 0; rowIndex < gridMetrics.rowCount; rowIndex++) {
17678
+ for (let columnIndex = 0; columnIndex < gridMetrics.columnCount; columnIndex++) {
17679
+ const point = {
17680
+ x: gridMetrics.offsetX + columnIndex * gridMetrics.cellWidth,
17681
+ y: gridMetrics.offsetY + rowIndex * gridMetrics.cellHeight,
17682
+ };
17683
+ const noise = cellRandom();
17684
+ const glyphDescriptor = resolveAsciiGlyph({
17685
+ point,
17686
+ layout,
17687
+ palette,
17688
+ cellWidth: gridMetrics.cellWidth,
17689
+ cellHeight: gridMetrics.cellHeight,
17690
+ noise,
17691
+ timeMs,
17692
+ });
17693
+ if (!glyphDescriptor) {
17694
+ continue;
17695
+ }
17696
+ context.fillStyle = glyphDescriptor.color;
17697
+ context.fillText(glyphDescriptor.character, point.x, point.y);
17698
+ }
17699
+ }
17700
+ context.restore();
17701
+ },
17702
+ };
17703
+ /**
17704
+ * Draws the dark terminal-like glow behind the ASCII octopus.
17705
+ *
17706
+ * @param context Canvas 2D context.
17707
+ * @param size Canvas size in CSS pixels.
17708
+ * @param palette Derived avatar palette.
17709
+ * @param layout Prepared octopus layout.
17710
+ * @param timeMs Current animation time in milliseconds.
17711
+ *
17712
+ * @private helper of `asciiOctopusAvatarVisual`
17713
+ */
17714
+ function drawAsciiBackdrop(context, size, palette, layout, timeMs) {
17715
+ const haloGradient = context.createRadialGradient(layout.centerX, layout.centerY - size * 0.12, size * 0.06, layout.centerX, layout.centerY, size * 0.62);
17716
+ haloGradient.addColorStop(0, `${palette.highlight}26`);
17717
+ haloGradient.addColorStop(0.42, `${palette.accent}16`);
17718
+ haloGradient.addColorStop(1, `${palette.highlight}00`);
17719
+ context.fillStyle = haloGradient;
17720
+ context.fillRect(0, 0, size, size);
17721
+ 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);
17722
+ lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
17723
+ lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
17724
+ context.fillStyle = lowerGlowGradient;
17725
+ context.fillRect(0, 0, size, size);
17726
+ context.beginPath();
17727
+ context.ellipse(layout.centerX, layout.centerY + size * 0.29, size * 0.23, size * 0.065, 0, 0, Math.PI * 2);
17728
+ context.fillStyle = `${palette.shadow}33`;
17729
+ context.fill();
17730
+ }
17731
+ /**
17732
+ * Resolves the ASCII character that should be drawn for one sampled cell.
17733
+ *
17734
+ * @param options Cell evaluation options.
17735
+ * @returns Character descriptor or `null` when the cell should stay empty.
17736
+ *
17737
+ * @private helper of `asciiOctopusAvatarVisual`
17738
+ */
17739
+ function resolveAsciiGlyph(options) {
17740
+ const { point, layout, palette, cellWidth, cellHeight, noise, timeMs } = options;
17741
+ const eyeGlyphDescriptor = resolveEyeGlyph(point, layout.leftEye, layout.interaction, palette, timeMs) ||
17742
+ resolveEyeGlyph(point, layout.rightEye, layout.interaction, palette, timeMs);
17743
+ if (eyeGlyphDescriptor) {
17744
+ return eyeGlyphDescriptor;
17745
+ }
17746
+ const mouthGlyphDescriptor = resolveMouthGlyph(point, layout, palette, cellHeight);
17747
+ if (mouthGlyphDescriptor) {
17748
+ return mouthGlyphDescriptor;
17749
+ }
17750
+ const isWithinOctopusBounds = point.x >= layout.leftBound &&
17751
+ point.x <= layout.rightBound &&
17752
+ point.y >= layout.topBound &&
17753
+ point.y <= layout.bottomBound;
17754
+ if (!isWithinOctopusBounds) {
17755
+ return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
17756
+ }
17757
+ const isInsideBody = isPointInsidePolygon(point, layout.bodyPoints);
17758
+ const bodyEdgeDistance = isInsideBody
17759
+ ? getDistanceToPolyline(point, layout.bodyPoints, true)
17760
+ : Number.POSITIVE_INFINITY;
17761
+ const tentacleCoverage = measureTentacleCoverage(point, layout.sampledTentacles, cellWidth);
17762
+ if (isInsideBody || tentacleCoverage) {
17763
+ return resolveOctopusSurfaceGlyph({
17764
+ point,
17765
+ layout,
17766
+ palette,
17767
+ isInsideBody,
17768
+ bodyEdgeDistance,
17769
+ tentacleCoverage,
17770
+ cellWidth,
17771
+ cellHeight,
17772
+ noise,
17773
+ timeMs,
17774
+ });
17775
+ }
17776
+ return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
17777
+ }
17778
+ /**
17779
+ * Resolves the ASCII character for one eye cell.
17780
+ *
17781
+ * @param point Sampled cell point.
17782
+ * @param eyeFeature Eye geometry.
17783
+ * @param palette Derived avatar palette.
17784
+ * @param timeMs Current animation time in milliseconds.
17785
+ * @returns Eye glyph descriptor or `null`.
17786
+ *
17787
+ * @private helper of `asciiOctopusAvatarVisual`
17788
+ */
17789
+ function resolveEyeGlyph(point, eyeFeature, interaction, palette, timeMs) {
17790
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
17791
+ radiusX: eyeFeature.radiusX,
17792
+ radiusY: eyeFeature.radiusY,
17793
+ timeMs,
17794
+ phase: eyeFeature.phase,
17795
+ interaction,
17796
+ });
17797
+ const scleraDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX, eyeFeature.centerY, eyeFeature.radiusX, eyeFeature.radiusY, eyeFeature.rotation);
17798
+ if (scleraDistance > 1.08) {
17799
+ return null;
17800
+ }
17801
+ 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);
17802
+ if (highlightDistance <= 1) {
17803
+ return { character: '*', color: '#ffffff' };
17804
+ }
17805
+ const pupilDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.2, eyeFeature.radiusY * 0.48, eyeFeature.rotation);
17806
+ if (pupilDistance <= 1) {
17807
+ return { character: '@', color: palette.ink };
17808
+ }
17809
+ const irisDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.64, eyeFeature.radiusY * 0.72, eyeFeature.rotation);
17810
+ if (irisDistance <= 1) {
17811
+ return {
17812
+ character: irisDistance < 0.46 ? '0' : 'o',
17813
+ color: irisDistance < 0.62 ? palette.secondary : `${palette.highlight}d9`,
17814
+ };
17815
+ }
17816
+ return {
17817
+ character: scleraDistance > 0.82 ? 'o' : '0',
17818
+ color: '#f8fbff',
17819
+ };
17820
+ }
17821
+ /**
17822
+ * Resolves the ASCII character for the octopus mouth.
17823
+ *
17824
+ * @param point Sampled cell point.
17825
+ * @param layout Prepared octopus layout.
17826
+ * @param palette Derived avatar palette.
17827
+ * @param cellHeight Character cell height.
17828
+ * @returns Mouth glyph descriptor or `null`.
17829
+ *
17830
+ * @private helper of `asciiOctopusAvatarVisual`
17831
+ */
17832
+ function resolveMouthGlyph(point, layout, palette, cellHeight) {
17833
+ const mouthDistance = getDistanceToPolyline(point, layout.mouthPoints, false);
17834
+ if (mouthDistance > cellHeight * 0.38) {
17835
+ return null;
17836
+ }
17837
+ const horizontalProgress = clamp01((point.x - layout.mouthPoints[0].x) /
17838
+ (layout.mouthPoints[layout.mouthPoints.length - 1].x - layout.mouthPoints[0].x));
17839
+ let character = '-';
17840
+ if (horizontalProgress < 0.28) {
17841
+ character = '\\';
17842
+ }
17843
+ else if (horizontalProgress > 0.72) {
17844
+ character = '/';
17845
+ }
17846
+ else if (horizontalProgress > 0.42 && horizontalProgress < 0.58) {
17847
+ character = '_';
17848
+ }
17849
+ return {
17850
+ character,
17851
+ color: `${palette.ink}bf`,
17852
+ };
17853
+ }
17854
+ /**
17855
+ * Resolves the ASCII character for body and tentacle cells.
17856
+ *
17857
+ * @param options Surface evaluation options.
17858
+ * @returns Surface glyph descriptor.
17859
+ *
17860
+ * @private helper of `asciiOctopusAvatarVisual`
17861
+ */
17862
+ function resolveOctopusSurfaceGlyph(options) {
17863
+ const { point, layout, palette, isInsideBody, bodyEdgeDistance, tentacleCoverage, cellHeight, noise, timeMs } = options;
17864
+ const isTentacleDominant = tentacleCoverage !== null && (!isInsideBody || point.y > layout.centerY + layout.bodyRadius * 0.08);
17865
+ if (isTentacleDominant && tentacleCoverage) {
17866
+ const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.78;
17867
+ if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.42) {
17868
+ return {
17869
+ character: noise > 0.9 ? '0' : 'o',
17870
+ color: `${palette.highlight}d0`,
17871
+ };
17872
+ }
17873
+ return {
17874
+ character: pickTentacleCharacter(tentacleCoverage, noise),
17875
+ color: tentacleCoverage.progress < 0.24
17876
+ ? `${palette.secondary}c7`
17877
+ : tentacleCoverage.progress > 0.72
17878
+ ? `${palette.accent}bf`
17879
+ : tentacleCoverage.normalizedDistance > 0.7
17880
+ ? `${palette.highlight}bf`
17881
+ : `${palette.primary}c9`,
17882
+ };
17883
+ }
17884
+ const highlightBias = clamp01((layout.centerY - point.y + layout.bodyRadius * 0.44) / (layout.bodyRadius * 1.14));
17885
+ const bodyDepth = clamp01(1 - bodyEdgeDistance / (layout.bodyRadius * 0.9));
17886
+ const shimmer = Math.sin(timeMs / 720 + point.x * 0.085 + point.y * 0.06 + layout.shapePhase) * 0.05;
17887
+ const bodyIntensity = clamp01(0.22 + bodyDepth * 0.58 + highlightBias * 0.2 + shimmer + (noise - 0.5) * 0.18);
17888
+ const isOutline = isInsideBody && bodyEdgeDistance < cellHeight * 0.54;
17889
+ const character = isOutline
17890
+ ? pickRampCharacter(OUTLINE_GLYPHS, clamp01(0.58 + bodyIntensity * 0.42))
17891
+ : pickRampCharacter(BODY_GLYPHS, bodyIntensity);
17892
+ let color = `${palette.primary}bf`;
17893
+ if (highlightBias > 0.76) {
17894
+ color = `${palette.highlight}d9`;
17895
+ }
17896
+ else if (bodyDepth > 0.7) {
17897
+ color = `${palette.secondary}cb`;
17898
+ }
17899
+ else if ((point.x < layout.centerX && noise > 0.58) || (point.x >= layout.centerX && noise < 0.42)) {
17900
+ color = `${palette.accent}ba`;
17901
+ }
17902
+ return {
17903
+ character,
17904
+ color: isOutline ? `${palette.highlight}c9` : color,
17905
+ };
17906
+ }
17907
+ /**
17908
+ * Resolves faint atmosphere glyphs around the ASCII octopus.
17909
+ *
17910
+ * @param point Sampled cell point.
17911
+ * @param layout Prepared octopus layout.
17912
+ * @param palette Derived avatar palette.
17913
+ * @param noise Stable per-cell noise.
17914
+ * @param timeMs Current animation time in milliseconds.
17915
+ * @returns Atmosphere glyph descriptor or `null`.
17916
+ *
17917
+ * @private helper of `asciiOctopusAvatarVisual`
17918
+ */
17919
+ function resolveAtmosphereGlyph(point, layout, palette, noise, timeMs) {
17920
+ const horizontalDistance = Math.abs(point.x - layout.centerX) / (layout.bodyRadius * layout.horizontalStretch * 2.2);
17921
+ const verticalDistance = Math.abs(point.y - (layout.centerY + layout.bodyRadius * 0.04)) / (layout.bodyRadius * 2.1);
17922
+ const haloDistance = Math.hypot(horizontalDistance, verticalDistance);
17923
+ const shimmer = Math.sin(timeMs / 1450 + point.x * 0.03 + point.y * 0.04 + layout.shapePhase) * 0.06;
17924
+ const density = clamp01(1.16 - haloDistance + shimmer + (noise - 0.5) * 0.14);
17925
+ if (density < 0.18 || noise > density * 0.84 + 0.34) {
17926
+ return null;
17927
+ }
17928
+ return {
17929
+ character: pickRampCharacter(ATMOSPHERE_GLYPHS, density),
17930
+ color: point.y < layout.centerY ? `${palette.highlight}63` : `${palette.accent}47`,
17931
+ };
17932
+ }
17933
+ /**
17934
+ * Builds the grid used by the ASCII renderer.
17935
+ *
17936
+ * @param size Canvas size in CSS pixels.
17937
+ * @param staticRandom Stable random generator for this avatar.
17938
+ * @returns Grid metrics.
17939
+ *
17940
+ * @private helper of `asciiOctopusAvatarVisual`
17941
+ */
17942
+ function createAsciiGridMetrics(size, staticRandom) {
17943
+ const fontSize = Math.max(9, Math.round(size * (0.048 + staticRandom() * 0.006)));
17944
+ const cellWidth = fontSize * (0.58 + staticRandom() * 0.04);
17945
+ const cellHeight = fontSize * 0.82;
17946
+ const columnCount = Math.max(12, Math.floor(size / cellWidth) - 1);
17947
+ const rowCount = Math.max(12, Math.floor(size / cellHeight) - 1);
17948
+ const offsetX = (size - (columnCount - 1) * cellWidth) / 2;
17949
+ const offsetY = (size - (rowCount - 1) * cellHeight) / 2;
17950
+ return {
17951
+ fontSize,
17952
+ cellWidth,
17953
+ cellHeight,
17954
+ columnCount,
17955
+ rowCount,
17956
+ offsetX,
17957
+ offsetY,
17958
+ };
17959
+ }
17960
+ /**
17961
+ * Builds the deterministic octopus geometry that will later be sampled into ASCII cells.
17962
+ *
17963
+ * @param size Canvas size in CSS pixels.
17964
+ * @param timeMs Current animation time in milliseconds.
17965
+ * @param createRandom Seeded random factory scoped to the avatar.
17966
+ * @param staticRandom Stable random generator for this avatar.
17967
+ * @returns Prepared octopus layout.
17968
+ *
17969
+ * @private helper of `asciiOctopusAvatarVisual`
17970
+ */
17971
+ function createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction) {
17972
+ const centerX = size * (0.5 + (staticRandom() - 0.5) * 0.02) + interaction.bodyOffsetX * size * 0.05;
17973
+ const centerY = size * (0.41 + staticRandom() * 0.05) + interaction.bodyOffsetY * size * 0.035;
17974
+ const bodyRadius = size * (0.195 + staticRandom() * 0.05);
17975
+ const horizontalStretch = 1.08 + staticRandom() * 0.22;
17976
+ const verticalStretch = 0.88 + staticRandom() * 0.14;
17977
+ const mantleLift = size * (0.1 + staticRandom() * 0.03);
17978
+ const lowerDrop = size * (0.03 + staticRandom() * 0.024);
17979
+ const tentacleDepth = size * (0.026 + staticRandom() * 0.022);
17980
+ const wobbleAmplitude = size * (0.008 + staticRandom() * 0.01);
17981
+ const lobeCount = 5 + Math.floor(staticRandom() * 4);
17982
+ const shapePhase = staticRandom() * Math.PI * 2;
17983
+ const tentacleCount = 8 + Math.floor(staticRandom() * 5);
17984
+ const eyeSpacing = size * (0.108 + staticRandom() * 0.042);
17985
+ const eyeRadiusX = size * (0.05 + staticRandom() * 0.015);
17986
+ const eyeRadiusY = eyeRadiusX * (1.16 + staticRandom() * 0.2);
17987
+ const bodyPoints = createOrganicOctopusBodyPoints({
17988
+ centerX,
17989
+ centerY,
17990
+ bodyRadius,
17991
+ horizontalStretch,
17992
+ verticalStretch,
17993
+ mantleLift,
17994
+ lowerDrop,
17995
+ tentacleDepth,
17996
+ wobbleAmplitude,
17997
+ lobeCount,
17998
+ shapePhase,
17999
+ timeMs,
18000
+ pointCount: 40,
18001
+ });
18002
+ const tentacleShapes = createOrganicOctopusTentacleShapes({
18003
+ size,
18004
+ centerX,
18005
+ centerY,
18006
+ bodyRadius,
18007
+ horizontalStretch,
18008
+ tentacleCount,
18009
+ shapePhase,
18010
+ createRandom,
18011
+ timeMs,
18012
+ saltPrefix: 'ascii-octopus',
18013
+ bodyPoints,
18014
+ });
18015
+ const sampledTentacles = tentacleShapes.map(sampleOrganicTentacleRibbonPoints);
18016
+ const leftEye = {
18017
+ centerX: centerX - eyeSpacing,
18018
+ centerY: centerY - size * 0.01,
18019
+ radiusX: eyeRadiusX,
18020
+ radiusY: eyeRadiusY,
18021
+ rotation: (staticRandom() - 0.5) * 0.24,
18022
+ phase: shapePhase,
18023
+ };
18024
+ const rightEye = {
18025
+ centerX: centerX + eyeSpacing,
18026
+ centerY: centerY - size * 0.01,
18027
+ radiusX: eyeRadiusX,
18028
+ radiusY: eyeRadiusY,
18029
+ rotation: (staticRandom() - 0.5) * 0.24,
18030
+ phase: shapePhase + Math.PI / 4,
18031
+ };
18032
+ const mouthPoints = sampleQuadraticBezierPoints({ x: centerX - size * 0.074, y: centerY + size * 0.092 }, {
18033
+ x: centerX,
18034
+ y: centerY +
18035
+ size * (0.142 + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
18036
+ interaction.gazeY * size * 0.012,
18037
+ }, { x: centerX + size * 0.074, y: centerY + size * 0.092 }, 12);
18038
+ let leftBound = Number.POSITIVE_INFINITY;
18039
+ let rightBound = Number.NEGATIVE_INFINITY;
18040
+ let topBound = Number.POSITIVE_INFINITY;
18041
+ let bottomBound = Number.NEGATIVE_INFINITY;
18042
+ for (const bodyPoint of bodyPoints) {
18043
+ leftBound = Math.min(leftBound, bodyPoint.x);
18044
+ rightBound = Math.max(rightBound, bodyPoint.x);
18045
+ topBound = Math.min(topBound, bodyPoint.y);
18046
+ bottomBound = Math.max(bottomBound, bodyPoint.y);
18047
+ }
18048
+ for (const sampledTentacle of sampledTentacles) {
18049
+ for (const ribbonPoint of sampledTentacle) {
18050
+ leftBound = Math.min(leftBound, ribbonPoint.x - ribbonPoint.width);
18051
+ rightBound = Math.max(rightBound, ribbonPoint.x + ribbonPoint.width);
18052
+ topBound = Math.min(topBound, ribbonPoint.y - ribbonPoint.width);
18053
+ bottomBound = Math.max(bottomBound, ribbonPoint.y + ribbonPoint.width);
18054
+ }
18055
+ }
18056
+ return {
18057
+ centerX,
18058
+ centerY,
18059
+ bodyRadius,
18060
+ horizontalStretch,
18061
+ shapePhase,
18062
+ interaction,
18063
+ bodyPoints,
18064
+ sampledTentacles,
18065
+ leftEye,
18066
+ rightEye,
18067
+ mouthPoints,
18068
+ leftBound: leftBound - size * 0.08,
18069
+ rightBound: rightBound + size * 0.08,
18070
+ topBound: topBound - size * 0.08,
18071
+ bottomBound: bottomBound + size * 0.08,
18072
+ };
18073
+ }
18074
+ /**
18075
+ * Samples points along a quadratic Bezier curve.
18076
+ *
18077
+ * @param startPoint Curve start point.
18078
+ * @param controlPoint Curve control point.
18079
+ * @param endPoint Curve end point.
18080
+ * @param pointCount Number of intervals to sample.
18081
+ * @returns Sampled curve points.
18082
+ *
18083
+ * @private helper of `asciiOctopusAvatarVisual`
18084
+ */
18085
+ function sampleQuadraticBezierPoints(startPoint, controlPoint, endPoint, pointCount) {
18086
+ return Array.from({ length: pointCount + 1 }, (_, pointIndex) => {
18087
+ const progress = pointIndex / pointCount;
18088
+ const inverseProgress = 1 - progress;
18089
+ return {
18090
+ x: inverseProgress * inverseProgress * startPoint.x +
18091
+ 2 * inverseProgress * progress * controlPoint.x +
18092
+ progress * progress * endPoint.x,
18093
+ y: inverseProgress * inverseProgress * startPoint.y +
18094
+ 2 * inverseProgress * progress * controlPoint.y +
18095
+ progress * progress * endPoint.y,
18096
+ };
18097
+ });
18098
+ }
18099
+ /**
18100
+ * Measures how strongly the sampled cell intersects with the generated tentacles.
18101
+ *
18102
+ * @param point Sampled cell point.
18103
+ * @param sampledTentacles Pre-sampled tentacle ribbons.
18104
+ * @param cellWidth Character cell width.
18105
+ * @returns Nearest tentacle coverage or `null`.
18106
+ *
18107
+ * @private helper of `asciiOctopusAvatarVisual`
18108
+ */
18109
+ function measureTentacleCoverage(point, sampledTentacles, cellWidth) {
18110
+ let bestTentacleCoverage = null;
18111
+ let bestNormalizedDistance = 0;
18112
+ for (const sampledTentacle of sampledTentacles) {
18113
+ for (const ribbonPoint of sampledTentacle) {
18114
+ const deltaX = point.x - ribbonPoint.x;
18115
+ const deltaY = point.y - ribbonPoint.y;
18116
+ const distance = Math.hypot(deltaX, deltaY);
18117
+ const coverageRadius = ribbonPoint.width + cellWidth * 0.22;
18118
+ const normalizedDistance = 1 - distance / coverageRadius;
18119
+ if (normalizedDistance <= bestNormalizedDistance || normalizedDistance <= 0) {
18120
+ continue;
18121
+ }
18122
+ bestNormalizedDistance = normalizedDistance;
18123
+ bestTentacleCoverage = {
18124
+ tangentAngle: Math.atan2(-ribbonPoint.normalX, ribbonPoint.normalY),
18125
+ progress: ribbonPoint.progress,
18126
+ normalizedDistance,
18127
+ };
18128
+ }
18129
+ }
18130
+ return bestTentacleCoverage;
18131
+ }
18132
+ /**
18133
+ * Picks one ASCII character that matches the nearest tentacle direction.
18134
+ *
18135
+ * @param tentacleCoverage Nearest tentacle coverage.
18136
+ * @param noise Stable per-cell noise.
18137
+ * @returns Tentacle ASCII character.
18138
+ *
18139
+ * @private helper of `asciiOctopusAvatarVisual`
18140
+ */
18141
+ function pickTentacleCharacter(tentacleCoverage, noise) {
18142
+ const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.82;
18143
+ if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.34) {
18144
+ return noise > 0.91 ? '0' : 'o';
18145
+ }
18146
+ const horizontalWeight = Math.abs(Math.cos(tentacleCoverage.tangentAngle));
18147
+ const verticalWeight = Math.abs(Math.sin(tentacleCoverage.tangentAngle));
18148
+ if (horizontalWeight > 0.84) {
18149
+ return noise > 0.52 ? '=' : '-';
18150
+ }
18151
+ if (verticalWeight > 0.82) {
18152
+ return noise > 0.56 ? '|' : '!';
18153
+ }
18154
+ return Math.sin(tentacleCoverage.tangentAngle) * Math.cos(tentacleCoverage.tangentAngle) > 0 ? '\\' : '/';
18155
+ }
18156
+ /**
18157
+ * Picks one character from an ordered ramp.
18158
+ *
18159
+ * @param glyphRamp Ordered glyph ramp.
18160
+ * @param intensity Normalized intensity in the range `[0, 1]`.
18161
+ * @returns Selected glyph.
18162
+ *
18163
+ * @private helper of `asciiOctopusAvatarVisual`
18164
+ */
18165
+ function pickRampCharacter(glyphRamp, intensity) {
18166
+ const characterIndex = Math.min(glyphRamp.length - 1, Math.floor(clamp01(intensity) * glyphRamp.length));
18167
+ return glyphRamp[characterIndex];
18168
+ }
18169
+ /**
18170
+ * Measures the normalized distance from a point to a rotated ellipse.
18171
+ *
18172
+ * @param point Sampled cell point.
18173
+ * @param centerX Ellipse center X coordinate.
18174
+ * @param centerY Ellipse center Y coordinate.
18175
+ * @param radiusX Horizontal ellipse radius.
18176
+ * @param radiusY Vertical ellipse radius.
18177
+ * @param rotation Ellipse rotation in radians.
18178
+ * @returns Normalized ellipse distance where values below `1` are inside.
18179
+ *
18180
+ * @private helper of `asciiOctopusAvatarVisual`
18181
+ */
18182
+ function measureRotatedEllipseDistance(point, centerX, centerY, radiusX, radiusY, rotation) {
18183
+ const cosine = Math.cos(rotation);
18184
+ const sine = Math.sin(rotation);
18185
+ const translatedX = point.x - centerX;
18186
+ const translatedY = point.y - centerY;
18187
+ const localX = translatedX * cosine + translatedY * sine;
18188
+ const localY = -translatedX * sine + translatedY * cosine;
18189
+ return Math.sqrt((localX * localX) / (radiusX * radiusX) + (localY * localY) / (radiusY * radiusY));
18190
+ }
18191
+ /**
18192
+ * Checks whether a point lies inside the given closed polygon.
18193
+ *
18194
+ * @param point Sampled cell point.
18195
+ * @param polygonPoints Polygon points in order.
18196
+ * @returns `true` when the point lies inside the polygon.
18197
+ *
18198
+ * @private helper of `asciiOctopusAvatarVisual`
18199
+ */
18200
+ function isPointInsidePolygon(point, polygonPoints) {
18201
+ let isInside = false;
18202
+ for (let currentPointIndex = 0, previousPointIndex = polygonPoints.length - 1; currentPointIndex < polygonPoints.length; previousPointIndex = currentPointIndex++) {
18203
+ const currentPoint = polygonPoints[currentPointIndex];
18204
+ const previousPoint = polygonPoints[previousPointIndex];
18205
+ const isIntersecting = currentPoint.y > point.y !== previousPoint.y > point.y &&
18206
+ point.x <
18207
+ ((previousPoint.x - currentPoint.x) * (point.y - currentPoint.y)) / (previousPoint.y - currentPoint.y) +
18208
+ currentPoint.x;
18209
+ if (isIntersecting) {
18210
+ isInside = !isInside;
18211
+ }
18212
+ }
18213
+ return isInside;
18214
+ }
18215
+ /**
18216
+ * Measures the shortest distance from a point to a polyline.
18217
+ *
18218
+ * @param point Sampled cell point.
18219
+ * @param polylinePoints Polyline points in order.
18220
+ * @param isClosed Whether the final point should connect back to the first point.
18221
+ * @returns Shortest distance to the polyline.
18222
+ *
18223
+ * @private helper of `asciiOctopusAvatarVisual`
18224
+ */
18225
+ function getDistanceToPolyline(point, polylinePoints, isClosed) {
18226
+ let shortestDistance = Number.POSITIVE_INFINITY;
18227
+ const segmentCount = isClosed ? polylinePoints.length : polylinePoints.length - 1;
18228
+ for (let segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) {
18229
+ const startPoint = polylinePoints[segmentIndex];
18230
+ const endPoint = polylinePoints[(segmentIndex + 1) % polylinePoints.length];
18231
+ shortestDistance = Math.min(shortestDistance, getDistanceToLineSegment(point, startPoint, endPoint));
18232
+ }
18233
+ return shortestDistance;
18234
+ }
18235
+ /**
18236
+ * Measures the shortest distance from a point to one line segment.
18237
+ *
18238
+ * @param point Sampled cell point.
18239
+ * @param startPoint Segment start point.
18240
+ * @param endPoint Segment end point.
18241
+ * @returns Shortest distance to the segment.
18242
+ *
18243
+ * @private helper of `asciiOctopusAvatarVisual`
18244
+ */
18245
+ function getDistanceToLineSegment(point, startPoint, endPoint) {
18246
+ const deltaX = endPoint.x - startPoint.x;
18247
+ const deltaY = endPoint.y - startPoint.y;
18248
+ const segmentLengthSquared = deltaX * deltaX + deltaY * deltaY;
18249
+ if (segmentLengthSquared === 0) {
18250
+ return Math.hypot(point.x - startPoint.x, point.y - startPoint.y);
18251
+ }
18252
+ const progress = clamp01(((point.x - startPoint.x) * deltaX + (point.y - startPoint.y) * deltaY) / segmentLengthSquared);
18253
+ const projectionX = startPoint.x + deltaX * progress;
18254
+ const projectionY = startPoint.y + deltaY * progress;
18255
+ return Math.hypot(point.x - projectionX, point.y - projectionY);
18256
+ }
18257
+ /**
18258
+ * Clamps a number into the inclusive range `[0, 1]`.
18259
+ *
18260
+ * @param value Arbitrary numeric value.
18261
+ * @returns Clamped value.
18262
+ *
18263
+ * @private helper of `asciiOctopusAvatarVisual`
18264
+ */
18265
+ function clamp01(value) {
18266
+ return Math.max(0, Math.min(1, value));
18267
+ }
18268
+
18269
+ /* eslint-disable no-magic-numbers */
18270
+ /**
18271
+ * Fractal avatar visual.
18272
+ *
18273
+ * @private built-in avatar visual
18274
+ */
18275
+ const fractalAvatarVisual = {
18276
+ id: 'fractal',
18277
+ title: 'Fractal',
18278
+ description: 'Layered dragon-curve ribbons with deterministic glows, bends, and seeded color interplay.',
18279
+ isAnimated: true,
18280
+ render({ context, size, palette, createRandom, timeMs }) {
18281
+ const staticRandom = createRandom('fractal-static');
18282
+ const centerX = size * 0.5;
18283
+ const centerY = size * 0.5;
18284
+ const layerCount = 2 + Math.floor(staticRandom() * 3);
18285
+ const haloRotation = staticRandom() * Math.PI * 2;
18286
+ const colorSequence = [palette.primary, palette.secondary, palette.accent, palette.highlight];
18287
+ drawAvatarFrame(context, size, palette);
18288
+ drawFractalBackground(context, size, palette, timeMs, haloRotation);
18289
+ for (let layerIndex = 0; layerIndex < layerCount; layerIndex++) {
18290
+ const layerRandom = createRandom(`fractal-layer-${layerIndex}`);
18291
+ const order = 8 + Math.floor(layerRandom() * 4);
18292
+ const turnSequence = createDragonCurveTurns(order);
18293
+ const basePoints = createDragonCurvePoints(turnSequence);
18294
+ const transformedPoints = transformDragonCurvePoints(basePoints, {
18295
+ size,
18296
+ centerX: centerX + (layerRandom() - 0.5) * size * 0.08,
18297
+ centerY: centerY + (layerRandom() - 0.5) * size * 0.08,
18298
+ rotation: layerRandom() * Math.PI * 2 + Math.sin(timeMs / (1700 + layerIndex * 280) + layerIndex) * 0.14,
18299
+ scale: size * (0.19 + layerIndex * 0.055 + layerRandom() * 0.045),
18300
+ horizontalStretch: 0.74 + layerRandom() * 0.9,
18301
+ verticalStretch: 0.74 + layerRandom() * 0.9,
18302
+ warpAmplitude: size * (0.008 + layerRandom() * 0.012),
18303
+ warpPhase: layerRandom() * Math.PI * 2,
18304
+ mirrorX: layerRandom() < 0.5 ? -1 : 1,
18305
+ mirrorY: layerRandom() < 0.38 ? -1 : 1,
18306
+ timeMs,
18307
+ });
18308
+ const primaryColor = colorSequence[layerIndex % colorSequence.length];
18309
+ const secondaryColor = colorSequence[(layerIndex + 1) % colorSequence.length];
18310
+ const tertiaryColor = colorSequence[(layerIndex + 2) % colorSequence.length];
18311
+ const strokeWidth = size * (0.026 - layerIndex * 0.0035);
18312
+ drawDragonCurveLayer(context, transformedPoints, {
18313
+ size,
18314
+ primaryColor,
18315
+ secondaryColor,
18316
+ tertiaryColor,
18317
+ shadowColor: palette.shadow,
18318
+ strokeWidth,
18319
+ timeMs,
18320
+ layerIndex,
18321
+ });
18322
+ }
18323
+ drawFractalCore(context, size, palette, timeMs, staticRandom());
18324
+ },
18325
+ };
18326
+ /**
18327
+ * Draws the shared luminous atmosphere behind the curve layers.
18328
+ *
18329
+ * @param context Canvas 2D context.
18330
+ * @param size Canvas size in CSS pixels.
18331
+ * @param palette Derived avatar palette.
18332
+ * @param timeMs Current animation time in milliseconds.
18333
+ * @param haloRotation Seed-based phase offset.
18334
+ *
18335
+ * @private helper of `fractalAvatarVisual`
18336
+ */
18337
+ function drawFractalBackground(context, size, palette, timeMs, haloRotation) {
18338
+ const centerX = size * 0.5;
18339
+ const centerY = size * 0.5;
18340
+ const radialGlow = context.createRadialGradient(centerX, centerY, size * 0.06, centerX, centerY, size * 0.72);
18341
+ radialGlow.addColorStop(0, `${palette.highlight}55`);
18342
+ radialGlow.addColorStop(0.4, `${palette.secondary}1f`);
18343
+ radialGlow.addColorStop(1, `${palette.highlight}00`);
18344
+ context.fillStyle = radialGlow;
18345
+ context.fillRect(0, 0, size, size);
18346
+ for (let haloIndex = 0; haloIndex < 3; haloIndex++) {
18347
+ const radius = size * (0.17 + haloIndex * 0.09);
18348
+ const rotation = haloRotation + haloIndex * 0.85 + timeMs / (4400 + haloIndex * 700);
18349
+ context.beginPath();
18350
+ context.ellipse(centerX, centerY, radius, radius * (0.62 + haloIndex * 0.06), rotation, 0, Math.PI * 2);
18351
+ context.strokeStyle = haloIndex % 2 === 0 ? `${palette.secondary}24` : `${palette.accent}20`;
18352
+ context.lineWidth = size * 0.006;
18353
+ context.stroke();
18354
+ }
18355
+ }
18356
+ /**
18357
+ * Generates the left-right turn sequence for a dragon curve.
18358
+ *
18359
+ * @param order Number of folding iterations.
18360
+ * @returns Turn sequence where `1` means right and `-1` means left.
18361
+ *
18362
+ * @private helper of `fractalAvatarVisual`
18363
+ */
18364
+ function createDragonCurveTurns(order) {
18365
+ let turns = [];
18366
+ for (let iteration = 0; iteration < order; iteration++) {
18367
+ turns = [
18368
+ ...turns,
18369
+ 1,
18370
+ ...turns
18371
+ .slice()
18372
+ .reverse()
18373
+ .map((turn) => (turn === 1 ? -1 : 1)),
18374
+ ];
18375
+ }
18376
+ return turns;
18377
+ }
18378
+ /**
18379
+ * Converts a dragon-curve turn sequence into a raw grid polyline.
18380
+ *
18381
+ * @param turnSequence Ordered turn sequence.
18382
+ * @returns Unscaled polyline points.
18383
+ *
18384
+ * @private helper of `fractalAvatarVisual`
18385
+ */
18386
+ function createDragonCurvePoints(turnSequence) {
18387
+ const points = [{ x: 0, y: 0 }];
18388
+ const directions = [
18389
+ { x: 1, y: 0 },
18390
+ { x: 0, y: 1 },
18391
+ { x: -1, y: 0 },
18392
+ { x: 0, y: -1 },
18393
+ ];
18394
+ let directionIndex = 0;
18395
+ for (let segmentIndex = 0; segmentIndex <= turnSequence.length; segmentIndex++) {
18396
+ const currentPoint = points[points.length - 1];
18397
+ const direction = directions[directionIndex];
18398
+ points.push({
18399
+ x: currentPoint.x + direction.x,
18400
+ y: currentPoint.y + direction.y,
18401
+ });
18402
+ if (segmentIndex < turnSequence.length) {
18403
+ directionIndex = (directionIndex + turnSequence[segmentIndex] + directions.length) % directions.length;
18404
+ }
18405
+ }
18406
+ return points;
18407
+ }
18408
+ /**
18409
+ * Normalizes and decorates the dragon-curve polyline for avatar rendering.
18410
+ *
18411
+ * @param points Raw grid polyline points.
18412
+ * @param options Transformation parameters.
18413
+ * @returns Transformed canvas points.
18414
+ *
18415
+ * @private helper of `fractalAvatarVisual`
18416
+ */
18417
+ function transformDragonCurvePoints(points, options) {
18418
+ const { size, centerX, centerY, rotation, scale, horizontalStretch, verticalStretch, warpAmplitude, warpPhase, mirrorX, mirrorY, timeMs, } = options;
18419
+ const bounds = getPointBounds(points);
18420
+ const width = Math.max(1, bounds.maxX - bounds.minX);
18421
+ const height = Math.max(1, bounds.maxY - bounds.minY);
18422
+ const normalizationScale = scale / Math.max(width, height);
18423
+ const cosine = Math.cos(rotation);
18424
+ const sine = Math.sin(rotation);
18425
+ return points.map((point, pointIndex) => {
18426
+ const normalizedX = (point.x - (bounds.minX + width / 2)) * normalizationScale * horizontalStretch * mirrorX;
18427
+ const normalizedY = (point.y - (bounds.minY + height / 2)) * normalizationScale * verticalStretch * mirrorY;
18428
+ const progress = pointIndex / Math.max(1, points.length - 1);
18429
+ const localWarp = Math.sin(progress * Math.PI * 4 + warpPhase + timeMs / 1400) * warpAmplitude +
18430
+ Math.cos(progress * Math.PI * 7 - warpPhase + timeMs / 1800) * warpAmplitude * 0.45;
18431
+ const rotatedX = normalizedX * cosine - normalizedY * sine;
18432
+ const rotatedY = normalizedX * sine + normalizedY * cosine;
18433
+ return {
18434
+ x: centerX + rotatedX + Math.sin(progress * Math.PI * 2 + warpPhase) * localWarp,
18435
+ y: centerY +
18436
+ rotatedY +
18437
+ Math.cos(progress * Math.PI * 3 + warpPhase * 0.6) * localWarp +
18438
+ (progress - 0.5) * size * 0.02,
18439
+ };
18440
+ });
18441
+ }
18442
+ /**
18443
+ * Returns the bounding box of a point cloud.
18444
+ *
18445
+ * @param points Point cloud to inspect.
18446
+ * @returns Bounding box.
18447
+ *
18448
+ * @private helper of `fractalAvatarVisual`
18449
+ */
18450
+ function getPointBounds(points) {
18451
+ return points.reduce((bounds, point) => ({
18452
+ minX: Math.min(bounds.minX, point.x),
18453
+ maxX: Math.max(bounds.maxX, point.x),
18454
+ minY: Math.min(bounds.minY, point.y),
18455
+ maxY: Math.max(bounds.maxY, point.y),
18456
+ }), {
18457
+ minX: Number.POSITIVE_INFINITY,
18458
+ maxX: Number.NEGATIVE_INFINITY,
18459
+ minY: Number.POSITIVE_INFINITY,
18460
+ maxY: Number.NEGATIVE_INFINITY,
18461
+ });
18462
+ }
18463
+ /**
18464
+ * Draws one stylized dragon-curve ribbon with glow and spark nodes.
18465
+ *
18466
+ * @param context Canvas 2D context.
18467
+ * @param points Transformed polyline points.
18468
+ * @param options Layer styling options.
18469
+ *
18470
+ * @private helper of `fractalAvatarVisual`
18471
+ */
18472
+ function drawDragonCurveLayer(context, points, options) {
18473
+ const { size, primaryColor, secondaryColor, tertiaryColor, shadowColor, strokeWidth, timeMs, layerIndex } = options;
18474
+ const firstPoint = points[0];
18475
+ const lastPoint = points[points.length - 1];
18476
+ const ribbonGradient = context.createLinearGradient(firstPoint.x, firstPoint.y, lastPoint.x, lastPoint.y);
18477
+ ribbonGradient.addColorStop(0, `${primaryColor}f2`);
18478
+ ribbonGradient.addColorStop(0.5, `${secondaryColor}e6`);
18479
+ ribbonGradient.addColorStop(1, `${tertiaryColor}f2`);
18480
+ context.save();
18481
+ context.beginPath();
18482
+ tracePolyline(context, points);
18483
+ context.strokeStyle = `${shadowColor}82`;
18484
+ context.lineWidth = strokeWidth * 1.8;
18485
+ context.lineJoin = 'round';
18486
+ context.lineCap = 'round';
18487
+ context.filter = `blur(${size * 0.022}px)`;
18488
+ context.stroke();
18489
+ context.restore();
18490
+ context.beginPath();
18491
+ tracePolyline(context, points);
18492
+ context.strokeStyle = ribbonGradient;
18493
+ context.lineWidth = strokeWidth;
18494
+ context.lineJoin = 'round';
18495
+ context.lineCap = 'round';
18496
+ context.stroke();
18497
+ context.beginPath();
18498
+ tracePolyline(context, points);
18499
+ context.strokeStyle = 'rgba(255,255,255,0.22)';
18500
+ context.lineWidth = Math.max(1.2, strokeWidth * 0.28);
18501
+ context.lineJoin = 'round';
18502
+ context.lineCap = 'round';
18503
+ context.stroke();
18504
+ const sparkStride = Math.max(24, Math.floor(points.length / 18));
18505
+ for (let pointIndex = sparkStride; pointIndex < points.length; pointIndex += sparkStride) {
18506
+ const point = points[pointIndex];
18507
+ const pulse = 0.7 + 0.3 * Math.sin(timeMs / 700 + pointIndex * 0.12 + layerIndex);
18508
+ const radius = strokeWidth * (0.24 + pulse * 0.22);
18509
+ context.beginPath();
18510
+ context.arc(point.x, point.y, radius * 1.8, 0, Math.PI * 2);
18511
+ context.fillStyle = `${secondaryColor}20`;
18512
+ context.fill();
18513
+ context.beginPath();
18514
+ context.arc(point.x, point.y, radius, 0, Math.PI * 2);
18515
+ context.fillStyle = tertiaryColor;
18516
+ context.fill();
18517
+ }
18518
+ }
18519
+ /**
18520
+ * Traces a polyline through the provided points.
18521
+ *
18522
+ * @param context Canvas 2D context.
18523
+ * @param points Polyline points.
18524
+ *
18525
+ * @private helper of `fractalAvatarVisual`
18526
+ */
18527
+ function tracePolyline(context, points) {
18528
+ const firstPoint = points[0];
18529
+ context.moveTo(firstPoint.x, firstPoint.y);
18530
+ for (let pointIndex = 1; pointIndex < points.length; pointIndex++) {
18531
+ const point = points[pointIndex];
18532
+ context.lineTo(point.x, point.y);
18533
+ }
18534
+ }
18535
+ /**
18536
+ * Draws the central crystalline accent tying the dragon-curve layers together.
18537
+ *
18538
+ * @param context Canvas 2D context.
18539
+ * @param size Canvas size in CSS pixels.
18540
+ * @param palette Derived avatar palette.
18541
+ * @param timeMs Current animation time in milliseconds.
18542
+ * @param corePhase Seed-based phase offset.
18543
+ *
18544
+ * @private helper of `fractalAvatarVisual`
18545
+ */
18546
+ function drawFractalCore(context, size, palette, timeMs, corePhase) {
18547
+ const centerX = size * 0.5;
18548
+ const centerY = size * 0.5;
18549
+ const radius = size * 0.082;
18550
+ const rotation = corePhase * Math.PI * 2 + timeMs / 2200;
18551
+ const innerRotation = -rotation * 1.35;
18552
+ context.save();
18553
+ context.translate(centerX, centerY);
18554
+ context.rotate(rotation);
18555
+ context.beginPath();
18556
+ for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
18557
+ const angle = (pointIndex / 4) * Math.PI * 2;
18558
+ const x = Math.cos(angle) * radius;
18559
+ const y = Math.sin(angle) * radius;
18560
+ if (pointIndex === 0) {
18561
+ context.moveTo(x, y);
18562
+ }
18563
+ else {
18564
+ context.lineTo(x, y);
18565
+ }
18566
+ }
18567
+ context.closePath();
18568
+ context.fillStyle = `${palette.highlight}88`;
18569
+ context.shadowColor = `${palette.highlight}77`;
18570
+ context.shadowBlur = size * 0.05;
18571
+ context.fill();
18572
+ context.restore();
18573
+ context.save();
18574
+ context.translate(centerX, centerY);
18575
+ context.rotate(innerRotation);
18576
+ context.beginPath();
18577
+ for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
18578
+ const angle = Math.PI / 4 + (pointIndex / 4) * Math.PI * 2;
18579
+ const x = Math.cos(angle) * radius * 0.55;
18580
+ const y = Math.sin(angle) * radius * 0.55;
18581
+ if (pointIndex === 0) {
18582
+ context.moveTo(x, y);
18583
+ }
18584
+ else {
18585
+ context.lineTo(x, y);
18586
+ }
18587
+ }
18588
+ context.closePath();
18589
+ context.fillStyle = `${palette.ink}cc`;
18590
+ context.fill();
18591
+ context.restore();
18592
+ }
18593
+
18594
+ /* eslint-disable no-magic-numbers */
18595
+ /**
18596
+ * Minecraft-style 3D avatar visual.
18597
+ *
18598
+ * @private built-in avatar visual
18599
+ */
18600
+ const minecraftAvatarVisual = {
18601
+ id: 'minecraft',
18602
+ title: 'Minecraft 3D',
18603
+ description: 'Blocky 3D portrait with deterministic pixel textures, shoulders, and hovering depth.',
18604
+ isAnimated: true,
18605
+ render({ context, size, palette, createRandom, timeMs }) {
18606
+ const random = createRandom('minecraft');
18607
+ const bob = Math.sin(timeMs / 880) * size * 0.015;
18608
+ const headSize = size * 0.34;
18609
+ const depth = headSize * 0.22;
18610
+ const headX = size * 0.31;
18611
+ const headY = size * 0.18 + bob;
18612
+ const bodyWidth = headSize * 0.86;
18613
+ const bodyHeight = headSize * 0.82;
18614
+ const bodyDepth = depth * 0.8;
18615
+ const bodyX = size * 0.33;
18616
+ const bodyY = headY + headSize * 0.96;
18617
+ const hasHeadband = random() < 0.5;
18618
+ const faceTexture = createMinecraftFaceTexture(createRandom('minecraft-face'), palette, hasHeadband);
18619
+ const shirtTexture = createMinecraftShirtTexture(createRandom('minecraft-shirt'), palette);
18620
+ drawAvatarFrame(context, size, palette);
18621
+ const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
18622
+ spotlight.addColorStop(0, `${palette.highlight}66`);
18623
+ spotlight.addColorStop(1, `${palette.highlight}00`);
18624
+ context.fillStyle = spotlight;
18625
+ context.fillRect(0, 0, size, size);
18626
+ context.save();
18627
+ context.fillStyle = 'rgba(0, 0, 0, 0.22)';
18628
+ context.filter = `blur(${size * 0.018}px)`;
18629
+ context.beginPath();
18630
+ context.ellipse(size * 0.5, size * 0.86, size * 0.2, size * 0.06, 0, 0, Math.PI * 2);
18631
+ context.fill();
18632
+ context.restore();
18633
+ drawVoxelCuboid(context, {
18634
+ x: bodyX,
18635
+ y: bodyY,
18636
+ width: bodyWidth,
18637
+ height: bodyHeight,
18638
+ depth: bodyDepth,
18639
+ frontTexture: shirtTexture,
18640
+ topColor: `${palette.highlight}cc`,
18641
+ sideColor: `${palette.secondary}dd`,
18642
+ outlineColor: `${palette.shadow}aa`,
18643
+ });
18644
+ drawVoxelCuboid(context, {
18645
+ x: headX,
18646
+ y: headY,
18647
+ width: headSize,
18648
+ height: headSize,
18649
+ depth,
18650
+ frontTexture: faceTexture,
18651
+ topColor: `${palette.highlight}ee`,
18652
+ sideColor: `${palette.secondary}ee`,
18653
+ outlineColor: `${palette.shadow}cc`,
18654
+ });
18655
+ },
18656
+ };
18657
+ /**
18658
+ * Draws a stylized voxel cuboid with a front pixel texture.
18659
+ *
18660
+ * @param context Canvas 2D context.
18661
+ * @param cuboid Cuboid settings.
18662
+ *
18663
+ * @private helper of `minecraftAvatarVisual`
18664
+ */
18665
+ function drawVoxelCuboid(context, cuboid) {
18666
+ var _a;
18667
+ const { x, y, width, height, depth, frontTexture, topColor, sideColor, outlineColor } = cuboid;
18668
+ const lift = depth * 0.6;
18669
+ context.save();
18670
+ context.beginPath();
18671
+ context.moveTo(x, y);
18672
+ context.lineTo(x + depth, y - lift);
18673
+ context.lineTo(x + width + depth, y - lift);
18674
+ context.lineTo(x + width, y);
18675
+ context.closePath();
18676
+ context.fillStyle = topColor;
18677
+ context.fill();
18678
+ context.restore();
18679
+ context.save();
18680
+ context.beginPath();
18681
+ context.moveTo(x + width, y);
18682
+ context.lineTo(x + width + depth, y - lift);
18683
+ context.lineTo(x + width + depth, y + height - lift);
18684
+ context.lineTo(x + width, y + height);
18685
+ context.closePath();
18686
+ context.fillStyle = sideColor;
18687
+ context.fill();
18688
+ context.restore();
18689
+ const rows = frontTexture.length;
18690
+ const columns = ((_a = frontTexture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
18691
+ const pixelWidth = width / Math.max(columns, 1);
18692
+ const pixelHeight = height / Math.max(rows, 1);
18693
+ context.save();
18694
+ createRoundedRectPath(context, x, y, width, height, width * 0.03);
18695
+ context.clip();
18696
+ for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
18697
+ for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
18698
+ context.fillStyle = frontTexture[rowIndex][columnIndex];
18699
+ context.fillRect(x + columnIndex * pixelWidth, y + rowIndex * pixelHeight, pixelWidth, pixelHeight);
18700
+ }
18701
+ }
18702
+ context.restore();
18703
+ context.strokeStyle = outlineColor;
18704
+ context.lineWidth = Math.max(1.2, width * 0.025);
18705
+ context.beginPath();
18706
+ context.moveTo(x, y);
18707
+ context.lineTo(x + depth, y - lift);
18708
+ context.lineTo(x + width + depth, y - lift);
18709
+ context.lineTo(x + width + depth, y + height - lift);
18710
+ context.lineTo(x + width, y + height);
18711
+ context.lineTo(x, y + height);
18712
+ context.closePath();
18713
+ context.stroke();
18714
+ }
18715
+ /**
18716
+ * Creates the front-face pixel texture for the cube head.
18717
+ *
18718
+ * @param random Seeded random generator.
18719
+ * @param palette Derived avatar palette.
18720
+ * @param hasHeadband Whether the avatar should render a headband row.
18721
+ * @returns 8x8 pixel texture.
18722
+ *
18723
+ * @private helper of `minecraftAvatarVisual`
18724
+ */
18725
+ function createMinecraftFaceTexture(random, palette, hasHeadband) {
18726
+ const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.highlight));
18727
+ const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
18728
+ const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
18729
+ for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
18730
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
18731
+ texture[rowIndex][columnIndex] = hairlineColor;
18732
+ }
18733
+ }
18734
+ texture[2][0] = hairlineColor;
18735
+ texture[2][7] = hairlineColor;
18736
+ texture[3][0] = hairlineColor;
18737
+ texture[3][7] = hairlineColor;
18738
+ if (hasHeadband) {
18739
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
18740
+ texture[2][columnIndex] = palette.accent;
18741
+ }
18742
+ }
18743
+ texture[3][2] = palette.ink;
18744
+ texture[3][5] = palette.ink;
18745
+ texture[4][2] = '#ffffff';
18746
+ texture[4][5] = '#ffffff';
18747
+ texture[5][1] = cheekColor;
18748
+ texture[5][6] = cheekColor;
18749
+ texture[5][3] = palette.shadow;
18750
+ texture[5][4] = palette.shadow;
18751
+ texture[6][3] = palette.shadow;
18752
+ texture[6][4] = palette.shadow;
18753
+ return texture;
18754
+ }
18755
+ /**
18756
+ * Creates the front-face pixel texture for the torso.
18757
+ *
18758
+ * @param random Seeded random generator.
18759
+ * @param palette Derived avatar palette.
18760
+ * @returns 8x8 torso texture.
18761
+ *
18762
+ * @private helper of `minecraftAvatarVisual`
18763
+ */
18764
+ function createMinecraftShirtTexture(random, palette) {
18765
+ const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.primary));
18766
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
18767
+ for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
18768
+ for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
18769
+ texture[rowIndex][columnIndex] = palette.shadow;
18770
+ }
18771
+ }
18772
+ for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
18773
+ texture[rowIndex][3] = stripeColor;
18774
+ texture[rowIndex][4] = stripeColor;
18775
+ }
18776
+ texture[4][1] = palette.accent;
18777
+ texture[4][6] = palette.accent;
18778
+ texture[5][2] = palette.highlight;
18779
+ texture[5][5] = palette.highlight;
18780
+ return texture;
18781
+ }
18782
+
18783
+ /* eslint-disable no-magic-numbers */
18784
+ /**
18785
+ * Octopus avatar visual.
18786
+ *
18787
+ * @private built-in avatar visual
18788
+ */
18789
+ const octopusAvatarVisual = {
18790
+ id: 'octopus',
18791
+ title: 'Octopus',
18792
+ description: 'Playful underwater mascot with cursor-following eyes, animated tentacles, bubbles, and seeded markings.',
18793
+ isAnimated: true,
18794
+ supportsPointerTracking: true,
18795
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
18796
+ const staticRandom = createRandom('octopus-static');
18797
+ const bubbleRandom = createRandom('octopus-bubbles');
18798
+ const bubbleCount = 8;
18799
+ const bubbleRadiusBase = size * 0.02;
18800
+ const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.035;
18801
+ const centerY = size * 0.42 + interaction.bodyOffsetY * size * 0.024;
18802
+ const headRadius = size * (0.19 + staticRandom() * 0.03);
18803
+ const mantleHeight = headRadius * 1.18;
18804
+ const tentacleLength = size * (0.18 + staticRandom() * 0.06);
18805
+ const tentaclePhases = Array.from({ length: 8 }, () => staticRandom() * Math.PI * 2);
18806
+ const spotCount = 3 + Math.floor(staticRandom() * 4);
18807
+ const spotColors = [palette.secondary, palette.accent, palette.highlight];
18808
+ drawAvatarFrame(context, size, palette);
18809
+ const waterGlow = context.createRadialGradient(centerX, size * 0.22, size * 0.06, centerX, size * 0.22, size * 0.58);
18810
+ waterGlow.addColorStop(0, `${palette.highlight}66`);
18811
+ waterGlow.addColorStop(1, `${palette.highlight}00`);
18812
+ context.fillStyle = waterGlow;
18813
+ context.fillRect(0, 0, size, size);
18814
+ for (let bubbleIndex = 0; bubbleIndex < bubbleCount; bubbleIndex++) {
18815
+ const x = size * (0.15 + bubbleRandom() * 0.7);
18816
+ const y = size * (0.12 + bubbleRandom() * 0.68);
18817
+ const radius = bubbleRadiusBase * (0.6 + bubbleRandom() * 2.3);
18818
+ context.beginPath();
18819
+ context.arc(x, y, radius, 0, Math.PI * 2);
18820
+ context.fillStyle = 'rgba(255,255,255,0.08)';
18821
+ context.fill();
18822
+ context.beginPath();
18823
+ context.arc(x - radius * 0.22, y - radius * 0.22, radius * 0.25, 0, Math.PI * 2);
18824
+ context.fillStyle = 'rgba(255,255,255,0.28)';
18825
+ context.fill();
18826
+ }
18827
+ for (let tentacleIndex = 0; tentacleIndex < 8; tentacleIndex++) {
18828
+ const startX = centerX + (tentacleIndex - 3.5) * headRadius * 0.19;
18829
+ const startY = centerY + headRadius * 0.62;
18830
+ const animationPhase = tentaclePhases[tentacleIndex];
18831
+ const sway = Math.sin(timeMs / 520 + animationPhase) * size * 0.03;
18832
+ const endX = startX + (tentacleIndex - 3.5) * size * 0.025 + sway;
18833
+ const endY = startY + tentacleLength + Math.cos(timeMs / 700 + animationPhase) * size * 0.01;
18834
+ const controlX = (startX + endX) / 2 + sway * 0.8;
18835
+ const controlY = startY + tentacleLength * 0.45;
18836
+ const lineWidth = size * (0.042 - tentacleIndex * 0.0022);
18837
+ context.beginPath();
18838
+ context.moveTo(startX, startY);
18839
+ context.quadraticCurveTo(controlX, controlY, endX, endY);
18840
+ context.lineCap = 'round';
18841
+ context.strokeStyle = palette.primary;
18842
+ context.lineWidth = lineWidth;
18843
+ context.stroke();
18844
+ for (let cupIndex = 1; cupIndex <= 3; cupIndex++) {
18845
+ const cupT = cupIndex / 4;
18846
+ const cupX = (1 - cupT) * (1 - cupT) * startX + 2 * (1 - cupT) * cupT * controlX + cupT * cupT * endX;
18847
+ const cupY = (1 - cupT) * (1 - cupT) * startY + 2 * (1 - cupT) * cupT * controlY + cupT * cupT * endY;
18848
+ context.beginPath();
18849
+ context.arc(cupX, cupY, lineWidth * 0.18, 0, Math.PI * 2);
18850
+ context.fillStyle = `${palette.highlight}cc`;
18851
+ context.fill();
18852
+ }
18853
+ }
18854
+ context.save();
18855
+ context.fillStyle = palette.primary;
18856
+ context.shadowColor = `${palette.shadow}88`;
18857
+ context.shadowBlur = size * 0.08;
18858
+ context.beginPath();
18859
+ context.ellipse(centerX, centerY, headRadius, mantleHeight, 0, Math.PI, 0, true);
18860
+ context.lineTo(centerX + headRadius, centerY);
18861
+ context.ellipse(centerX, centerY, headRadius, headRadius * 0.82, 0, 0, Math.PI);
18862
+ context.closePath();
18863
+ context.fill();
18864
+ context.restore();
18865
+ context.beginPath();
18866
+ context.ellipse(centerX, centerY - headRadius * 0.22, headRadius * 0.74, headRadius * 0.42, 0, Math.PI, Math.PI * 2);
18867
+ context.fillStyle = `${palette.highlight}55`;
18868
+ context.fill();
18869
+ for (let spotIndex = 0; spotIndex < spotCount; spotIndex++) {
18870
+ const spotRandom = createRandom(`octopus-spot-${spotIndex}`);
18871
+ const spotX = centerX + (spotRandom() - 0.5) * headRadius * 1.1;
18872
+ const spotY = centerY - headRadius * 0.05 + (spotRandom() - 0.5) * headRadius * 0.9;
18873
+ const spotRadius = headRadius * (0.07 + spotRandom() * 0.07);
18874
+ context.beginPath();
18875
+ context.arc(spotX, spotY, spotRadius, 0, Math.PI * 2);
18876
+ context.fillStyle = pickRandomItem(spotColors, spotRandom);
18877
+ context.fill();
18878
+ }
18879
+ const eyeOffsetX = headRadius * 0.42;
18880
+ const eyeY = centerY + headRadius * 0.04;
18881
+ const eyeRadius = headRadius * 0.22;
18882
+ drawEye(context, centerX - eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, 0);
18883
+ drawEye(context, centerX + eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, Math.PI / 5);
18884
+ context.beginPath();
18885
+ context.arc(centerX - headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
18886
+ context.arc(centerX + headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
18887
+ context.fillStyle = `${palette.accent}44`;
18888
+ context.fill();
18889
+ context.beginPath();
18890
+ context.moveTo(centerX - headRadius * 0.18, centerY + headRadius * 0.24);
18891
+ context.quadraticCurveTo(centerX, centerY + headRadius * 0.42, centerX + headRadius * 0.18, centerY + headRadius * 0.24);
18892
+ context.strokeStyle = palette.shadow;
18893
+ context.lineWidth = size * 0.016;
18894
+ context.lineCap = 'round';
18895
+ context.stroke();
18896
+ },
18897
+ };
18898
+ /**
18899
+ * Draws one expressive octopus eye.
18900
+ *
18901
+ * @param context Canvas 2D context.
18902
+ * @param centerX Eye center X coordinate.
18903
+ * @param centerY Eye center Y coordinate.
18904
+ * @param radius Eye radius.
18905
+ * @param palette Derived avatar palette.
18906
+ * @param timeMs Current animation time in milliseconds.
18907
+ * @param interaction Smoothed avatar interaction state.
18908
+ * @param phase Seed-based phase offset.
18909
+ *
18910
+ * @private helper of `octopusAvatarVisual`
18911
+ */
18912
+ function drawEye(context, centerX, centerY, radius, palette, timeMs, interaction, phase) {
18913
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
18914
+ radiusX: radius,
18915
+ radiusY: radius,
18916
+ timeMs,
18917
+ phase,
18918
+ interaction,
18919
+ autonomousDriftRatioX: 0.05,
18920
+ autonomousDriftRatioY: 0.03,
18921
+ });
18922
+ context.beginPath();
18923
+ context.arc(centerX, centerY, radius, 0, Math.PI * 2);
18924
+ context.fillStyle = '#ffffff';
18925
+ context.fill();
18926
+ context.beginPath();
18927
+ context.arc(centerX + pupilOffsetX, centerY + pupilOffsetY, radius * 0.45, 0, Math.PI * 2);
18928
+ context.fillStyle = palette.ink;
18929
+ context.fill();
18930
+ context.beginPath();
18931
+ context.arc(centerX + pupilOffsetX - radius * 0.12, centerY + pupilOffsetY - radius * 0.12, radius * 0.15, 0, Math.PI * 2);
18932
+ context.fillStyle = '#ffffff';
18933
+ context.fill();
18934
+ context.beginPath();
18935
+ context.arc(centerX, centerY, radius, 0, Math.PI * 2);
18936
+ context.strokeStyle = palette.shadow;
18937
+ context.lineWidth = radius * 0.18;
18938
+ context.stroke();
18939
+ }
18940
+
18941
+ /* eslint-disable no-magic-numbers */
18942
+ /**
18943
+ * Octopus2 avatar visual.
18944
+ *
18945
+ * @private built-in avatar visual
18946
+ */
18947
+ const octopus2AvatarVisual = {
18948
+ id: 'octopus2',
18949
+ title: 'Octopus2',
18950
+ description: 'Organic alien octopus rendered as one continuously morphing blob with responsive luminous eyes.',
18951
+ isAnimated: true,
18952
+ supportsPointerTracking: true,
18953
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
18954
+ const staticRandom = createRandom('octopus2-static');
18955
+ const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.042;
18956
+ const centerY = size * (0.48 + staticRandom() * 0.03) + interaction.bodyOffsetY * size * 0.028;
18957
+ const bodyRadius = size * (0.25 + staticRandom() * 0.035);
18958
+ const horizontalStretch = 1.04 + staticRandom() * 0.16;
18959
+ const verticalStretch = 0.94 + staticRandom() * 0.12;
18960
+ const mantleLift = size * (0.075 + staticRandom() * 0.025);
18961
+ const lowerDrop = size * (0.05 + staticRandom() * 0.02);
18962
+ const tentacleDepth = size * (0.08 + staticRandom() * 0.03);
18963
+ const wobbleAmplitude = size * (0.014 + staticRandom() * 0.008);
18964
+ const lobeCount = 6 + Math.floor(staticRandom() * 3);
18965
+ const shapePhase = staticRandom() * Math.PI * 2;
18966
+ const bodyPoints = createOrganicOctopusBodyPoints({
18967
+ centerX,
18968
+ centerY,
18969
+ bodyRadius,
18970
+ horizontalStretch,
18971
+ verticalStretch,
18972
+ mantleLift,
18973
+ lowerDrop,
18974
+ tentacleDepth,
18975
+ wobbleAmplitude,
18976
+ lobeCount,
18977
+ shapePhase,
18978
+ timeMs,
18979
+ });
18980
+ drawAvatarFrame(context, size, palette);
18981
+ const hazeGradient = context.createRadialGradient(centerX, size * 0.22, size * 0.05, centerX, centerY, size * 0.6);
18982
+ hazeGradient.addColorStop(0, `${palette.highlight}4d`);
18983
+ hazeGradient.addColorStop(0.45, `${palette.accent}24`);
18984
+ hazeGradient.addColorStop(1, `${palette.highlight}00`);
18985
+ context.fillStyle = hazeGradient;
18986
+ context.fillRect(0, 0, size, size);
18987
+ const rimGlowGradient = context.createRadialGradient(centerX, centerY + size * 0.08, size * 0.14, centerX, centerY, size * 0.5);
18988
+ rimGlowGradient.addColorStop(0, `${palette.secondary}26`);
18989
+ rimGlowGradient.addColorStop(1, `${palette.secondary}00`);
18990
+ context.fillStyle = rimGlowGradient;
18991
+ context.fillRect(0, 0, size, size);
18992
+ context.save();
18993
+ traceSmoothClosedPath(context, bodyPoints);
18994
+ const bodyGradient = context.createRadialGradient(centerX - size * 0.09, centerY - size * 0.18, size * 0.06, centerX, centerY + size * 0.14, size * 0.5);
18995
+ bodyGradient.addColorStop(0, palette.highlight);
18996
+ bodyGradient.addColorStop(0.25, palette.secondary);
18997
+ bodyGradient.addColorStop(0.68, palette.primary);
18998
+ bodyGradient.addColorStop(1, palette.shadow);
18999
+ context.fillStyle = bodyGradient;
19000
+ context.shadowColor = `${palette.shadow}aa`;
19001
+ context.shadowBlur = size * 0.08;
19002
+ context.shadowOffsetY = size * 0.018;
19003
+ context.fill();
19004
+ context.restore();
19005
+ context.save();
19006
+ traceSmoothClosedPath(context, bodyPoints);
19007
+ context.clip();
19008
+ const interiorGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.22, centerX, centerY + size * 0.36);
19009
+ interiorGlowGradient.addColorStop(0, `${palette.highlight}59`);
19010
+ interiorGlowGradient.addColorStop(0.45, `${palette.accent}1a`);
19011
+ interiorGlowGradient.addColorStop(1, `${palette.shadow}00`);
19012
+ context.fillStyle = interiorGlowGradient;
19013
+ context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.76);
19014
+ drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase);
19015
+ drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs);
19016
+ context.restore();
19017
+ context.save();
19018
+ traceSmoothClosedPath(context, bodyPoints);
19019
+ context.strokeStyle = `${palette.highlight}59`;
19020
+ context.lineWidth = size * 0.014;
19021
+ context.stroke();
19022
+ context.restore();
19023
+ const eyeOffsetX = size * 0.13;
19024
+ const eyeCenterY = centerY - size * 0.02;
19025
+ const eyeRadiusX = size * 0.072;
19026
+ const eyeRadiusY = size * 0.086;
19027
+ drawAlienEye(context, centerX - eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase, interaction);
19028
+ drawAlienEye(context, centerX + eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase + Math.PI / 5, interaction);
19029
+ context.beginPath();
19030
+ context.moveTo(centerX - size * 0.08, centerY + size * 0.12);
19031
+ 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);
19032
+ context.strokeStyle = `${palette.ink}b3`;
19033
+ context.lineWidth = size * 0.013;
19034
+ context.lineCap = 'round';
19035
+ context.stroke();
19036
+ context.beginPath();
19037
+ context.ellipse(centerX, centerY - size * 0.13, size * 0.16, size * 0.065, 0, Math.PI, Math.PI * 2);
19038
+ context.fillStyle = `${palette.highlight}33`;
19039
+ context.fill();
19040
+ },
19041
+ };
19042
+ /**
19043
+ * Draws translucent inner filaments clipped inside the main body mesh.
19044
+ *
19045
+ * @param context Canvas 2D context.
19046
+ * @param centerX Body center X coordinate.
19047
+ * @param centerY Body center Y coordinate.
19048
+ * @param size Canvas size in CSS pixels.
19049
+ * @param palette Derived avatar palette.
19050
+ * @param timeMs Current animation time in milliseconds.
19051
+ * @param shapePhase Seed-based phase offset.
19052
+ *
19053
+ * @private helper of `octopus2AvatarVisual`
19054
+ */
19055
+ function drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase) {
19056
+ for (let filamentIndex = 0; filamentIndex < 5; filamentIndex++) {
19057
+ const horizontalOffset = (filamentIndex - 2) * size * 0.075;
19058
+ const sway = Math.sin(timeMs / 720 + filamentIndex * 0.8 + shapePhase) * size * 0.028;
19059
+ context.beginPath();
19060
+ context.moveTo(centerX + horizontalOffset * 0.35, centerY - size * 0.11);
19061
+ 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);
19062
+ context.strokeStyle = filamentIndex % 2 === 0 ? `${palette.highlight}29` : `${palette.accent}24`;
19063
+ context.lineWidth = size * (0.01 + filamentIndex * 0.0008);
19064
+ context.lineCap = 'round';
19065
+ context.stroke();
19066
+ }
19067
+ }
19068
+ /**
19069
+ * Draws soft sucker-like highlights in the lower body area.
19070
+ *
19071
+ * @param context Canvas 2D context.
19072
+ * @param centerX Body center X coordinate.
19073
+ * @param centerY Body center Y coordinate.
19074
+ * @param size Canvas size in CSS pixels.
19075
+ * @param palette Derived avatar palette.
19076
+ * @param createRandom Seeded random factory scoped to the avatar.
19077
+ * @param timeMs Current animation time in milliseconds.
19078
+ *
19079
+ * @private helper of `octopus2AvatarVisual`
19080
+ */
19081
+ function drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs) {
19082
+ const suckerRandom = createRandom('octopus2-suckers');
19083
+ for (let suckerIndex = 0; suckerIndex < 12; suckerIndex++) {
19084
+ const x = centerX + (suckerRandom() - 0.5) * size * 0.36;
19085
+ const y = centerY + size * (0.11 + suckerRandom() * 0.22);
19086
+ const radiusX = size * (0.015 + suckerRandom() * 0.012);
19087
+ const radiusY = radiusX * (0.72 + suckerRandom() * 0.34);
19088
+ const rotation = suckerRandom() * Math.PI + Math.sin(timeMs / 1100 + suckerIndex) * 0.08;
19089
+ context.beginPath();
19090
+ context.ellipse(x, y, radiusX, radiusY, rotation, 0, Math.PI * 2);
19091
+ context.fillStyle = `${palette.highlight}24`;
19092
+ context.fill();
19093
+ context.strokeStyle = `${palette.highlight}40`;
19094
+ context.lineWidth = Math.max(1, size * 0.005);
19095
+ context.stroke();
19096
+ }
19097
+ }
19098
+ /**
19099
+ * Draws one luminous alien eye on top of the organic octopus mesh.
19100
+ *
19101
+ * @param context Canvas 2D context.
19102
+ * @param centerX Eye center X coordinate.
19103
+ * @param centerY Eye center Y coordinate.
19104
+ * @param radiusX Eye horizontal radius.
19105
+ * @param radiusY Eye vertical radius.
19106
+ * @param palette Derived avatar palette.
19107
+ * @param timeMs Current animation time in milliseconds.
19108
+ * @param phase Seed-based animation phase.
19109
+ * @param interaction Smoothed avatar interaction state.
19110
+ *
19111
+ * @private helper of `octopus2AvatarVisual`
19112
+ */
19113
+ function drawAlienEye(context, centerX, centerY, radiusX, radiusY, palette, timeMs, phase, interaction) {
19114
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
19115
+ radiusX,
19116
+ radiusY,
19117
+ timeMs,
19118
+ phase,
19119
+ interaction,
19120
+ autonomousDriftRatioY: 0.1,
19121
+ });
19122
+ context.save();
19123
+ context.beginPath();
19124
+ context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
19125
+ context.fillStyle = '#f8fbff';
19126
+ context.fill();
19127
+ context.clip();
19128
+ const irisGradient = context.createRadialGradient(centerX - radiusX * 0.18, centerY - radiusY * 0.22, radiusX * 0.05, centerX, centerY, radiusX * 0.9);
19129
+ irisGradient.addColorStop(0, palette.highlight);
19130
+ irisGradient.addColorStop(0.55, palette.secondary);
19131
+ irisGradient.addColorStop(1, palette.shadow);
19132
+ context.beginPath();
19133
+ context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.68, radiusY * 0.72, 0, 0, Math.PI * 2);
19134
+ context.fillStyle = irisGradient;
19135
+ context.fill();
19136
+ context.beginPath();
19137
+ context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.16, radiusY * 0.48, 0, 0, Math.PI * 2);
19138
+ context.fillStyle = palette.ink;
19139
+ context.fill();
19140
+ context.beginPath();
19141
+ context.ellipse(centerX + pupilOffsetX - radiusX * 0.18, centerY + pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
19142
+ context.fillStyle = '#ffffff';
19143
+ context.fill();
19144
+ context.restore();
19145
+ context.beginPath();
19146
+ context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
19147
+ context.strokeStyle = `${palette.shadow}cc`;
19148
+ context.lineWidth = radiusX * 0.2;
19149
+ context.stroke();
19150
+ }
19151
+
19152
+ /* eslint-disable no-magic-numbers */
19153
+ /**
19154
+ * Builds one deterministic morphology profile for `Octopus3`.
19155
+ *
19156
+ * @param createRandom Seeded random factory scoped to the current avatar.
19157
+ * @returns Stable morphology profile.
19158
+ *
19159
+ * @private helper of `octopus3AvatarVisual`
19160
+ */
19161
+ function createOctopus3MorphologyProfile(createRandom) {
19162
+ const bodyRandom = createRandom('octopus3-body-profile');
19163
+ const faceRandom = createRandom('octopus3-face-profile');
19164
+ const detailRandom = createRandom('octopus3-detail-profile');
19165
+ const bodyFamilyRoll = bodyRandom();
19166
+ let bodyFamily;
19167
+ let body;
19168
+ let tentacles;
19169
+ if (bodyFamilyRoll < 0.34) {
19170
+ bodyFamily = 'lantern';
19171
+ body = {
19172
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.018, 0.018),
19173
+ centerYRatio: resolveSeededRange(bodyRandom, 0.39, 0.435),
19174
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.19, 0.23),
19175
+ horizontalStretch: resolveSeededRange(bodyRandom, 0.94, 1.08),
19176
+ verticalStretch: resolveSeededRange(bodyRandom, 1.02, 1.18),
19177
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.115, 0.148),
19178
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.042, 0.066),
19179
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.018, 0.03),
19180
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.009, 0.017),
19181
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 4, 6),
19182
+ pointCount: resolveSeededIntegerRange(bodyRandom, 38, 42),
19183
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.18, 0.23),
19184
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.075),
19185
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.14, 0.18),
19186
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.045, 0.062),
19187
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.165, -0.135),
19188
+ };
19189
+ tentacles = {
19190
+ count: resolveSeededIntegerRange(bodyRandom, 7, 10),
19191
+ flowLengthScale: resolveSeededRange(bodyRandom, 1.08, 1.34),
19192
+ lateralReachScale: resolveSeededRange(bodyRandom, 0.72, 0.94),
19193
+ tipReachScale: resolveSeededRange(bodyRandom, 0.82, 1.06),
19194
+ baseWidthScale: resolveSeededRange(bodyRandom, 0.82, 0.98),
19195
+ tipWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
19196
+ rootSpreadScale: resolveSeededRange(bodyRandom, 0.76, 0.94),
19197
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.82, 1),
19198
+ swayScale: resolveSeededRange(bodyRandom, 0.82, 1.02),
19199
+ };
19200
+ }
19201
+ else if (bodyFamilyRoll < 0.68) {
19202
+ bodyFamily = 'drifter';
19203
+ body = {
19204
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.025, 0.025),
19205
+ centerYRatio: resolveSeededRange(bodyRandom, 0.425, 0.46),
19206
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.175, 0.215),
19207
+ horizontalStretch: resolveSeededRange(bodyRandom, 1.22, 1.42),
19208
+ verticalStretch: resolveSeededRange(bodyRandom, 0.82, 0.92),
19209
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.092, 0.115),
19210
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.02, 0.036),
19211
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
19212
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.013, 0.022),
19213
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 7, 9),
19214
+ pointCount: resolveSeededIntegerRange(bodyRandom, 40, 46),
19215
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.24, 0.28),
19216
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.06, 0.082),
19217
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.17, 0.22),
19218
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.038, 0.055),
19219
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.14, -0.11),
19220
+ };
19221
+ tentacles = {
19222
+ count: resolveSeededIntegerRange(bodyRandom, 10, 13),
19223
+ flowLengthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
19224
+ lateralReachScale: resolveSeededRange(bodyRandom, 1.18, 1.42),
19225
+ tipReachScale: resolveSeededRange(bodyRandom, 1.12, 1.42),
19226
+ baseWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.06),
19227
+ tipWidthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
19228
+ rootSpreadScale: resolveSeededRange(bodyRandom, 1.12, 1.32),
19229
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.92, 1.14),
19230
+ swayScale: resolveSeededRange(bodyRandom, 1.04, 1.22),
19231
+ };
19232
+ }
19233
+ else {
19234
+ bodyFamily = 'rounded';
19235
+ body = {
19236
+ centerXJitterRatio: resolveSeededRange(bodyRandom, -0.02, 0.02),
19237
+ centerYRatio: resolveSeededRange(bodyRandom, 0.398, 0.442),
19238
+ bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.208, 0.248),
19239
+ horizontalStretch: resolveSeededRange(bodyRandom, 1.06, 1.22),
19240
+ verticalStretch: resolveSeededRange(bodyRandom, 0.9, 1.01),
19241
+ mantleLiftRatio: resolveSeededRange(bodyRandom, 0.1, 0.128),
19242
+ lowerDropRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
19243
+ tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.038, 0.06),
19244
+ wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.014, 0.024),
19245
+ lobeCount: resolveSeededIntegerRange(bodyRandom, 5, 8),
19246
+ pointCount: resolveSeededIntegerRange(bodyRandom, 39, 44),
19247
+ shadowWidthRatio: resolveSeededRange(bodyRandom, 0.2, 0.25),
19248
+ shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.08),
19249
+ crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.16, 0.2),
19250
+ crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.05, 0.07),
19251
+ crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.155, -0.122),
19252
+ };
19253
+ tentacles = {
19254
+ count: resolveSeededIntegerRange(bodyRandom, 8, 12),
19255
+ flowLengthScale: resolveSeededRange(bodyRandom, 0.94, 1.16),
19256
+ lateralReachScale: resolveSeededRange(bodyRandom, 0.9, 1.14),
19257
+ tipReachScale: resolveSeededRange(bodyRandom, 0.96, 1.22),
19258
+ baseWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.2),
19259
+ tipWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.22),
19260
+ rootSpreadScale: resolveSeededRange(bodyRandom, 0.94, 1.08),
19261
+ startYOffsetScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
19262
+ swayScale: resolveSeededRange(bodyRandom, 0.9, 1.1),
19263
+ };
19264
+ }
19265
+ const faceFamilyRoll = faceRandom();
19266
+ let faceFamily;
19267
+ let face;
19268
+ if (faceFamilyRoll < 0.34) {
19269
+ faceFamily = 'watchful';
19270
+ face = {
19271
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.118, 0.152),
19272
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.026, -0.002),
19273
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.05, 0.062),
19274
+ eyeHeightRatio: resolveSeededRange(faceRandom, 1.18, 1.38),
19275
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.16, 0.28),
19276
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.02, 0.06),
19277
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
19278
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.086, 0.104),
19279
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.126, 0.15),
19280
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.006, 0.006),
19281
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.002, 0.002),
19282
+ eyeStyle: {
19283
+ irisScale: resolveSeededRange(faceRandom, 1, 1.1),
19284
+ pupilWidthScale: resolveSeededRange(faceRandom, 0.86, 1.02),
19285
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.94, 1.08),
19286
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.96, 1.12),
19287
+ upperLidInsetRatio: resolveSeededRange(faceRandom, 0.08, 0.14),
19288
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.12, 0.22),
19289
+ },
19290
+ };
19291
+ }
19292
+ else if (faceFamilyRoll < 0.68) {
19293
+ faceFamily = 'sleepy';
19294
+ face = {
19295
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.092, 0.124),
19296
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.002, 0.024),
19297
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
19298
+ eyeHeightRatio: resolveSeededRange(faceRandom, 0.96, 1.14),
19299
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.1, 0.22),
19300
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.01, 0.05),
19301
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.066, 0.086),
19302
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.094, 0.118),
19303
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.118, 0.145),
19304
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
19305
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
19306
+ eyeStyle: {
19307
+ irisScale: resolveSeededRange(faceRandom, 0.9, 1),
19308
+ pupilWidthScale: resolveSeededRange(faceRandom, 1, 1.18),
19309
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.78, 0.92),
19310
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.7, 0.88),
19311
+ upperLidInsetRatio: resolveSeededRange(faceRandom, -0.02, 0.06),
19312
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.22, 0.34),
19313
+ },
19314
+ };
19315
+ }
19316
+ else {
19317
+ faceFamily = 'mischief';
19318
+ face = {
19319
+ eyeSpacingRatio: resolveSeededRange(faceRandom, 0.086, 0.114),
19320
+ eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.01),
19321
+ eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.046, 0.06),
19322
+ eyeHeightRatio: resolveSeededRange(faceRandom, 1.08, 1.28),
19323
+ eyeRotationRange: resolveSeededRange(faceRandom, 0.28, 0.44),
19324
+ eyeTiltBias: resolveSeededRange(faceRandom, 0.12, 0.22),
19325
+ mouthWidthRatio: resolveSeededRange(faceRandom, 0.052, 0.074),
19326
+ mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.082, 0.1),
19327
+ mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.116, 0.15),
19328
+ mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.018),
19329
+ mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.01, 0.01),
19330
+ eyeStyle: {
19331
+ irisScale: resolveSeededRange(faceRandom, 1.04, 1.12),
19332
+ pupilWidthScale: resolveSeededRange(faceRandom, 0.72, 0.9),
19333
+ pupilHeightScale: resolveSeededRange(faceRandom, 0.96, 1.14),
19334
+ upperLidArchRatio: resolveSeededRange(faceRandom, 0.88, 1.02),
19335
+ upperLidInsetRatio: resolveSeededRange(faceRandom, 0.04, 0.12),
19336
+ lowerLidOpacity: resolveSeededRange(faceRandom, 0.08, 0.18),
19337
+ },
19338
+ };
19339
+ }
19340
+ return {
19341
+ bodyFamily,
19342
+ faceFamily,
19343
+ body,
19344
+ tentacles,
19345
+ face,
19346
+ details: {
19347
+ mantleCurrentCount: resolveSeededIntegerRange(detailRandom, 4, 8),
19348
+ mantleNodeCount: resolveSeededIntegerRange(detailRandom, 3, 7),
19349
+ },
19350
+ };
19351
+ }
19352
+ /**
19353
+ * Resolves one seeded floating-point number inside the provided range.
19354
+ *
19355
+ * @param random Seeded random generator.
19356
+ * @param minimumValue Inclusive lower bound.
19357
+ * @param maximumValue Inclusive upper bound.
19358
+ * @returns Seeded number within the range.
19359
+ *
19360
+ * @private helper of `octopus3AvatarVisual`
19361
+ */
19362
+ function resolveSeededRange(random, minimumValue, maximumValue) {
19363
+ return minimumValue + random() * (maximumValue - minimumValue);
19364
+ }
19365
+ /**
19366
+ * Resolves one seeded integer inside the provided inclusive range.
19367
+ *
19368
+ * @param random Seeded random generator.
19369
+ * @param minimumValue Inclusive lower bound.
19370
+ * @param maximumValue Inclusive upper bound.
19371
+ * @returns Seeded integer within the range.
19372
+ *
19373
+ * @private helper of `octopus3AvatarVisual`
19374
+ */
19375
+ function resolveSeededIntegerRange(random, minimumValue, maximumValue) {
19376
+ return minimumValue + Math.floor(random() * (maximumValue - minimumValue + 1));
19377
+ }
19378
+ /**
19379
+ * Converts an opacity ratio into a two-digit hexadecimal alpha suffix.
19380
+ *
19381
+ * @param opacity Opacity ratio in the range `[0, 1]`.
19382
+ * @returns Two-digit hexadecimal alpha string.
19383
+ *
19384
+ * @private helper of `octopus3AvatarVisual`
19385
+ */
19386
+ function formatAlphaHex(opacity) {
19387
+ return Math.round(Math.min(1, Math.max(0, opacity)) * 255)
19388
+ .toString(16)
19389
+ .padStart(2, '0');
19390
+ }
19391
+ /**
19392
+ * Octopus3 avatar visual.
19393
+ *
19394
+ * @private built-in avatar visual
19395
+ */
19396
+ const octopus3AvatarVisual = {
19397
+ id: 'octopus3',
19398
+ title: 'Octopus3',
19399
+ description: 'Gelatinous alien octopus with a morphing mantle, responsive eyes, and visible ribbon tentacles.',
19400
+ isAnimated: true,
19401
+ supportsPointerTracking: true,
19402
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
19403
+ const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
19404
+ const animationRandom = createRandom('octopus3-animation-profile');
19405
+ const eyeRandom = createRandom('octopus3-eye-profile');
19406
+ const centerX = size * (0.5 + morphologyProfile.body.centerXJitterRatio) + interaction.bodyOffsetX * size * 0.05;
19407
+ const centerY = size * morphologyProfile.body.centerYRatio + interaction.bodyOffsetY * size * 0.035;
19408
+ const bodyRadius = size * morphologyProfile.body.bodyRadiusRatio;
19409
+ const horizontalStretch = morphologyProfile.body.horizontalStretch;
19410
+ const verticalStretch = morphologyProfile.body.verticalStretch;
19411
+ const mantleLift = size * morphologyProfile.body.mantleLiftRatio;
19412
+ const lowerDrop = size * morphologyProfile.body.lowerDropRatio;
19413
+ const tentacleDepth = size * morphologyProfile.body.tentacleDepthRatio;
19414
+ const wobbleAmplitude = size * morphologyProfile.body.wobbleAmplitudeRatio;
19415
+ const lobeCount = morphologyProfile.body.lobeCount;
19416
+ const shapePhase = animationRandom() * Math.PI * 2;
19417
+ const eyeSpacing = size * morphologyProfile.face.eyeSpacingRatio;
19418
+ const eyeCenterY = centerY + size * morphologyProfile.face.eyeCenterYOffsetRatio;
19419
+ const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio;
19420
+ const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio;
19421
+ const bodyPoints = createOrganicOctopusBodyPoints({
19422
+ centerX,
19423
+ centerY,
19424
+ bodyRadius,
19425
+ horizontalStretch,
19426
+ verticalStretch,
19427
+ mantleLift,
19428
+ lowerDrop,
19429
+ tentacleDepth,
19430
+ wobbleAmplitude,
19431
+ lobeCount,
19432
+ shapePhase,
19433
+ timeMs,
19434
+ pointCount: morphologyProfile.body.pointCount,
19435
+ });
19436
+ const tentacleShapes = createOrganicOctopusTentacleShapes({
19437
+ size,
19438
+ centerX,
19439
+ centerY,
19440
+ bodyRadius,
19441
+ horizontalStretch,
19442
+ tentacleCount: morphologyProfile.tentacles.count,
19443
+ shapePhase,
19444
+ createRandom,
19445
+ timeMs,
19446
+ saltPrefix: 'octopus3',
19447
+ bodyPoints,
19448
+ variation: {
19449
+ flowLengthScale: morphologyProfile.tentacles.flowLengthScale,
19450
+ lateralReachScale: morphologyProfile.tentacles.lateralReachScale,
19451
+ tipReachScale: morphologyProfile.tentacles.tipReachScale,
19452
+ baseWidthScale: morphologyProfile.tentacles.baseWidthScale,
19453
+ tipWidthScale: morphologyProfile.tentacles.tipWidthScale,
19454
+ rootSpreadScale: morphologyProfile.tentacles.rootSpreadScale,
19455
+ startYOffsetScale: morphologyProfile.tentacles.startYOffsetScale,
19456
+ swayScale: morphologyProfile.tentacles.swayScale,
19457
+ },
19458
+ });
19459
+ drawAvatarFrame(context, size, palette);
19460
+ drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile);
19461
+ context.beginPath();
19462
+ context.ellipse(centerX, centerY + size * 0.25, size * morphologyProfile.body.shadowWidthRatio, size * morphologyProfile.body.shadowHeightRatio, 0, 0, Math.PI * 2);
19463
+ context.fillStyle = `${palette.shadow}33`;
19464
+ context.fill();
19465
+ for (const tentacleShape of tentacleShapes) {
19466
+ drawTentacleRibbon(context, tentacleShape, palette);
19467
+ }
19468
+ context.save();
19469
+ traceSmoothClosedPath(context, bodyPoints);
19470
+ const bodyGradient = context.createRadialGradient(centerX - size * 0.1, centerY - size * 0.18, size * 0.04, centerX, centerY + size * 0.16, size * 0.54);
19471
+ bodyGradient.addColorStop(0, palette.highlight);
19472
+ bodyGradient.addColorStop(0.18, palette.secondary);
19473
+ bodyGradient.addColorStop(0.55, palette.primary);
19474
+ bodyGradient.addColorStop(1, palette.shadow);
19475
+ context.fillStyle = bodyGradient;
19476
+ context.shadowColor = `${palette.shadow}aa`;
19477
+ context.shadowBlur = size * 0.08;
19478
+ context.shadowOffsetY = size * 0.02;
19479
+ context.fill();
19480
+ context.restore();
19481
+ context.save();
19482
+ traceSmoothClosedPath(context, bodyPoints);
19483
+ context.clip();
19484
+ const innerGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.24, centerX, centerY + size * 0.26);
19485
+ innerGlowGradient.addColorStop(0, `${palette.highlight}66`);
19486
+ innerGlowGradient.addColorStop(0.4, `${palette.secondary}26`);
19487
+ innerGlowGradient.addColorStop(1, `${palette.shadow}00`);
19488
+ context.fillStyle = innerGlowGradient;
19489
+ context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.72);
19490
+ drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile);
19491
+ drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile);
19492
+ context.restore();
19493
+ context.save();
19494
+ traceSmoothClosedPath(context, bodyPoints);
19495
+ context.strokeStyle = `${palette.highlight}73`;
19496
+ context.lineWidth = size * 0.013;
19497
+ context.stroke();
19498
+ context.restore();
19499
+ context.beginPath();
19500
+ context.ellipse(centerX, centerY + size * morphologyProfile.body.crownHighlightYOffsetRatio, size * morphologyProfile.body.crownHighlightWidthRatio, size * morphologyProfile.body.crownHighlightHeightRatio, 0, Math.PI, Math.PI * 2);
19501
+ context.fillStyle = `${palette.highlight}3d`;
19502
+ context.fill();
19503
+ drawSeededEye(context, centerX - eyeSpacing, eyeCenterY, eyeRadiusX, eyeRadiusY, -morphologyProfile.face.eyeTiltBias + (eyeRandom() - 0.5) * morphologyProfile.face.eyeRotationRange, palette, timeMs, shapePhase, interaction, morphologyProfile.face.eyeStyle);
19504
+ 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);
19505
+ const mouthHalfWidth = size * morphologyProfile.face.mouthWidthRatio;
19506
+ const mouthY = centerY + size * morphologyProfile.face.mouthYOffsetRatio;
19507
+ const mouthCornerTilt = size * morphologyProfile.face.mouthCornerTiltRatio;
19508
+ context.beginPath();
19509
+ context.moveTo(centerX - mouthHalfWidth, mouthY - mouthCornerTilt);
19510
+ context.quadraticCurveTo(centerX + size * morphologyProfile.face.mouthCenterOffsetRatio, centerY +
19511
+ size * (morphologyProfile.face.mouthCurveDepthRatio + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
19512
+ interaction.gazeY * size * 0.012, centerX + mouthHalfWidth, mouthY + mouthCornerTilt);
19513
+ context.strokeStyle = `${palette.ink}b3`;
19514
+ context.lineWidth = size * 0.012;
19515
+ context.lineCap = 'round';
19516
+ context.stroke();
19517
+ },
19518
+ };
19519
+ /**
19520
+ * Draws the deep-sea glow around the Octopus3 silhouette.
19521
+ *
19522
+ * @param context Canvas 2D context.
19523
+ * @param size Canvas size in CSS pixels.
19524
+ * @param palette Derived avatar palette.
19525
+ * @param centerX Body center X coordinate.
19526
+ * @param centerY Body center Y coordinate.
19527
+ * @param timeMs Current animation time in milliseconds.
19528
+ * @param shapePhase Seed-based phase offset.
19529
+ * @param morphologyProfile Seeded morphology profile.
19530
+ *
19531
+ * @private helper of `octopus3AvatarVisual`
19532
+ */
19533
+ function drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile) {
19534
+ 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));
19535
+ haloGradient.addColorStop(0, `${palette.highlight}5c`);
19536
+ haloGradient.addColorStop(0.35, `${palette.accent}26`);
19537
+ haloGradient.addColorStop(1, `${palette.highlight}00`);
19538
+ context.fillStyle = haloGradient;
19539
+ context.fillRect(0, 0, size, size);
19540
+ 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));
19541
+ lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
19542
+ lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
19543
+ context.fillStyle = lowerGlowGradient;
19544
+ context.fillRect(0, 0, size, size);
19545
+ }
19546
+ /**
19547
+ * Draws one ribbon tentacle with a filled organic profile and visible sucker highlights.
19548
+ *
19549
+ * @param context Canvas 2D context.
19550
+ * @param tentacleShape Deterministic tentacle descriptor.
19551
+ * @param palette Derived avatar palette.
19552
+ *
19553
+ * @private helper of `octopus3AvatarVisual`
19554
+ */
19555
+ function drawTentacleRibbon(context, tentacleShape, palette) {
19556
+ const ribbonPoints = sampleOrganicTentacleRibbonPoints(tentacleShape);
19557
+ const gradient = context.createLinearGradient(tentacleShape.startPoint.x, tentacleShape.startPoint.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
19558
+ gradient.addColorStop(0, tentacleShape.colorBias < 0.35 ? palette.secondary : palette.primary);
19559
+ gradient.addColorStop(0.58, palette.primary);
19560
+ gradient.addColorStop(1, tentacleShape.colorBias > 0.65 ? palette.highlight : palette.accent);
19561
+ context.save();
19562
+ traceTentacleRibbonPath(context, ribbonPoints);
19563
+ context.fillStyle = gradient;
19564
+ context.shadowColor = `${palette.shadow}80`;
19565
+ context.shadowBlur = tentacleShape.baseWidth * 1.2;
19566
+ context.shadowOffsetY = tentacleShape.baseWidth * 0.2;
19567
+ context.fill();
19568
+ context.restore();
19569
+ context.save();
19570
+ traceTentacleRibbonPath(context, ribbonPoints);
19571
+ context.strokeStyle = tentacleShape.highlightBias > 0.5 ? `${palette.highlight}52` : `${palette.highlight}38`;
19572
+ context.lineWidth = Math.max(1, tentacleShape.baseWidth * 0.12);
19573
+ context.stroke();
19574
+ context.restore();
19575
+ context.beginPath();
19576
+ context.moveTo(tentacleShape.startPoint.x, tentacleShape.startPoint.y);
19577
+ context.bezierCurveTo(tentacleShape.controlPointOne.x, tentacleShape.controlPointOne.y, tentacleShape.controlPointTwo.x, tentacleShape.controlPointTwo.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
19578
+ context.strokeStyle = `${palette.highlight}2e`;
19579
+ context.lineWidth = Math.max(1, tentacleShape.tipWidth * 0.9);
19580
+ context.lineCap = 'round';
19581
+ context.stroke();
19582
+ drawTentacleSuckers(context, tentacleShape, palette);
19583
+ }
19584
+ /**
19585
+ * Traces a closed ribbon path from sampled tentacle points.
19586
+ *
19587
+ * @param context Canvas 2D context.
19588
+ * @param ribbonPoints Sampled ribbon points.
19589
+ *
19590
+ * @private helper of `octopus3AvatarVisual`
19591
+ */
19592
+ function traceTentacleRibbonPath(context, ribbonPoints) {
19593
+ const firstRibbonPoint = ribbonPoints[0];
19594
+ context.beginPath();
19595
+ context.moveTo(firstRibbonPoint.x + firstRibbonPoint.normalX * firstRibbonPoint.width, firstRibbonPoint.y + firstRibbonPoint.normalY * firstRibbonPoint.width);
19596
+ for (const ribbonPoint of ribbonPoints.slice(1)) {
19597
+ context.lineTo(ribbonPoint.x + ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y + ribbonPoint.normalY * ribbonPoint.width);
19598
+ }
19599
+ for (const ribbonPoint of [...ribbonPoints].reverse()) {
19600
+ context.lineTo(ribbonPoint.x - ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y - ribbonPoint.normalY * ribbonPoint.width);
19601
+ }
19602
+ context.closePath();
19603
+ }
19604
+ /**
19605
+ * Draws a row of soft sucker highlights along one side of the ribbon tentacle.
19606
+ *
19607
+ * @param context Canvas 2D context.
19608
+ * @param tentacleShape Deterministic tentacle descriptor.
19609
+ * @param palette Derived avatar palette.
19610
+ *
19611
+ * @private helper of `octopus3AvatarVisual`
19612
+ */
19613
+ function drawTentacleSuckers(context, tentacleShape, palette) {
19614
+ const undersideDirection = tentacleShape.endPoint.x >= tentacleShape.startPoint.x ? -1 : 1;
19615
+ for (let suckerIndex = 0; suckerIndex < 4; suckerIndex++) {
19616
+ const progress = 0.22 + suckerIndex * 0.17;
19617
+ const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
19618
+ const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.03));
19619
+ const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.03));
19620
+ const tangentX = nextPoint.x - previousPoint.x;
19621
+ const tangentY = nextPoint.y - previousPoint.y;
19622
+ const tangentLength = Math.hypot(tangentX, tangentY) || 1;
19623
+ const normalX = (-tangentY / tangentLength) * undersideDirection;
19624
+ const normalY = (tangentX / tangentLength) * undersideDirection;
19625
+ const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
19626
+ const suckerX = point.x + normalX * width * 0.52;
19627
+ const suckerY = point.y + normalY * width * 0.52;
19628
+ const rotation = Math.atan2(normalY, normalX);
19629
+ context.beginPath();
19630
+ context.ellipse(suckerX, suckerY, width * 0.22, width * 0.11, rotation, 0, Math.PI * 2);
19631
+ context.fillStyle = `${palette.highlight}73`;
19632
+ context.fill();
19633
+ context.strokeStyle = `${palette.highlight}99`;
19634
+ context.lineWidth = Math.max(1, width * 0.08);
19635
+ context.stroke();
19636
+ }
19637
+ }
19638
+ /**
19639
+ * Draws slow inner currents inside the clipped Octopus3 mantle.
19640
+ *
19641
+ * @param context Canvas 2D context.
19642
+ * @param centerX Body center X coordinate.
19643
+ * @param centerY Body center Y coordinate.
19644
+ * @param size Canvas size in CSS pixels.
19645
+ * @param palette Derived avatar palette.
19646
+ * @param timeMs Current animation time in milliseconds.
19647
+ * @param shapePhase Seed-based phase offset.
19648
+ * @param morphologyProfile Seeded morphology profile.
19649
+ *
19650
+ * @private helper of `octopus3AvatarVisual`
19651
+ */
19652
+ function drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile) {
19653
+ const centeredCurrentIndex = (morphologyProfile.details.mantleCurrentCount - 1) / 2;
19654
+ for (let currentIndex = 0; currentIndex < morphologyProfile.details.mantleCurrentCount; currentIndex++) {
19655
+ const horizontalOffset = (currentIndex - centeredCurrentIndex) *
19656
+ size *
19657
+ (0.05 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.025);
19658
+ const sway = Math.sin(timeMs / 680 + currentIndex * 0.78 + shapePhase) * size * 0.024;
19659
+ context.beginPath();
19660
+ context.moveTo(centerX + horizontalOffset * 0.3, centerY - size * (0.11 + morphologyProfile.body.verticalStretch * 0.02));
19661
+ 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));
19662
+ context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}30` : `${palette.accent}26`;
19663
+ context.lineWidth =
19664
+ size * (0.0075 + currentIndex * 0.00065 + morphologyProfile.tentacles.baseWidthScale * 0.0005);
19665
+ context.lineCap = 'round';
19666
+ context.stroke();
19667
+ }
19668
+ }
19669
+ /**
19670
+ * Draws seeded luminous nodes inside the Octopus3 mantle.
19671
+ *
19672
+ * @param context Canvas 2D context.
19673
+ * @param centerX Body center X coordinate.
19674
+ * @param centerY Body center Y coordinate.
19675
+ * @param size Canvas size in CSS pixels.
19676
+ * @param palette Derived avatar palette.
19677
+ * @param createRandom Seeded random factory scoped to the avatar.
19678
+ * @param morphologyProfile Seeded morphology profile.
19679
+ *
19680
+ * @private helper of `octopus3AvatarVisual`
19681
+ */
19682
+ function drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile) {
19683
+ for (let nodeIndex = 0; nodeIndex < morphologyProfile.details.mantleNodeCount; nodeIndex++) {
19684
+ const nodeRandom = createRandom(`octopus3-node-${nodeIndex}`);
19685
+ const nodeX = centerX + (nodeRandom() - 0.5) * size * (0.2 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.16);
19686
+ const nodeY = centerY -
19687
+ size * 0.03 +
19688
+ (nodeRandom() - 0.5) * size * (0.16 + (morphologyProfile.body.verticalStretch - 0.82) * 0.1);
19689
+ const nodeRadius = size * (0.016 + nodeRandom() * 0.016);
19690
+ context.beginPath();
19691
+ context.arc(nodeX, nodeY, nodeRadius, 0, Math.PI * 2);
19692
+ context.fillStyle = nodeIndex % 2 === 0 ? `${palette.highlight}40` : `${palette.accent}33`;
19693
+ context.fill();
19694
+ }
19695
+ }
19696
+ /**
19697
+ * Draws one expressive seeded eye with a slit pupil and slightly tilted eyelids.
19698
+ *
19699
+ * @param context Canvas 2D context.
19700
+ * @param centerX Eye center X coordinate.
19701
+ * @param centerY Eye center Y coordinate.
19702
+ * @param radiusX Eye horizontal radius.
19703
+ * @param radiusY Eye vertical radius.
19704
+ * @param rotation Eye rotation in radians.
19705
+ * @param palette Derived avatar palette.
19706
+ * @param timeMs Current animation time in milliseconds.
19707
+ * @param phase Seed-based animation phase.
19708
+ * @param interaction Smoothed avatar interaction state.
19709
+ * @param eyeStyle Seeded eye-style traits.
19710
+ *
19711
+ * @private helper of `octopus3AvatarVisual`
19712
+ */
19713
+ function drawSeededEye(context, centerX, centerY, radiusX, radiusY, rotation, palette, timeMs, phase, interaction, eyeStyle) {
19714
+ const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
19715
+ radiusX,
19716
+ radiusY,
19717
+ timeMs,
19718
+ phase,
19719
+ interaction,
19720
+ });
19721
+ context.save();
19722
+ context.translate(centerX, centerY);
19723
+ context.rotate(rotation);
19724
+ context.beginPath();
19725
+ context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
19726
+ context.fillStyle = '#f8fbff';
19727
+ context.fill();
19728
+ context.clip();
19729
+ const irisGradient = context.createRadialGradient(-radiusX * 0.18, -radiusY * 0.24, radiusX * 0.05, 0, 0, radiusX * 0.92);
19730
+ irisGradient.addColorStop(0, palette.highlight);
19731
+ irisGradient.addColorStop(0.58, palette.secondary);
19732
+ irisGradient.addColorStop(1, palette.shadow);
19733
+ context.beginPath();
19734
+ context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.66 * eyeStyle.irisScale, radiusY * 0.74 * eyeStyle.irisScale, 0, 0, Math.PI * 2);
19735
+ context.fillStyle = irisGradient;
19736
+ context.fill();
19737
+ context.beginPath();
19738
+ context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.14 * eyeStyle.pupilWidthScale, radiusY * 0.5 * eyeStyle.pupilHeightScale, 0, 0, Math.PI * 2);
19739
+ context.fillStyle = palette.ink;
19740
+ context.fill();
19741
+ context.beginPath();
19742
+ context.ellipse(pupilOffsetX - radiusX * 0.22, pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
19743
+ context.fillStyle = '#ffffff';
19744
+ context.fill();
19745
+ context.restore();
19746
+ context.save();
19747
+ context.translate(centerX, centerY);
19748
+ context.rotate(rotation);
19749
+ context.beginPath();
19750
+ context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
19751
+ context.strokeStyle = `${palette.shadow}d9`;
19752
+ context.lineWidth = radiusX * 0.18;
19753
+ context.stroke();
19754
+ context.beginPath();
19755
+ context.moveTo(-radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
19756
+ context.quadraticCurveTo(0, -radiusY * (eyeStyle.upperLidArchRatio - interaction.gazeY * 0.16 + interaction.intensity * 0.08), radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
19757
+ context.strokeStyle = `${palette.shadow}73`;
19758
+ context.lineWidth = radiusX * 0.16;
19759
+ context.lineCap = 'round';
19760
+ context.stroke();
19761
+ if (eyeStyle.lowerLidOpacity > 0) {
19762
+ context.beginPath();
19763
+ context.moveTo(-radiusX * 0.74, radiusY * 0.2);
19764
+ context.quadraticCurveTo(0, radiusY * 0.38, radiusX * 0.74, radiusY * 0.2);
19765
+ context.strokeStyle = `${palette.highlight}${formatAlphaHex(eyeStyle.lowerLidOpacity)}`;
19766
+ context.lineWidth = radiusX * 0.08;
19767
+ context.lineCap = 'round';
19768
+ context.stroke();
19769
+ }
19770
+ context.restore();
19771
+ }
19772
+
19773
+ /* eslint-disable no-magic-numbers */
19774
+ /**
19775
+ * Family variants used by the orb renderer.
19776
+ *
19777
+ * @private helper of `orbAvatarVisual`
19778
+ */
19779
+ const ORB_FAMILIES = ['pearl', 'nebula', 'ember', 'glacier'];
19780
+ /**
19781
+ * Built-in Orb avatar visual.
19782
+ *
19783
+ * @private built-in avatar visual
19784
+ */
19785
+ const orbAvatarVisual = {
19786
+ id: 'orb',
19787
+ title: 'Orb',
19788
+ description: 'Glowing morphing circle-orb with seeded gradients, smooth deformations, and luminous layered depth.',
19789
+ isAnimated: true,
19790
+ render({ context, size, palette, createRandom, timeMs }) {
19791
+ const profile = createOrbMorphologyProfile(createRandom);
19792
+ const colorSet = resolveOrbColorSet(palette, profile.family);
19793
+ const centerX = size * 0.5 + profile.coreShiftX * size * 0.06 + Math.sin(timeMs / 2600) * size * 0.009;
19794
+ const centerY = size * 0.5 +
19795
+ profile.coreShiftY * size * 0.06 +
19796
+ Math.cos(timeMs / 3100 + profile.highlightAngle) * size * 0.01;
19797
+ const radius = size * profile.baseRadiusRatio;
19798
+ const silhouettePoints = createOrbSilhouettePoints({
19799
+ centerX,
19800
+ centerY,
19801
+ radius,
19802
+ profile,
19803
+ timeMs,
19804
+ });
19805
+ drawAvatarFrame(context, size, palette);
19806
+ drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs);
19807
+ drawOrbBody(context, silhouettePoints, centerX, centerY, radius, colorSet, profile, size);
19808
+ context.save();
19809
+ traceSmoothClosedPath(context, silhouettePoints);
19810
+ context.clip();
19811
+ drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
19812
+ drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs);
19813
+ drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
19814
+ drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
19815
+ context.restore();
19816
+ drawOrbRim(context, silhouettePoints, colorSet, size);
19817
+ },
19818
+ };
19819
+ /**
19820
+ * Builds the deterministic orb profile from the seeded avatar random factory.
19821
+ *
19822
+ * @param createRandom Seeded random factory.
19823
+ * @returns Stable orb morphology profile.
19824
+ *
19825
+ * @private helper of `orbAvatarVisual`
19826
+ */
19827
+ function createOrbMorphologyProfile(createRandom) {
19828
+ const family = pickRandomItem(ORB_FAMILIES, createRandom('orb-family'));
19829
+ const familyAdjustment = resolveOrbFamilyAdjustment(family);
19830
+ const layoutRandom = createRandom('orb-layout');
19831
+ const effectRandom = createRandom('orb-effects');
19832
+ return {
19833
+ family,
19834
+ baseRadiusRatio: clampNumber(0.255 + layoutRandom() * 0.055 + familyAdjustment.baseRadiusRatio, 0.22, 0.335),
19835
+ horizontalStretch: clampNumber(0.93 + layoutRandom() * 0.13 + familyAdjustment.horizontalStretch, 0.88, 1.16),
19836
+ verticalStretch: clampNumber(0.91 + layoutRandom() * 0.13 + familyAdjustment.verticalStretch, 0.88, 1.15),
19837
+ wobbleAmplitude: clampNumber(0.038 + effectRandom() * 0.042 + familyAdjustment.wobbleAmplitude, 0.022, 0.12),
19838
+ wobbleFrequencyOne: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 2, 7),
19839
+ wobbleFrequencyTwo: clampInteger(3 + Math.floor(layoutRandom() * 3) + familyAdjustment.wobbleFrequency, 3, 8),
19840
+ wobbleFrequencyThree: clampInteger(5 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 4, 9),
19841
+ ringCount: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.ringCount, 2, 5),
19842
+ sparkleCount: clampInteger(6 + Math.floor(effectRandom() * 7) + familyAdjustment.sparkleCount, 4, 16),
19843
+ haloCount: clampInteger(2 + Math.floor(layoutRandom() * 2) + familyAdjustment.haloCount, 1, 4),
19844
+ coreShiftX: (layoutRandom() - 0.5) * 0.08,
19845
+ coreShiftY: (effectRandom() - 0.5) * 0.08,
19846
+ highlightAngle: layoutRandom() * Math.PI * 2,
19847
+ bandRotation: effectRandom() * Math.PI * 2,
19848
+ pulseSpeed: 0.82 + effectRandom() * 0.72,
19849
+ haloBlurRatio: clampNumber(0.18 + layoutRandom() * 0.12 + familyAdjustment.haloBlurRatio, 0.16, 0.34),
19850
+ sheenStrength: clampNumber(0.46 + effectRandom() * 0.28 + familyAdjustment.sheenStrength, 0.38, 0.88),
19851
+ };
19852
+ }
19853
+ /**
19854
+ * Resolves the family-specific adjustments that keep the orb surface varied while still circular.
19855
+ *
19856
+ * @param family Selected orb family.
19857
+ * @returns Family-specific profile adjustments.
19858
+ *
19859
+ * @private helper of `orbAvatarVisual`
19860
+ */
19861
+ function resolveOrbFamilyAdjustment(family) {
19862
+ switch (family) {
19863
+ case 'nebula':
19864
+ return {
19865
+ baseRadiusRatio: 0.006,
19866
+ horizontalStretch: 0.05,
19867
+ verticalStretch: -0.01,
19868
+ wobbleAmplitude: 0.012,
19869
+ wobbleFrequency: 1,
19870
+ ringCount: 1,
19871
+ sparkleCount: 2,
19872
+ haloCount: 0,
19873
+ haloBlurRatio: 0.02,
19874
+ sheenStrength: 0.08,
19875
+ };
19876
+ case 'ember':
19877
+ return {
19878
+ baseRadiusRatio: -0.004,
19879
+ horizontalStretch: -0.03,
19880
+ verticalStretch: 0.03,
19881
+ wobbleAmplitude: 0.02,
19882
+ wobbleFrequency: 1,
19883
+ ringCount: 0,
19884
+ sparkleCount: 3,
19885
+ haloCount: 0,
19886
+ haloBlurRatio: 0.04,
19887
+ sheenStrength: 0.06,
19888
+ };
19889
+ case 'glacier':
19890
+ return {
19891
+ baseRadiusRatio: 0.012,
19892
+ horizontalStretch: 0.01,
19893
+ verticalStretch: 0.02,
19894
+ wobbleAmplitude: -0.006,
19895
+ wobbleFrequency: -1,
19896
+ ringCount: 0,
19897
+ sparkleCount: 0,
19898
+ haloCount: 0,
19899
+ haloBlurRatio: -0.01,
19900
+ sheenStrength: 0.12,
19901
+ };
19902
+ case 'pearl':
19903
+ default:
19904
+ return {
19905
+ baseRadiusRatio: 0.02,
19906
+ horizontalStretch: 0.025,
19907
+ verticalStretch: 0.02,
19908
+ wobbleAmplitude: -0.01,
19909
+ wobbleFrequency: 0,
19910
+ ringCount: 0,
19911
+ sparkleCount: -1,
19912
+ haloCount: 1,
19913
+ haloBlurRatio: 0.02,
19914
+ sheenStrength: 0.1,
19915
+ };
19916
+ }
19917
+ }
19918
+ /**
19919
+ * Resolves the color set used by the orb renderer.
19920
+ *
19921
+ * @param palette Base avatar palette.
19922
+ * @param family Selected orb family.
19923
+ * @returns Derived orb-specific color set.
19924
+ *
19925
+ * @private helper of `orbAvatarVisual`
19926
+ */
19927
+ function resolveOrbColorSet(palette, family) {
19928
+ const primaryColor = Color.fromSafe(palette.primary);
19929
+ const secondaryColor = Color.fromSafe(palette.secondary);
19930
+ const accentColor = Color.fromSafe(palette.accent);
19931
+ const highlightColor = Color.fromSafe(palette.highlight);
19932
+ const shadowColor = Color.fromSafe(palette.shadow);
19933
+ switch (family) {
19934
+ case 'nebula':
19935
+ return {
19936
+ core: accentColor.then(lighten(0.16)).then(saturate(0.14)).toHex(),
19937
+ mid: secondaryColor.then(lighten(0.08)).then(saturate(0.08)).toHex(),
19938
+ outer: primaryColor.then(darken(0.03)).then(saturate(0.04)).toHex(),
19939
+ rim: shadowColor.then(lighten(0.08)).toHex(),
19940
+ highlight: highlightColor.then(lighten(0.14)).toHex(),
19941
+ aura: secondaryColor.then(lighten(0.18)).toHex(),
19942
+ };
19943
+ case 'ember':
19944
+ return {
19945
+ core: accentColor.then(lighten(0.2)).then(saturate(0.16)).toHex(),
19946
+ mid: primaryColor.then(lighten(0.1)).then(saturate(0.08)).toHex(),
19947
+ outer: secondaryColor.then(darken(0.04)).then(saturate(0.04)).toHex(),
19948
+ rim: shadowColor.then(lighten(0.08)).toHex(),
19949
+ highlight: highlightColor.then(lighten(0.18)).toHex(),
19950
+ aura: accentColor.then(lighten(0.12)).toHex(),
19951
+ };
19952
+ case 'glacier':
19953
+ return {
19954
+ core: highlightColor.then(lighten(0.18)).then(saturate(-0.04)).toHex(),
19955
+ mid: secondaryColor.then(lighten(0.1)).then(saturate(-0.06)).toHex(),
19956
+ outer: primaryColor.then(lighten(0.06)).toHex(),
19957
+ rim: shadowColor.then(lighten(0.12)).toHex(),
19958
+ highlight: highlightColor.then(lighten(0.26)).toHex(),
19959
+ aura: primaryColor.then(lighten(0.18)).toHex(),
19960
+ };
19961
+ case 'pearl':
19962
+ default:
19963
+ return {
19964
+ core: highlightColor.then(lighten(0.2)).then(saturate(-0.06)).toHex(),
19965
+ mid: primaryColor.then(lighten(0.12)).then(saturate(-0.02)).toHex(),
19966
+ outer: secondaryColor.then(lighten(0.08)).then(saturate(-0.04)).toHex(),
19967
+ rim: shadowColor.then(lighten(0.12)).toHex(),
19968
+ highlight: highlightColor.then(lighten(0.3)).toHex(),
19969
+ aura: highlightColor.then(lighten(0.18)).toHex(),
19970
+ };
19971
+ }
19972
+ }
19973
+ /**
19974
+ * Creates the orb silhouette points from the deterministic profile.
19975
+ *
19976
+ * @param options Orb geometry options.
19977
+ * @returns Smoothly varying orb outline.
19978
+ *
19979
+ * @private helper of `orbAvatarVisual`
19980
+ */
19981
+ function createOrbSilhouettePoints(options) {
19982
+ const { centerX, centerY, radius, profile, timeMs } = options;
19983
+ const pointCount = 48;
19984
+ return Array.from({ length: pointCount }, (_, pointIndex) => {
19985
+ const progress = pointIndex / pointCount;
19986
+ const angle = -Math.PI / 2 + progress * Math.PI * 2;
19987
+ const breathing = Math.sin(timeMs / (1450 / profile.pulseSpeed) + profile.bandRotation) * profile.wobbleAmplitude;
19988
+ const surfaceWaveOne = Math.sin(angle * profile.wobbleFrequencyOne + profile.highlightAngle + timeMs / (980 / profile.pulseSpeed)) * profile.wobbleAmplitude;
19989
+ const surfaceWaveTwo = Math.cos(angle * profile.wobbleFrequencyTwo - profile.bandRotation * 0.8 + timeMs / (1320 / profile.pulseSpeed)) *
19990
+ profile.wobbleAmplitude *
19991
+ 0.62;
19992
+ const surfaceWaveThree = Math.sin(angle * profile.wobbleFrequencyThree +
19993
+ profile.highlightAngle * 1.4 -
19994
+ timeMs / (1710 / profile.pulseSpeed)) *
19995
+ profile.wobbleAmplitude *
19996
+ 0.38;
19997
+ const surfaceTaper = Math.sin(angle * 2 + profile.highlightAngle) * profile.wobbleAmplitude * 0.2;
19998
+ const localRadius = radius * (1 + breathing * 0.12 + surfaceWaveOne + surfaceWaveTwo + surfaceWaveThree + surfaceTaper);
19999
+ return {
20000
+ x: centerX +
20001
+ Math.cos(angle) * localRadius * profile.horizontalStretch +
20002
+ Math.sin(angle * 3 + profile.highlightAngle + timeMs / 2100) * radius * 0.012,
20003
+ y: centerY +
20004
+ Math.sin(angle) * localRadius * profile.verticalStretch +
20005
+ Math.cos(angle * 2 - profile.highlightAngle + timeMs / 2400) * radius * 0.01,
20006
+ };
20007
+ });
20008
+ }
20009
+ /**
20010
+ * Draws the atmospheric glow behind the orb.
20011
+ *
20012
+ * @param context Canvas 2D context.
20013
+ * @param size Canvas size in CSS pixels.
20014
+ * @param centerX Orb center X coordinate.
20015
+ * @param centerY Orb center Y coordinate.
20016
+ * @param radius Orb base radius.
20017
+ * @param colorSet Derived orb color set.
20018
+ * @param profile Deterministic orb profile.
20019
+ * @param timeMs Current animation time in milliseconds.
20020
+ *
20021
+ * @private helper of `orbAvatarVisual`
20022
+ */
20023
+ function drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs) {
20024
+ const atmosphereGradient = context.createRadialGradient(centerX, centerY, radius * 0.08, centerX, centerY, radius * (1.9 + profile.haloBlurRatio));
20025
+ atmosphereGradient.addColorStop(0, `${colorSet.highlight}26`);
20026
+ atmosphereGradient.addColorStop(0.32, `${colorSet.aura}16`);
20027
+ atmosphereGradient.addColorStop(1, `${colorSet.aura}00`);
20028
+ context.save();
20029
+ context.globalCompositeOperation = 'screen';
20030
+ context.fillStyle = atmosphereGradient;
20031
+ context.fillRect(0, 0, size, size);
20032
+ for (let haloIndex = 0; haloIndex < profile.haloCount; haloIndex++) {
20033
+ const haloPulse = Math.sin(timeMs / (1200 + haloIndex * 180) + profile.highlightAngle) * radius * 0.025;
20034
+ const haloRadiusX = radius * (1.18 + haloIndex * 0.18) + haloPulse;
20035
+ const haloRadiusY = radius * (0.98 + haloIndex * 0.16) + haloPulse * 0.82;
20036
+ const haloGradient = context.createRadialGradient(centerX, centerY, radius * 0.12, centerX, centerY, haloRadiusX * 1.12);
20037
+ haloGradient.addColorStop(0, `${colorSet.aura}${haloIndex === 0 ? '38' : '24'}`);
20038
+ haloGradient.addColorStop(0.5, `${colorSet.highlight}${haloIndex === 0 ? '1f' : '12'}`);
20039
+ haloGradient.addColorStop(1, `${colorSet.aura}00`);
20040
+ context.beginPath();
20041
+ context.ellipse(centerX, centerY, haloRadiusX, haloRadiusY, profile.highlightAngle * 0.12 + haloIndex * 0.2 + Math.sin(timeMs / 3800) * 0.04, 0, Math.PI * 2);
20042
+ context.fillStyle = haloGradient;
20043
+ context.fill();
20044
+ }
20045
+ context.restore();
20046
+ }
20047
+ /**
20048
+ * Draws the main orb body using the smooth silhouette path.
20049
+ *
20050
+ * @param context Canvas 2D context.
20051
+ * @param points Smooth orb outline points.
20052
+ * @param centerX Orb center X coordinate.
20053
+ * @param centerY Orb center Y coordinate.
20054
+ * @param radius Orb base radius.
20055
+ * @param colorSet Derived orb color set.
20056
+ * @param profile Deterministic orb profile.
20057
+ * @param size Canvas size in CSS pixels.
20058
+ *
20059
+ * @private helper of `orbAvatarVisual`
20060
+ */
20061
+ function drawOrbBody(context, points, centerX, centerY, radius, colorSet, profile, size) {
20062
+ 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));
20063
+ bodyGradient.addColorStop(0, `${colorSet.highlight}f8`);
20064
+ bodyGradient.addColorStop(0.22, `${colorSet.core}f2`);
20065
+ bodyGradient.addColorStop(0.58, `${colorSet.mid}e8`);
20066
+ bodyGradient.addColorStop(0.86, `${colorSet.outer}dc`);
20067
+ bodyGradient.addColorStop(1, `${colorSet.rim}ea`);
20068
+ context.save();
20069
+ traceSmoothClosedPath(context, points);
20070
+ context.shadowColor = `${colorSet.rim}aa`;
20071
+ context.shadowBlur = size * (0.06 + profile.haloBlurRatio * 0.15);
20072
+ context.fillStyle = bodyGradient;
20073
+ context.fill();
20074
+ context.restore();
20075
+ context.save();
20076
+ traceSmoothClosedPath(context, points);
20077
+ context.strokeStyle = `${colorSet.highlight}${profile.family === 'pearl' ? '72' : '58'}`;
20078
+ context.lineWidth = Math.max(1.2, size * 0.012);
20079
+ context.lineJoin = 'round';
20080
+ context.lineCap = 'round';
20081
+ context.stroke();
20082
+ context.restore();
20083
+ }
20084
+ /**
20085
+ * Draws the layered energy rings and soft internal gradients inside the orb.
20086
+ *
20087
+ * @param context Canvas 2D context.
20088
+ * @param centerX Orb center X coordinate.
20089
+ * @param centerY Orb center Y coordinate.
20090
+ * @param radius Orb base radius.
20091
+ * @param colorSet Derived orb color set.
20092
+ * @param profile Deterministic orb profile.
20093
+ * @param size Canvas size in CSS pixels.
20094
+ * @param timeMs Current animation time in milliseconds.
20095
+ *
20096
+ * @private helper of `orbAvatarVisual`
20097
+ */
20098
+ function drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
20099
+ const internalGradient = context.createRadialGradient(centerX - radius * 0.08, centerY - radius * 0.1, radius * 0.06, centerX, centerY, radius * (0.95 + profile.sheenStrength * 0.15));
20100
+ internalGradient.addColorStop(0, `${colorSet.highlight}70`);
20101
+ internalGradient.addColorStop(0.48, `${colorSet.core}22`);
20102
+ internalGradient.addColorStop(1, `${colorSet.rim}00`);
20103
+ context.fillStyle = internalGradient;
20104
+ context.fillRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
20105
+ for (let ringIndex = 0; ringIndex < profile.ringCount; ringIndex++) {
20106
+ const ringProgress = (ringIndex + 1) / (profile.ringCount + 1);
20107
+ const ringRadiusX = radius * (0.34 + ringProgress * 0.44);
20108
+ const ringRadiusY = radius * (0.28 + ringProgress * 0.38);
20109
+ const ringRotation = profile.highlightAngle * 0.24 +
20110
+ ringIndex * 0.4 +
20111
+ Math.sin(timeMs / (1800 + ringIndex * 180) + profile.bandRotation) * 0.08;
20112
+ context.beginPath();
20113
+ 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);
20114
+ context.strokeStyle = ringIndex % 2 === 0 ? `${colorSet.highlight}32` : `${colorSet.aura}24`;
20115
+ context.lineWidth = Math.max(1.2, size * (0.007 - ringIndex * 0.001));
20116
+ context.shadowColor = `${colorSet.highlight}55`;
20117
+ context.shadowBlur = size * 0.02;
20118
+ context.stroke();
20119
+ }
20120
+ }
20121
+ /**
20122
+ * Draws soft sparkles and seeded dust inside the orb.
20123
+ *
20124
+ * @param context Canvas 2D context.
20125
+ * @param centerX Orb center X coordinate.
20126
+ * @param centerY Orb center Y coordinate.
20127
+ * @param radius Orb base radius.
20128
+ * @param colorSet Derived orb color set.
20129
+ * @param profile Deterministic orb profile.
20130
+ * @param size Canvas size in CSS pixels.
20131
+ * @param createRandom Seeded random factory.
20132
+ * @param timeMs Current animation time in milliseconds.
20133
+ *
20134
+ * @private helper of `orbAvatarVisual`
20135
+ */
20136
+ function drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs) {
20137
+ const sparkleStride = Math.max(1, Math.floor(profile.sparkleCount / 6));
20138
+ for (let sparkleIndex = 0; sparkleIndex < profile.sparkleCount; sparkleIndex++) {
20139
+ const sparkleRandom = createRandom(`orb-sparkle-${sparkleIndex}`);
20140
+ const sparkleAngle = sparkleRandom() * Math.PI * 2 + profile.highlightAngle * 0.4;
20141
+ const sparkleOrbitRadius = radius * (0.42 + sparkleRandom() * 0.55);
20142
+ const sparkleOrbitPulse = 0.92 + Math.sin(timeMs / (700 + sparkleIndex * 70) + profile.bandRotation) * 0.08;
20143
+ const sparkleCenterX = centerX + Math.cos(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
20144
+ const sparkleCenterY = centerY + Math.sin(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
20145
+ const sparkleRadius = size * (0.0028 + sparkleRandom() * 0.0058) * sparkleOrbitPulse;
20146
+ context.beginPath();
20147
+ context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius * 2, 0, Math.PI * 2);
20148
+ context.fillStyle = `${colorSet.highlight}14`;
20149
+ context.fill();
20150
+ context.beginPath();
20151
+ context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius, 0, Math.PI * 2);
20152
+ context.fillStyle = sparkleIndex % sparkleStride === 0 ? `${colorSet.highlight}d2` : `${colorSet.aura}c8`;
20153
+ context.shadowColor = `${colorSet.highlight}66`;
20154
+ context.shadowBlur = size * 0.012;
20155
+ context.fill();
20156
+ }
20157
+ }
20158
+ /**
20159
+ * Draws the specular sweep that makes the orb feel glossy and dimensional.
20160
+ *
20161
+ * @param context Canvas 2D context.
20162
+ * @param centerX Orb center X coordinate.
20163
+ * @param centerY Orb center Y coordinate.
20164
+ * @param radius Orb base radius.
20165
+ * @param colorSet Derived orb color set.
20166
+ * @param profile Deterministic orb profile.
20167
+ * @param size Canvas size in CSS pixels.
20168
+ * @param timeMs Current animation time in milliseconds.
20169
+ *
20170
+ * @private helper of `orbAvatarVisual`
20171
+ */
20172
+ function drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
20173
+ const sheenAngle = profile.bandRotation + timeMs / (2400 / profile.pulseSpeed);
20174
+ const sheenDirectionX = Math.cos(sheenAngle);
20175
+ const sheenDirectionY = Math.sin(sheenAngle);
20176
+ const sheenGradient = context.createLinearGradient(centerX - sheenDirectionX * radius, centerY - sheenDirectionY * radius, centerX + sheenDirectionX * radius, centerY + sheenDirectionY * radius);
20177
+ sheenGradient.addColorStop(0, `${colorSet.highlight}00`);
20178
+ sheenGradient.addColorStop(0.24, `${colorSet.highlight}0e`);
20179
+ sheenGradient.addColorStop(0.43, `${colorSet.highlight}${profile.sheenStrength > 0.65 ? '66' : '48'}`);
20180
+ sheenGradient.addColorStop(0.57, `${colorSet.core}${profile.sheenStrength > 0.65 ? '42' : '2e'}`);
20181
+ sheenGradient.addColorStop(0.75, `${colorSet.aura}1e`);
20182
+ sheenGradient.addColorStop(1, `${colorSet.highlight}00`);
20183
+ context.fillStyle = sheenGradient;
20184
+ context.fillRect(centerX - radius * 1.6, centerY - radius * 1.6, radius * 3.2, radius * 3.2);
20185
+ context.beginPath();
20186
+ context.ellipse(centerX - radius * 0.18, centerY - radius * 0.2, radius * 0.44, radius * 0.24, profile.highlightAngle * 0.32, 0, Math.PI * 2);
20187
+ context.fillStyle = `${colorSet.highlight}${profile.family === 'ember' ? '26' : '2e'}`;
20188
+ context.shadowColor = `${colorSet.highlight}55`;
20189
+ context.shadowBlur = size * 0.02;
20190
+ context.fill();
20191
+ }
20192
+ /**
20193
+ * Draws the bright nucleus that gives the orb a recognisable center.
20194
+ *
20195
+ * @param context Canvas 2D context.
20196
+ * @param centerX Orb center X coordinate.
20197
+ * @param centerY Orb center Y coordinate.
20198
+ * @param radius Orb base radius.
20199
+ * @param colorSet Derived orb color set.
20200
+ * @param profile Deterministic orb profile.
20201
+ * @param size Canvas size in CSS pixels.
20202
+ * @param timeMs Current animation time in milliseconds.
20203
+ *
20204
+ * @private helper of `orbAvatarVisual`
20205
+ */
20206
+ function drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
20207
+ const coreRadiusX = radius * (0.18 + profile.sheenStrength * 0.06);
20208
+ const coreRadiusY = radius * (0.15 + profile.sheenStrength * 0.045);
20209
+ const corePulse = 1 + Math.sin(timeMs / (1100 / profile.pulseSpeed) + profile.bandRotation) * 0.04;
20210
+ context.beginPath();
20211
+ 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);
20212
+ context.fillStyle = `${colorSet.core}f0`;
20213
+ context.shadowColor = `${colorSet.highlight}88`;
20214
+ context.shadowBlur = size * 0.03;
20215
+ context.fill();
20216
+ context.beginPath();
20217
+ context.arc(centerX - radius * 0.06, centerY - radius * 0.07, radius * 0.06, 0, Math.PI * 2);
20218
+ context.fillStyle = `${colorSet.highlight}d6`;
20219
+ context.fill();
20220
+ }
20221
+ /**
20222
+ * Draws the final rim stroke so the orb stays crisp against busy backgrounds.
20223
+ *
20224
+ * @param context Canvas 2D context.
20225
+ * @param points Smooth orb outline points.
20226
+ * @param colorSet Derived orb color set.
20227
+ * @param size Canvas size in CSS pixels.
20228
+ *
20229
+ * @private helper of `orbAvatarVisual`
20230
+ */
20231
+ function drawOrbRim(context, points, colorSet, size) {
20232
+ context.save();
20233
+ traceSmoothClosedPath(context, points);
20234
+ context.strokeStyle = `${colorSet.rim}c0`;
20235
+ context.lineWidth = Math.max(1.25, size * 0.013);
20236
+ context.lineJoin = 'round';
20237
+ context.lineCap = 'round';
20238
+ context.shadowColor = `${colorSet.highlight}4f`;
20239
+ context.shadowBlur = size * 0.018;
20240
+ context.stroke();
20241
+ context.restore();
20242
+ }
20243
+ /**
20244
+ * Clamps a number into the provided range.
20245
+ *
20246
+ * @param value Number to clamp.
20247
+ * @param minimum Minimum accepted value.
20248
+ * @param maximum Maximum accepted value.
20249
+ * @returns Clamped number.
20250
+ *
20251
+ * @private helper of `orbAvatarVisual`
20252
+ */
20253
+ function clampNumber(value, minimum, maximum) {
20254
+ return Math.min(maximum, Math.max(minimum, value));
20255
+ }
20256
+ /**
20257
+ * Clamps a number into the provided integer range.
20258
+ *
20259
+ * @param value Number to clamp.
20260
+ * @param minimum Minimum accepted value.
20261
+ * @param maximum Maximum accepted value.
20262
+ * @returns Clamped integer.
20263
+ *
20264
+ * @private helper of `orbAvatarVisual`
20265
+ */
20266
+ function clampInteger(value, minimum, maximum) {
20267
+ return Math.min(maximum, Math.max(minimum, Math.round(value)));
20268
+ }
20269
+
20270
+ /* eslint-disable no-magic-numbers */
20271
+ /**
20272
+ * Pixel-art avatar visual.
20273
+ *
20274
+ * @private built-in avatar visual
20275
+ */
20276
+ const pixelArtAvatarVisual = {
20277
+ id: 'pixel-art',
20278
+ title: 'Pixel art',
20279
+ description: 'Symmetric retro badge with a deterministic face and palette-driven pixels.',
20280
+ isAnimated: false,
20281
+ render({ context, size, palette, createRandom, avatarDefinition }) {
20282
+ const random = createRandom('pixel-art');
20283
+ const panelSize = size * 0.62;
20284
+ const panelX = (size - panelSize) / 2;
20285
+ const panelY = size * 0.19;
20286
+ const pixelGridSize = 10;
20287
+ const pixelSize = panelSize / pixelGridSize;
20288
+ const halfColumns = Math.ceil(pixelGridSize / 2);
20289
+ const colorStops = [palette.primary, palette.secondary, palette.accent, palette.highlight];
20290
+ const foreheadRowCount = 2 + Math.floor(random() * 2);
20291
+ const cheekInset = 1 + Math.floor(random() * 2);
20292
+ const emblemHeight = 2 + Math.floor(random() * 2);
20293
+ drawAvatarFrame(context, size, palette);
20294
+ const glow = context.createRadialGradient(size * 0.5, size * 0.32, size * 0.05, size * 0.5, size * 0.32, size * 0.5);
20295
+ glow.addColorStop(0, `${palette.highlight}aa`);
20296
+ glow.addColorStop(1, `${palette.highlight}00`);
20297
+ context.fillStyle = glow;
20298
+ context.fillRect(0, 0, size, size);
20299
+ context.save();
20300
+ createRoundedRectPath(context, panelX, panelY, panelSize, panelSize, panelSize * 0.16);
20301
+ context.fillStyle = palette.shadow;
20302
+ context.shadowColor = `${palette.shadow}66`;
20303
+ context.shadowBlur = size * 0.08;
20304
+ context.fill();
20305
+ context.restore();
20306
+ for (let rowIndex = 0; rowIndex < pixelGridSize; rowIndex++) {
20307
+ for (let columnIndex = 0; columnIndex < halfColumns; columnIndex++) {
20308
+ const mirroredColumnIndex = pixelGridSize - columnIndex - 1;
20309
+ const normalizedRowDistance = Math.abs(rowIndex - pixelGridSize / 2) / (pixelGridSize / 2);
20310
+ const normalizedColumnDistance = columnIndex / halfColumns;
20311
+ const fillChance = 0.85 - normalizedRowDistance * 0.32 - normalizedColumnDistance * 0.08;
20312
+ if (random() > fillChance) {
20313
+ continue;
20314
+ }
20315
+ const color = colorStops[Math.min(colorStops.length - 1, Math.floor(random() *
20316
+ (rowIndex < foreheadRowCount
20317
+ ? 2
20318
+ : rowIndex > pixelGridSize - emblemHeight - 1
20319
+ ? colorStops.length
20320
+ : 3)))];
20321
+ if (columnIndex === 0 &&
20322
+ rowIndex >= cheekInset &&
20323
+ rowIndex <= pixelGridSize - cheekInset - 1 &&
20324
+ random() < 0.4) {
20325
+ continue;
20326
+ }
20327
+ drawPixel(context, panelX + columnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
20328
+ if (mirroredColumnIndex !== columnIndex) {
20329
+ drawPixel(context, panelX + mirroredColumnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
20330
+ }
20331
+ }
20332
+ }
20333
+ const eyeRowIndex = 3 + Math.floor(random() * 2);
20334
+ const eyeColumnOffset = 2 + Math.floor(random() * 2);
20335
+ drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
20336
+ drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
20337
+ drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
20338
+ drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
20339
+ const mouthRowIndex = eyeRowIndex + 3;
20340
+ const mouthWidth = 2 + Math.floor(random() * 2);
20341
+ for (let mouthOffset = 0; mouthOffset < mouthWidth; mouthOffset++) {
20342
+ drawPixel(context, panelX + (4 + mouthOffset) * pixelSize, panelY + mouthRowIndex * pixelSize, pixelSize, palette.shadow);
20343
+ }
20344
+ context.save();
20345
+ context.fillStyle = `${palette.highlight}44`;
20346
+ context.font = `${Math.round(size * 0.12)}px sans-serif`;
20347
+ context.textAlign = 'center';
20348
+ context.fillText(avatarDefinition.agentName.charAt(0).toUpperCase(), size * 0.5, size * 0.88);
20349
+ context.restore();
20350
+ },
20351
+ };
20352
+ /**
20353
+ * Draws one pixel-art block with a tiny inner highlight.
20354
+ *
20355
+ * @param context Canvas 2D context.
20356
+ * @param x Left coordinate.
20357
+ * @param y Top coordinate.
20358
+ * @param size Pixel size.
20359
+ * @param color Pixel fill color.
20360
+ *
20361
+ * @private helper of `pixelArtAvatarVisual`
20362
+ */
20363
+ function drawPixel(context, x, y, size, color) {
20364
+ const normalizedSize = size * 0.9;
20365
+ const offset = (size - normalizedSize) / 2;
20366
+ context.fillStyle = color;
20367
+ context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize);
20368
+ context.fillStyle = 'rgba(255,255,255,0.18)';
20369
+ context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize * 0.14);
20370
+ }
20371
+
20372
+ // Note: [💞] Ignore a discrepancy between file name and entity name
20373
+ /**
20374
+ * Built-in avatar visuals available to the app.
20375
+ *
20376
+ * @private shared registry for the avatar rendering system
20377
+ */
20378
+ const AVATAR_VISUALS = [
20379
+ pixelArtAvatarVisual,
20380
+ octopusAvatarVisual,
20381
+ octopus2AvatarVisual,
20382
+ octopus3AvatarVisual,
20383
+ asciiOctopusAvatarVisual,
20384
+ minecraftAvatarVisual,
20385
+ fractalAvatarVisual,
20386
+ orbAvatarVisual,
20387
+ ];
20388
+ /**
20389
+ * Normalizes user-facing avatar visual names so ids can be matched case-insensitively
20390
+ * across spaces, hyphens, underscores, and future separator variants.
20391
+ *
20392
+ * @param value Raw avatar visual id or title.
20393
+ * @returns Stable lookup key.
20394
+ *
20395
+ * @private shared registry for the avatar rendering system
20396
+ */
20397
+ function normalizeAvatarVisualLookupKey(value) {
20398
+ return value
20399
+ .trim()
20400
+ .toLowerCase()
20401
+ .replace(/[^a-z0-9]+/g, '');
20402
+ }
20403
+ /**
20404
+ * Resolves a user-facing avatar visual value to a supported built-in visual id.
20405
+ *
20406
+ * The lookup is derived from `AVATAR_VISUALS`, so new visuals become selectable by
20407
+ * adding them to the registry rather than updating parser-specific option lists.
20408
+ *
20409
+ * @param value Raw visual id/title, for example `PIXEL_ART`, `pixel art`, or `pixel-art`.
20410
+ * @returns Matching visual id or `null` when the value is empty/unknown.
20411
+ *
20412
+ * @private shared registry for the avatar rendering system
20413
+ */
20414
+ function resolveAvatarVisualId(value) {
20415
+ if (!value) {
20416
+ return null;
20417
+ }
20418
+ const normalizedValue = normalizeAvatarVisualLookupKey(value);
20419
+ if (!normalizedValue) {
20420
+ return null;
20421
+ }
20422
+ const avatarVisual = AVATAR_VISUALS.find((candidateAvatarVisual) => normalizeAvatarVisualLookupKey(candidateAvatarVisual.id) === normalizedValue ||
20423
+ normalizeAvatarVisualLookupKey(candidateAvatarVisual.title) === normalizedValue);
20424
+ return (avatarVisual === null || avatarVisual === void 0 ? void 0 : avatarVisual.id) || null;
20425
+ }
20426
+
20427
+ /**
20428
+ * META AVATAR commitment definition
20429
+ *
20430
+ * The `META AVATAR` commitment sets the built-in default avatar visual used when
20431
+ * the agent does not provide an explicit `META IMAGE`.
20432
+ *
20433
+ * @private [đŸĒ”] Maybe export the commitments through some package
20434
+ */
20435
+ class MetaAvatarCommitmentDefinition extends BaseCommitmentDefinition {
20436
+ constructor() {
20437
+ super('META AVATAR');
20438
+ }
20439
+ /**
20440
+ * Short one-line description of META AVATAR.
20441
+ */
20442
+ get description() {
20443
+ return "Set the agent's built-in avatar visual.";
20444
+ }
20445
+ /**
20446
+ * Icon for this commitment.
20447
+ */
20448
+ get icon() {
20449
+ return '👤';
20450
+ }
20451
+ /**
20452
+ * Markdown documentation for META AVATAR commitment.
20453
+ */
20454
+ get documentation() {
20455
+ const supportedVisuals = AVATAR_VISUALS.map((avatarVisual) => `\`${avatarVisual.id}\``).join(', ');
20456
+ return spaceTrim$1(`
20457
+ # META AVATAR
20458
+
20459
+ Sets the built-in avatar visual used for the agent when no explicit \`META IMAGE\` is provided.
20460
+
20461
+ ## Key aspects
20462
+
20463
+ - Does not modify the agent's behavior or responses.
20464
+ - Only one \`META AVATAR\` should be used per agent.
20465
+ - If multiple are specified, the last one takes precedence.
20466
+ - Values are matched case-insensitively and spaces, hyphens, and underscores are normalized.
20467
+ - Supported visuals are derived from the shared avatar registry: ${supportedVisuals}.
20468
+
20469
+ ## Examples
20470
+
20471
+ \`\`\`book
20472
+ Pixel Assistant
20473
+
20474
+ META AVATAR PIXEL_ART
20475
+ GOAL Help users with concise answers.
20476
+ \`\`\`
20477
+
20478
+ \`\`\`book
20479
+ Orb Assistant
20480
+
20481
+ META AVATAR orb
20482
+ GOAL Answer in a calm and focused way.
20483
+ \`\`\`
20484
+ `);
20485
+ }
20486
+ applyToAgentModelRequirements(requirements, content) {
20487
+ // META AVATAR doesn't modify the system message or model requirements.
20488
+ // It's handled separately in the parsing logic for profile avatar resolution.
20489
+ return requirements;
20490
+ }
20491
+ }
20492
+ // Note: [💞] Ignore a discrepancy between file name and entity name
20493
+
17188
20494
  /**
17189
20495
  * META COLOR commitment definition
17190
20496
  *
@@ -17854,7 +21160,13 @@ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
17854
21160
  * Short one-line description of MODEL.
17855
21161
  */
17856
21162
  get description() {
17857
- return 'Enforce AI model requirements including name and technical parameters.';
21163
+ return 'Low-level commitment for explicit model selection and technical parameters. Use carefully.';
21164
+ }
21165
+ /**
21166
+ * Marks MODEL as a low-level commitment surfaced with caution.
21167
+ */
21168
+ get isLowLevel() {
21169
+ return true;
17858
21170
  }
17859
21171
  /**
17860
21172
  * Icon for this commitment.
@@ -17869,11 +21181,17 @@ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
17869
21181
  return spaceTrim$1(`
17870
21182
  # ${this.type}
17871
21183
 
17872
- Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
21184
+ Low-level commitment for explicit AI model selection and technical parameters.
21185
+
21186
+ ## Status
21187
+
21188
+ - This commitment is low-level and not used by most of the users.
21189
+ - Use it when you need to pin a specific model or fine-tune model parameters directly.
21190
+ - Prefer automatic model selection when you do not need manual control.
17873
21191
 
17874
21192
  ## Key aspects
17875
21193
 
17876
- - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments
21194
+ - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments.
17877
21195
  - Multiple \`MODEL\` commitments can be used to specify different parameters
17878
21196
  - Both \`MODEL\` and \`MODELS\` terms work identically and can be used interchangeably
17879
21197
  - Parameters control the randomness, creativity, and technical aspects of model responses
@@ -18402,6 +21720,12 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
18402
21720
  get description() {
18403
21721
  return 'Add behavioral rules the agent must follow.';
18404
21722
  }
21723
+ /**
21724
+ * Marks RULE as one of the priority commitments surfaced first in catalogues.
21725
+ */
21726
+ get isImportant() {
21727
+ return true;
21728
+ }
18405
21729
  /**
18406
21730
  * Icon for this commitment.
18407
21731
  */
@@ -19021,6 +22345,46 @@ function createTeammateLabel(url) {
19021
22345
  }
19022
22346
  // Note: [💞] Ignore a discrepancy between file name and entity name
19023
22347
 
22348
+ /**
22349
+ * Header used for same-server TEAM calls that may access private teammate agents.
22350
+ *
22351
+ * @private internal Agents Server access wiring
22352
+ */
22353
+ const TEAM_INTERNAL_AGENT_ACCESS_HEADER = 'x-promptbook-team-agent-access-token';
22354
+ /**
22355
+ * Creates request headers for same-server TEAM calls.
22356
+ *
22357
+ * @param options - Target agent URL, local server URL, and resolved access token.
22358
+ * @returns Header map when the target is same-origin; otherwise an empty map.
22359
+ *
22360
+ * @private internal Agents Server access wiring
22361
+ */
22362
+ function createTeamInternalAgentAccessHeaders(options) {
22363
+ if (!options.accessToken || !isSameOriginAgentUrl(options.agentUrl, options.localServerUrl)) {
22364
+ return {};
22365
+ }
22366
+ return {
22367
+ [TEAM_INTERNAL_AGENT_ACCESS_HEADER]: options.accessToken,
22368
+ };
22369
+ }
22370
+ /**
22371
+ * Checks whether a teammate URL points back to the current Agents Server origin.
22372
+ *
22373
+ * @private internal Agents Server access wiring
22374
+ */
22375
+ function isSameOriginAgentUrl(agentUrl, localServerUrl) {
22376
+ if (!localServerUrl) {
22377
+ return false;
22378
+ }
22379
+ try {
22380
+ return new URL(agentUrl).origin === new URL(localServerUrl).origin;
22381
+ }
22382
+ catch (_a) {
22383
+ return false;
22384
+ }
22385
+ }
22386
+ // Note: [💞] Ignore a discrepancy between file name and entity name
22387
+
19024
22388
  /**
19025
22389
  * Map of team tool functions.
19026
22390
  */
@@ -19066,11 +22430,17 @@ class TeamCommitmentDefinition extends BaseCommitmentDefinition {
19066
22430
  get description() {
19067
22431
  return 'Enable the agent to consult teammate agents via dedicated tools.';
19068
22432
  }
22433
+ /**
22434
+ * Marks TEAM as one of the priority commitments surfaced first in catalogues.
22435
+ */
22436
+ get isImportant() {
22437
+ return true;
22438
+ }
19069
22439
  /**
19070
22440
  * Icon for this commitment.
19071
22441
  */
19072
22442
  get icon() {
19073
- return '??';
22443
+ return 'đŸ‘Ĩ';
19074
22444
  }
19075
22445
  /**
19076
22446
  * Markdown documentation for TEAM commitment.
@@ -19372,21 +22742,28 @@ function createPseudoVoidTeamToolResult(entry, request) {
19372
22742
  /**
19373
22743
  * Resolves a RemoteAgent for the given teammate URL, caching the connection.
19374
22744
  */
19375
- async function getRemoteTeammateAgent(agentUrl) {
19376
- const cached = remoteAgentsByUrl.get(agentUrl);
22745
+ async function getRemoteTeammateAgent(agentUrl, runtimeContext) {
22746
+ var _a, _b;
22747
+ const requestHeaders = createTeamInternalAgentAccessHeaders({
22748
+ agentUrl,
22749
+ localServerUrl: (_a = runtimeContext.agentsServer) === null || _a === void 0 ? void 0 : _a.localServerUrl,
22750
+ accessToken: (_b = runtimeContext.agentsServer) === null || _b === void 0 ? void 0 : _b.teamInternalAccessToken,
22751
+ });
22752
+ const cacheKey = `${agentUrl}|${requestHeaders[TEAM_INTERNAL_AGENT_ACCESS_HEADER] || ''}`;
22753
+ const cached = remoteAgentsByUrl.get(cacheKey);
19377
22754
  if (cached) {
19378
22755
  return cached;
19379
22756
  }
19380
22757
  const connection = (async () => {
19381
22758
  const { RemoteAgent } = await Promise.resolve().then(function () { return RemoteAgent$1; });
19382
- return RemoteAgent.connect({ agentUrl });
22759
+ return RemoteAgent.connect({ agentUrl, requestHeaders });
19383
22760
  })();
19384
- remoteAgentsByUrl.set(agentUrl, connection);
22761
+ remoteAgentsByUrl.set(cacheKey, connection);
19385
22762
  try {
19386
22763
  return await connection;
19387
22764
  }
19388
22765
  catch (error) {
19389
- remoteAgentsByUrl.delete(agentUrl);
22766
+ remoteAgentsByUrl.delete(cacheKey);
19390
22767
  throw error;
19391
22768
  }
19392
22769
  }
@@ -19416,8 +22793,9 @@ function createTeamToolFunction(entry) {
19416
22793
  let error = null;
19417
22794
  let toolCalls;
19418
22795
  try {
19419
- const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url);
19420
- const prompt = buildTeammatePrompt(request, createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]));
22796
+ const runtimeContext = createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
22797
+ const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url, runtimeContext);
22798
+ const prompt = buildTeammatePrompt(request, runtimeContext);
19421
22799
  const teammateResult = await remoteAgent.callChatModel(prompt);
19422
22800
  response = teammateResult.content || '';
19423
22801
  toolCalls =
@@ -19456,11 +22834,10 @@ function createTeamToolFunction(entry) {
19456
22834
  /**
19457
22835
  * TEMPLATE commitment definition
19458
22836
  *
19459
- * The TEMPLATE commitment enforces a specific response structure or template
19460
- * that the agent must follow when generating responses. This helps ensure
19461
- * consistent message formatting across all agent interactions.
22837
+ * Deprecated legacy commitment for response templates and output structure.
22838
+ * New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
19462
22839
  *
19463
- * Example usage in agent source:
22840
+ * Legacy example usage in agent source:
19464
22841
  *
19465
22842
  * ```book
19466
22843
  * TEMPLATE Always structure your response with: 1) Summary, 2) Details, 3) Next steps
@@ -19480,7 +22857,16 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
19480
22857
  * Short one-line description of TEMPLATE.
19481
22858
  */
19482
22859
  get description() {
19483
- return 'Enforce a specific message structure or response template.';
22860
+ return 'Deprecated legacy template commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
22861
+ }
22862
+ /**
22863
+ * Optional UI/docs-only deprecation metadata.
22864
+ */
22865
+ get deprecation() {
22866
+ return {
22867
+ message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
22868
+ replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
22869
+ };
19484
22870
  }
19485
22871
  /**
19486
22872
  * Icon for this commitment.
@@ -19495,38 +22881,32 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
19495
22881
  return spaceTrim$1(`
19496
22882
  # ${this.type}
19497
22883
 
19498
- Enforces a specific response structure or template that the agent must follow when generating responses.
22884
+ Deprecated legacy commitment for response structure and templates.
19499
22885
 
19500
- ## Key aspects
22886
+ ## Migration
19501
22887
 
19502
- - Both terms work identically and can be used interchangeably.
19503
- - Can be used with or without content.
19504
- - When used without content, enables template mode for structured responses.
19505
- - When used with content, defines the specific template structure to follow.
19506
- - Multiple templates can be combined, with later ones taking precedence.
22888
+ - Existing \`${this.type}\` and \`TEMPLATES\` books still parse and compile.
22889
+ - New books should use \`WRITING SAMPLE\` for concrete response exemplars and \`WRITING RULES\` for structure or formatting constraints.
22890
+ - Runtime behavior is intentionally unchanged for backward compatibility.
19507
22891
 
19508
- ## Examples
22892
+ ## Preferred replacement
19509
22893
 
19510
22894
  \`\`\`book
19511
22895
  Customer Support Agent
19512
22896
 
19513
- PERSONA You are a helpful customer support representative
19514
- TEMPLATE Always structure your response with: 1) Acknowledgment, 2) Solution, 3) Follow-up question
19515
- WRITING RULES Be professional and empathetic
22897
+ GOAL Help the user with support questions.
22898
+ WRITING SAMPLE
22899
+ Thanks for reaching out. Here is the summary, details, and next step.
22900
+ WRITING RULES Keep the response structured as: summary, details, next step.
19516
22901
  \`\`\`
19517
22902
 
19518
- \`\`\`book
19519
- Technical Documentation Assistant
19520
-
19521
- PERSONA You are a technical writing expert
19522
- TEMPLATE Use the following format: **Topic:** [topic] | **Explanation:** [details] | **Example:** [code]
19523
- FORMAT Use markdown with clear headings
19524
- \`\`\`
22903
+ ## Legacy compatibility example
19525
22904
 
19526
22905
  \`\`\`book
19527
- Simple Agent
22906
+ Customer Support Agent
19528
22907
 
19529
- PERSONA You are a virtual assistant
22908
+ GOAL Help the user with support questions.
22909
+ TEMPLATE Always structure your response with: 1) Acknowledgment, 2) Solution, 3) Follow-up question
19530
22910
  TEMPLATE
19531
22911
  \`\`\`
19532
22912
  `);
@@ -19574,120 +22954,6 @@ class TemplateCommitmentDefinition extends BaseCommitmentDefinition {
19574
22954
  }
19575
22955
  // Note: [💞] Ignore a discrepancy between file name and entity name
19576
22956
 
19577
- /**
19578
- * USE commitment definition
19579
- *
19580
- * The USE commitment indicates that the agent should utilize specific tools or capabilities
19581
- * to access and interact with external systems when necessary.
19582
- *
19583
- * Supported USE types:
19584
- * - USE BROWSER: Enables the agent to use a web browser tool
19585
- * - USE SEARCH ENGINE (future): Enables search engine access
19586
- * - USE DEEPSEARCH: Enables deeper research-oriented search access
19587
- * - USE FILE SYSTEM (future): Enables file system operations
19588
- * - USE MCP (future): Enables MCP server connections
19589
- *
19590
- * The content following the USE commitment is ignored (similar to NOTE).
19591
- *
19592
- * Example usage in agent source:
19593
- *
19594
- * ```book
19595
- * USE BROWSER
19596
- * USE SEARCH ENGINE
19597
- * ```
19598
- *
19599
- * @private [đŸĒ”] Maybe export the commitments through some package
19600
- */
19601
- class UseCommitmentDefinition extends BaseCommitmentDefinition {
19602
- constructor() {
19603
- super('USE');
19604
- }
19605
- /**
19606
- * Short one-line description of USE commitments.
19607
- */
19608
- get description() {
19609
- return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, DEEPSEARCH, etc.).';
19610
- }
19611
- /**
19612
- * Icon for this commitment.
19613
- */
19614
- get icon() {
19615
- return '🔧';
19616
- }
19617
- /**
19618
- * Markdown documentation for USE commitment.
19619
- */
19620
- get documentation() {
19621
- return spaceTrim$1(`
19622
- # USE
19623
-
19624
- Enables the agent to use specific tools or capabilities for interacting with external systems.
19625
-
19626
- ## Supported USE types
19627
-
19628
- - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
19629
- - **USE SEARCH ENGINE** (future) - Enables search engine access
19630
- - **USE DEEPSEARCH** - Enables deeper research-oriented search access
19631
- - **USE FILE SYSTEM** (future) - Enables file system operations
19632
- - **USE MCP** (future) - Enables MCP server connections
19633
-
19634
- ## Key aspects
19635
-
19636
- - The content following the USE commitment is ignored (similar to NOTE)
19637
- - Multiple USE commitments can be specified to enable multiple capabilities
19638
- - The actual tool usage is handled by the agent runtime
19639
-
19640
- ## Examples
19641
-
19642
- ### Basic browser usage
19643
-
19644
- \`\`\`book
19645
- Research Assistant
19646
-
19647
- PERSONA You are a helpful research assistant
19648
- USE BROWSER
19649
- KNOWLEDGE Can search the web for up-to-date information
19650
- \`\`\`
19651
-
19652
- ### Multiple tools
19653
-
19654
- \`\`\`book
19655
- Data Analyst
19656
-
19657
- PERSONA You are a data analyst assistant
19658
- USE BROWSER
19659
- USE FILE SYSTEM
19660
- ACTION Can analyze data from various sources
19661
- \`\`\`
19662
- `);
19663
- }
19664
- applyToAgentModelRequirements(requirements, content) {
19665
- // USE commitments don't modify the system message or model requirements directly
19666
- // They are handled separately in the parsing logic for capability extraction
19667
- // This method exists for consistency with the CommitmentDefinition interface
19668
- return requirements;
19669
- }
19670
- /**
19671
- * Extracts the tool type from the USE commitment
19672
- * This is used by the parsing logic
19673
- */
19674
- extractToolType(content) {
19675
- var _a, _b;
19676
- const trimmedContent = content.trim();
19677
- // The tool type is the first word after USE (already stripped)
19678
- const match = trimmedContent.match(/^(\w+)/);
19679
- 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;
19680
- }
19681
- /**
19682
- * Checks if this is a known USE type
19683
- */
19684
- isKnownUseType(useType) {
19685
- const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'DEEPSEARCH', 'FILE SYSTEM', 'MCP'];
19686
- return knownTypes.includes(useType.toUpperCase());
19687
- }
19688
- }
19689
- // Note: [💞] Ignore a discrepancy between file name and entity name
19690
-
19691
22957
  /**
19692
22958
  * All `USE` commitment types currently participating in final system-message aggregation.
19693
22959
  *
@@ -25654,10 +28920,10 @@ const COMMITMENT_REGISTRY = [
25654
28920
  new MemoryCommitmentDefinition('MEMORIES'),
25655
28921
  new StyleCommitmentDefinition('STYLE'),
25656
28922
  new StyleCommitmentDefinition('STYLES'),
25657
- new RuleCommitmentDefinition('RULES'),
25658
28923
  new RuleCommitmentDefinition('RULE'),
25659
- new LanguageCommitmentDefinition('LANGUAGES'),
28924
+ new RuleCommitmentDefinition('RULES'),
25660
28925
  new LanguageCommitmentDefinition('LANGUAGE'),
28926
+ new LanguageCommitmentDefinition('LANGUAGES'),
25661
28927
  new WritingSampleCommitmentDefinition(),
25662
28928
  new WritingRulesCommitmentDefinition(),
25663
28929
  new SampleCommitmentDefinition('SAMPLE'),
@@ -25674,6 +28940,7 @@ const COMMITMENT_REGISTRY = [
25674
28940
  new ActionCommitmentDefinition('ACTION'),
25675
28941
  new ActionCommitmentDefinition('ACTIONS'),
25676
28942
  new ComponentCommitmentDefinition(),
28943
+ new MetaAvatarCommitmentDefinition(),
25677
28944
  new MetaImageCommitmentDefinition(),
25678
28945
  new MetaColorCommitmentDefinition(),
25679
28946
  new MetaFontCommitmentDefinition(),
@@ -25721,7 +28988,6 @@ const COMMITMENT_REGISTRY = [
25721
28988
  new UseMcpCommitmentDefinition(),
25722
28989
  new UsePrivacyCommitmentDefinition(),
25723
28990
  new UseProjectCommitmentDefinition(),
25724
- new UseCommitmentDefinition(),
25725
28991
  // Not yet implemented commitments (using placeholder)
25726
28992
  new NotYetImplementedCommitmentDefinition('EXPECT'),
25727
28993
  new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
@@ -25734,6 +29000,92 @@ const COMMITMENT_REGISTRY = [
25734
29000
  // TODO: [🧠] Maybe create through standardized $register
25735
29001
  // Note: [💞] Ignore a discrepancy between file name and entity name
25736
29002
 
29003
+ /**
29004
+ * Priority order for the important commitments shown first in catalogues and intellisense.
29005
+ *
29006
+ * Canonical singular names stay ahead of their plural aliases so the most important
29007
+ * commitments remain easy to scan.
29008
+ *
29009
+ * @private internal constant of commitment catalog sorting
29010
+ */
29011
+ const IMPORTANT_COMMITMENT_TYPE_SORT_ORDER = new Map([
29012
+ ['GOAL', 0],
29013
+ ['GOALS', 1],
29014
+ ['RULE', 2],
29015
+ ['RULES', 3],
29016
+ ['KNOWLEDGE', 4],
29017
+ ['TEAM', 5],
29018
+ ]);
29019
+ /**
29020
+ * Sort rank used when unfinished, low-level, and deprecated commitments should be grouped last.
29021
+ *
29022
+ * @private internal constant of commitment catalog sorting
29023
+ */
29024
+ const COMMITMENT_STATUS_SORT_ORDER = {
29025
+ normal: 0,
29026
+ deprecated: 1,
29027
+ unfinished: 2,
29028
+ lowLevel: 3,
29029
+ };
29030
+ /**
29031
+ * Resolves the relative sort rank of one commitment status.
29032
+ *
29033
+ * @param definition - Commitment definition to rank.
29034
+ * @param options - Sorting options.
29035
+ * @returns Relative sort rank for the definition.
29036
+ *
29037
+ * @private internal helper of commitment catalog sorting
29038
+ */
29039
+ function resolveCommitmentStatusSortRank(definition, options) {
29040
+ let statusSortRank = COMMITMENT_STATUS_SORT_ORDER.normal;
29041
+ if (options.isDeprecatedLast && definition.deprecation) {
29042
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.deprecated);
29043
+ }
29044
+ if (options.isUnfinishedLast && definition.isUnfinished) {
29045
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.unfinished);
29046
+ }
29047
+ if (options.isLowLevelLast && definition.isLowLevel) {
29048
+ statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.lowLevel);
29049
+ }
29050
+ return statusSortRank;
29051
+ }
29052
+ /**
29053
+ * Sorts commitment definitions so the important ones stay at the top.
29054
+ *
29055
+ * @param commitmentDefinitions - Definitions to sort.
29056
+ * @param options - Sorting options.
29057
+ * @returns Sorted commitment definitions.
29058
+ *
29059
+ * @private internal helper of commitment catalog sorting
29060
+ */
29061
+ function sortCommitmentDefinitions(commitmentDefinitions, options = {}) {
29062
+ return [...commitmentDefinitions]
29063
+ .map((definition, index) => ({
29064
+ definition,
29065
+ index,
29066
+ }))
29067
+ .sort((left, right) => {
29068
+ var _a, _b;
29069
+ if (left.definition.isImportant !== right.definition.isImportant) {
29070
+ return left.definition.isImportant ? -1 : 1;
29071
+ }
29072
+ if (left.definition.isImportant && right.definition.isImportant) {
29073
+ const leftPriority = (_a = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(left.definition.type)) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
29074
+ const rightPriority = (_b = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(right.definition.type)) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER;
29075
+ if (leftPriority !== rightPriority) {
29076
+ return leftPriority - rightPriority;
29077
+ }
29078
+ }
29079
+ const leftStatusSortRank = resolveCommitmentStatusSortRank(left.definition, options);
29080
+ const rightStatusSortRank = resolveCommitmentStatusSortRank(right.definition, options);
29081
+ if (leftStatusSortRank !== rightStatusSortRank) {
29082
+ return leftStatusSortRank - rightStatusSortRank;
29083
+ }
29084
+ return left.index - right.index;
29085
+ })
29086
+ .map(({ definition }) => definition);
29087
+ }
29088
+
25737
29089
  /**
25738
29090
  * Gets all available commitment definitions
25739
29091
  *
@@ -25742,7 +29094,7 @@ const COMMITMENT_REGISTRY = [
25742
29094
  * @public exported from `@promptbook/core`
25743
29095
  */
25744
29096
  function getAllCommitmentDefinitions() {
25745
- return $deepFreeze([...COMMITMENT_REGISTRY]);
29097
+ return $deepFreeze(sortCommitmentDefinitions(COMMITMENT_REGISTRY, { isUnfinishedLast: true, isLowLevelLast: true }));
25746
29098
  }
25747
29099
 
25748
29100
  /**
@@ -27941,7 +31293,7 @@ function deduplicatePreparationToolCalls(toolCalls) {
27941
31293
  lastPreparationIndex = index;
27942
31294
  }
27943
31295
  else {
27944
- // Remove earlier duplicate — keep only the last (most recent) one.
31296
+ // Remove earlier duplicate - keep only the last (most recent) one.
27945
31297
  toolCalls.splice(index, 1);
27946
31298
  }
27947
31299
  }
@@ -28354,6 +31706,7 @@ const SIMPLE_CAPABILITY_BY_COMMITMENT_TYPE = {
28354
31706
  * @private internal utility of `parseAgentSource`
28355
31707
  */
28356
31708
  const META_COMMITMENT_APPLIERS = {
31709
+ 'META AVATAR': applyMetaAvatarContent,
28357
31710
  'META LINK': applyMetaLinkContent,
28358
31711
  'META DOMAIN': applyMetaDomainContent,
28359
31712
  'META IMAGE': applyMetaImageContent,
@@ -28717,9 +32070,26 @@ function applyGenericMetaCommitment(state, content) {
28717
32070
  if (metaTypeRaw === 'LINK') {
28718
32071
  state.links.push(metaValue);
28719
32072
  }
32073
+ if (metaTypeRaw.toUpperCase() === 'AVATAR') {
32074
+ applyMetaAvatarContent(state, metaValue);
32075
+ return;
32076
+ }
28720
32077
  const metaType = normalizeTo_camelCase(metaTypeRaw);
28721
32078
  state.meta[metaType] = metaValue;
28722
32079
  }
32080
+ /**
32081
+ * Applies META AVATAR content into the canonical `meta.avatar` field.
32082
+ *
32083
+ * @private internal utility of `parseAgentSource`
32084
+ */
32085
+ function applyMetaAvatarContent(state, content) {
32086
+ const avatarVisualId = resolveAvatarVisualId(content);
32087
+ if (avatarVisualId) {
32088
+ state.meta.avatar = avatarVisualId;
32089
+ return;
32090
+ }
32091
+ delete state.meta.avatar;
32092
+ }
28723
32093
  /**
28724
32094
  * Applies META LINK content into links and the canonical `meta.link` field.
28725
32095
  *
@@ -30304,7 +33674,7 @@ function humanizeAiTextEllipsis(aiText) {
30304
33674
  // Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
30305
33675
 
30306
33676
  /**
30307
- * Change dash-like characters to regular dashes `—` -> `-` and remove soft hyphens
33677
+ * Change dash-like characters to regular dashes `-` -> `-` and remove soft hyphens
30308
33678
  *
30309
33679
  * Note: [🔂] This function is idempotent.
30310
33680
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
@@ -30312,7 +33682,7 @@ function humanizeAiTextEllipsis(aiText) {
30312
33682
  * @public exported from `@promptbook/markdown-utils`
30313
33683
  */
30314
33684
  function humanizeAiTextEmdashed(aiText) {
30315
- return aiText.replace(/\u00AD/g, '').replace(/[â€â€‘â€’â€“â€”â€•âˆ’âƒīšŖīŧ]/g, '-');
33685
+ return aiText.replace(/\u00AD/g, '').replace(/[‐‑‒–-â€•âˆ’âƒīšŖīŧ]/g, '-');
30316
33686
  }
30317
33687
  // Note: [🏂] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
30318
33688
 
@@ -37025,6 +40395,7 @@ function buildRemoteAgentSource(profile, meta) {
37025
40395
  const isMetaImageExplicit = profile.isMetaImageExplicit !== false;
37026
40396
  const metaLines = [
37027
40397
  formatMetaLine('FULLNAME', meta === null || meta === void 0 ? void 0 : meta.fullname),
40398
+ formatMetaLine('AVATAR', meta === null || meta === void 0 ? void 0 : meta.avatar),
37028
40399
  formatMetaLine('IMAGE', isMetaImageExplicit ? meta === null || meta === void 0 ? void 0 : meta.image : undefined),
37029
40400
  formatMetaLine('DESCRIPTION', meta === null || meta === void 0 ? void 0 : meta.description),
37030
40401
  formatMetaLine('COLOR', meta === null || meta === void 0 ? void 0 : meta.color),
@@ -37065,7 +40436,7 @@ class RemoteAgent extends Agent {
37065
40436
  var _a, _b, _c;
37066
40437
  const agentProfileUrl = `${options.agentUrl}/api/profile`;
37067
40438
  const profileResponse = await fetch(agentProfileUrl, {
37068
- headers: attachClientVersionHeader(),
40439
+ headers: attachClientVersionHeader(options.requestHeaders),
37069
40440
  });
37070
40441
  // <- TODO: [🐱‍🚀] What about closed-source agents?
37071
40442
  // <- TODO: [🐱‍🚀] Maybe use promptbookFetch
@@ -37145,6 +40516,7 @@ class RemoteAgent extends Agent {
37145
40516
  this.avatarVisualId = undefined;
37146
40517
  this.knowledgeSources = [];
37147
40518
  this.agentUrl = options.agentUrl;
40519
+ this.requestHeaders = options.requestHeaders || {};
37148
40520
  }
37149
40521
  get agentName() {
37150
40522
  return this._remoteAgentName || super.agentName;
@@ -37181,7 +40553,7 @@ class RemoteAgent extends Agent {
37181
40553
  }
37182
40554
  const response = await fetch(`${this.agentUrl}/api/voice`, {
37183
40555
  method: 'POST',
37184
- headers: attachClientVersionHeader(),
40556
+ headers: attachClientVersionHeader(this.requestHeaders),
37185
40557
  body: formData,
37186
40558
  });
37187
40559
  if (!response.ok) {
@@ -37212,6 +40584,7 @@ class RemoteAgent extends Agent {
37212
40584
  const bookResponse = await fetch(`${this.agentUrl}/api/chat`, {
37213
40585
  method: 'POST',
37214
40586
  headers: attachClientVersionHeader({
40587
+ ...this.requestHeaders,
37215
40588
  'Content-Type': 'application/json',
37216
40589
  }),
37217
40590
  body: JSON.stringify({