@promptbook/wizard 0.112.0-64 → 0.112.0-66

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 (55) hide show
  1. package/esm/index.es.js +781 -296
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/src/_packages/components.index.d.ts +0 -2
  4. package/esm/src/_packages/core.index.d.ts +2 -2
  5. package/esm/src/_packages/types.index.d.ts +0 -2
  6. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  7. package/esm/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
  8. package/esm/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
  9. package/esm/src/book-2.0/book-language-documentation/BookLanguageDocumentationExample.d.ts +27 -0
  10. package/esm/src/book-2.0/book-language-documentation/bookLanguageCommonPitfalls.d.ts +25 -0
  11. package/esm/src/book-2.0/book-language-documentation/bookLanguageDocumentationExamples.d.ts +10 -0
  12. package/esm/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.d.ts +14 -0
  13. package/esm/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.d.ts +43 -0
  14. package/esm/src/book-components/Chat/types/ChatMessage.d.ts +0 -34
  15. package/esm/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
  16. package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -11
  17. package/esm/src/commitments/_common/toolRuntimeContext.d.ts +0 -6
  18. package/esm/src/config.d.ts +3 -3
  19. package/esm/src/formfactors/index.d.ts +2 -2
  20. package/esm/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +1 -1
  21. package/esm/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +1 -1
  22. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +0 -4
  23. package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +0 -9
  24. package/esm/src/utils/files/getPromptbookTempPath.d.ts +24 -0
  25. package/esm/src/version.d.ts +1 -1
  26. package/package.json +2 -3
  27. package/umd/index.umd.js +780 -295
  28. package/umd/index.umd.js.map +1 -1
  29. package/umd/src/_packages/components.index.d.ts +0 -2
  30. package/umd/src/_packages/core.index.d.ts +2 -2
  31. package/umd/src/_packages/types.index.d.ts +0 -2
  32. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  33. package/umd/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
  34. package/umd/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
  35. package/umd/src/book-2.0/book-language-documentation/BookLanguageDocumentationExample.d.ts +27 -0
  36. package/umd/src/book-2.0/book-language-documentation/bookLanguageCommonPitfalls.d.ts +25 -0
  37. package/umd/src/book-2.0/book-language-documentation/bookLanguageDocumentationExamples.d.ts +10 -0
  38. package/umd/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.d.ts +14 -0
  39. package/umd/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.d.ts +43 -0
  40. package/umd/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.test.d.ts +1 -0
  41. package/umd/src/book-components/Chat/types/ChatMessage.d.ts +0 -34
  42. package/umd/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
  43. package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -11
  44. package/umd/src/commitments/_common/toolRuntimeContext.d.ts +0 -6
  45. package/umd/src/config.d.ts +3 -3
  46. package/umd/src/formfactors/index.d.ts +2 -2
  47. package/umd/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +1 -1
  48. package/umd/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +1 -1
  49. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +0 -4
  50. package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +0 -9
  51. package/umd/src/utils/files/getPromptbookTempPath.d.ts +24 -0
  52. package/umd/src/utils/files/getPromptbookTempPath.test.d.ts +1 -0
  53. package/umd/src/version.d.ts +1 -1
  54. /package/esm/src/{commitments/KNOWLEDGE/KNOWLEDGE.test.d.ts → book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.test.d.ts} +0 -0
  55. /package/{umd/src/commitments/KNOWLEDGE/KNOWLEDGE.test.d.ts → esm/src/utils/files/getPromptbookTempPath.test.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -49,7 +49,7 @@
49
49
  * @generated
50
50
  * @see https://github.com/webgptorg/promptbook
51
51
  */
52
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-64';
52
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-66';
53
53
  /**
54
54
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
55
55
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -982,6 +982,29 @@
982
982
  }
983
983
  // TODO: Maybe implement by mix+hsl
984
984
 
985
+ /**
986
+ * Relative directory name without the `./` prefix for Git ignore rules and glob patterns.
987
+ *
988
+ * @private internal utility for Promptbook-owned temp files
989
+ */
990
+ const PROMPTBOOK_TEMP_DIRECTORY_NAME = '.promptbook';
991
+ /**
992
+ * Builds one project-relative path inside the shared Promptbook working directory.
993
+ *
994
+ * @private internal utility for Promptbook-owned temp files
995
+ */
996
+ function getPromptbookTempPath(...pathSegments) {
997
+ return `./${getPromptbookTempPosixPath(...pathSegments)}`;
998
+ }
999
+ /**
1000
+ * Builds one POSIX path fragment inside the shared Promptbook working directory for globs and generated text files.
1001
+ *
1002
+ * @private internal utility for Promptbook-owned temp files
1003
+ */
1004
+ function getPromptbookTempPosixPath(...pathSegments) {
1005
+ return path.posix.join(PROMPTBOOK_TEMP_DIRECTORY_NAME, ...pathSegments);
1006
+ }
1007
+
985
1008
  /**
986
1009
  * Returns the same value that is passed as argument.
987
1010
  * No side effects.
@@ -1196,7 +1219,6 @@
1196
1219
  */
1197
1220
  const DEFAULT_BOOKS_DIRNAME = './books';
1198
1221
  // <- TODO: [🕝] Make also `AGENTS_DIRNAME_ALTERNATIVES`
1199
- // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
1200
1222
  /**
1201
1223
  * Where to store the temporary downloads
1202
1224
  *
@@ -1204,7 +1226,7 @@
1204
1226
  *
1205
1227
  * @public exported from `@promptbook/core`
1206
1228
  */
1207
- const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
1229
+ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = getPromptbookTempPath('download-cache');
1208
1230
  /**
1209
1231
  * Where to store the cache of executions for promptbook CLI
1210
1232
  *
@@ -1212,7 +1234,7 @@
1212
1234
  *
1213
1235
  * @public exported from `@promptbook/core`
1214
1236
  */
1215
- const DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
1237
+ const DEFAULT_EXECUTION_CACHE_DIRNAME = getPromptbookTempPath('execution-cache');
1216
1238
  /**
1217
1239
  * Where to store the scrape cache
1218
1240
  *
@@ -1220,7 +1242,7 @@
1220
1242
  *
1221
1243
  * @public exported from `@promptbook/core`
1222
1244
  */
1223
- const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
1245
+ const DEFAULT_SCRAPE_CACHE_DIRNAME = getPromptbookTempPath('scrape-cache');
1224
1246
  /*
1225
1247
  TODO: [🌃]
1226
1248
  /**
@@ -9226,9 +9248,11 @@
9226
9248
  * Creates the retry-history error message shared by all OpenAI-compatible model variants.
9227
9249
  */
9228
9250
  createAttemptHistoryError(finalErrorMessage) {
9229
- return new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
9230
- formatUnsupportedParameterAttemptHistory(this.attemptStack) +
9231
- `\nFinal error: ${finalErrorMessage}`);
9251
+ return new PipelineExecutionError(_spaceTrim.spaceTrim((block) => `
9252
+ All attempts failed. Attempt history:
9253
+ ${block(formatUnsupportedParameterAttemptHistory(this.attemptStack))}
9254
+ Final error: ${finalErrorMessage}
9255
+ `));
9232
9256
  }
9233
9257
  }
9234
9258
 
@@ -20745,18 +20769,6 @@
20745
20769
  return count;
20746
20770
  }
20747
20771
 
20748
- /**
20749
- * Name of the tool used by agents to search configured `KNOWLEDGE` sources.
20750
- *
20751
- * @public exported from `@promptbook/core`
20752
- */
20753
- const KNOWLEDGE_SEARCH_TOOL_NAME = 'knowledge_search';
20754
- /**
20755
- * Title of the system-message section generated for `KNOWLEDGE` commitments.
20756
- *
20757
- * @private constant of `KnowledgeCommitmentDefinition`
20758
- */
20759
- const KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE = 'Knowledge Search';
20760
20772
  /**
20761
20773
  * KNOWLEDGE commitment definition
20762
20774
  *
@@ -20878,17 +20890,9 @@
20878
20890
  knowledgeInfoEntries.push(`Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`);
20879
20891
  }
20880
20892
  if (knowledgeInfoEntries.length === 0) {
20881
- return addKnowledgeSearchToolAndSystemSection(nextRequirements);
20893
+ return nextRequirements;
20882
20894
  }
20883
- return addKnowledgeSearchToolAndSystemSection(nextRequirements);
20884
- }
20885
- /**
20886
- * Gets human-readable titles for tool functions provided by this commitment.
20887
- */
20888
- getToolTitles() {
20889
- return {
20890
- [KNOWLEDGE_SEARCH_TOOL_NAME]: 'Knowledge search',
20891
- };
20895
+ return this.appendToSystemMessage(nextRequirements, knowledgeInfoEntries.join('\n'), '\n\n');
20892
20896
  }
20893
20897
  }
20894
20898
  /**
@@ -20902,128 +20906,6 @@
20902
20906
  const significantText = contentWithoutUrls.replace(/[\s.,!?;:'"`()[\]{}<>/-]+/g, '');
20903
20907
  return significantText.length > 0;
20904
20908
  }
20905
- /**
20906
- * Adds the shared `knowledge_search` tool definition and the consolidated system-message section.
20907
- *
20908
- * @param requirements - Requirements after one `KNOWLEDGE` commitment was applied.
20909
- * @returns Requirements with the knowledge search instructions and tool definition.
20910
- *
20911
- * @private internal utility of `KnowledgeCommitmentDefinition`
20912
- */
20913
- function addKnowledgeSearchToolAndSystemSection(requirements) {
20914
- const nextRequirements = addKnowledgeSearchTool(requirements);
20915
- const section = createKnowledgeSearchSystemSection(nextRequirements);
20916
- const sectionHeader = `## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}`;
20917
- if (nextRequirements.systemMessage.includes(sectionHeader)) {
20918
- return {
20919
- ...nextRequirements,
20920
- systemMessage: nextRequirements.systemMessage.replace(new RegExp(`## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), section),
20921
- };
20922
- }
20923
- return {
20924
- ...nextRequirements,
20925
- systemMessage: nextRequirements.systemMessage.trim()
20926
- ? `${nextRequirements.systemMessage}\n\n${section}`
20927
- : section,
20928
- };
20929
- }
20930
- /**
20931
- * Adds the `knowledge_search` model tool when it is not already present.
20932
- *
20933
- * @param requirements - Current model requirements.
20934
- * @returns Requirements with the tool definition available to the model.
20935
- *
20936
- * @private internal utility of `KnowledgeCommitmentDefinition`
20937
- */
20938
- function addKnowledgeSearchTool(requirements) {
20939
- const existingTools = requirements.tools || [];
20940
- if (existingTools.some((tool) => tool.name === KNOWLEDGE_SEARCH_TOOL_NAME)) {
20941
- return requirements;
20942
- }
20943
- return {
20944
- ...requirements,
20945
- tools: [
20946
- ...existingTools,
20947
- {
20948
- name: KNOWLEDGE_SEARCH_TOOL_NAME,
20949
- description: _spaceTrim.spaceTrim(`
20950
- Search the agent's configured knowledge sources and return relevant excerpts with citation ids.
20951
- Use this before answering questions that may depend on the agent's KNOWLEDGE commitments.
20952
- `),
20953
- parameters: {
20954
- type: 'object',
20955
- properties: {
20956
- query: {
20957
- type: 'string',
20958
- description: 'The natural-language search query for the knowledge base.',
20959
- },
20960
- limit: {
20961
- type: 'integer',
20962
- description: 'Maximum number of matching source excerpts to return.',
20963
- },
20964
- },
20965
- required: ['query'],
20966
- },
20967
- },
20968
- ],
20969
- };
20970
- }
20971
- /**
20972
- * Creates the model-facing system-message section for knowledge search.
20973
- *
20974
- * @param requirements - Current model requirements.
20975
- * @returns Markdown system-message section.
20976
- *
20977
- * @private internal utility of `KnowledgeCommitmentDefinition`
20978
- */
20979
- function createKnowledgeSearchSystemSection(requirements) {
20980
- const sourceEntries = createKnowledgeSourceSystemEntries(requirements);
20981
- const sourceList = sourceEntries.length > 0 ? sourceEntries.map((entry) => `- ${entry}`).join('\n') : '- None';
20982
- return _spaceTrim.spaceTrim(`
20983
- ## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}
20984
-
20985
- - Use \`${KNOWLEDGE_SEARCH_TOOL_NAME}\` to search the configured knowledge sources before answering questions that depend on this agent's knowledge base.
20986
- - Base source-backed factual answers on the returned excerpts.
20987
- - When you use a returned excerpt, include its citation marker in the answer body, for example \`[0:0]\`.
20988
- - If the search returns no relevant information, say that the knowledge base did not contain the answer instead of inventing it.
20989
-
20990
- Configured knowledge sources:
20991
- ${sourceList}
20992
- `);
20993
- }
20994
- /**
20995
- * Builds a stable list of configured knowledge sources for system-message diagnostics.
20996
- *
20997
- * @param requirements - Current model requirements.
20998
- * @returns Human-readable source entries.
20999
- *
21000
- * @private internal utility of `KnowledgeCommitmentDefinition`
21001
- */
21002
- function createKnowledgeSourceSystemEntries(requirements) {
21003
- var _a;
21004
- const entries = [];
21005
- const seenEntries = new Set();
21006
- for (const source of requirements.knowledgeSources || []) {
21007
- const entry = `Source URL: ${source} (processed for retrieval during chat)`;
21008
- if (seenEntries.has(entry)) {
21009
- continue;
21010
- }
21011
- seenEntries.add(entry);
21012
- entries.push(entry);
21013
- }
21014
- const inlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || [])
21015
- .map((source) => source.filename)
21016
- .filter(Boolean);
21017
- for (const filename of inlineSources) {
21018
- const entry = `Knowledge Source Inline: ${filename} (Inline source: processed for retrieval during chat)`;
21019
- if (seenEntries.has(entry)) {
21020
- continue;
21021
- }
21022
- seenEntries.add(entry);
21023
- entries.push(entry);
21024
- }
21025
- return entries;
21026
- }
21027
20909
 
21028
20910
  /**
21029
20911
  * LANGUAGE commitment definition
@@ -23552,6 +23434,177 @@
23552
23434
  context.restore();
23553
23435
  }
23554
23436
 
23437
+ /* eslint-disable no-magic-numbers */
23438
+ /**
23439
+ * Builds the seeded six-face texture pack used by the Minecraft-style head cuboid.
23440
+ *
23441
+ * @param random Seeded random generator.
23442
+ * @param palette Derived avatar palette.
23443
+ * @param hasHeadband Whether the generated avatar should include a colored headband.
23444
+ * @returns Head cuboid textures.
23445
+ *
23446
+ * @private helper of the Minecraft avatar visuals
23447
+ */
23448
+ function createMinecraftHeadTextures(random, palette, hasHeadband) {
23449
+ const faceTexture = createMinecraftFaceTexture(random, palette, hasHeadband);
23450
+ const hairColor = random() < 0.5 ? palette.primary : palette.secondary;
23451
+ const skinColor = palette.highlight;
23452
+ const headbandColor = hasHeadband ? palette.accent : hairColor;
23453
+ const sideTexture = createFilledTexture(skinColor);
23454
+ const backTexture = createFilledTexture(skinColor);
23455
+ const topTexture = createFilledTexture(hairColor);
23456
+ const bottomTexture = createFilledTexture(`${palette.shadow}cc`);
23457
+ fillTextureRect(sideTexture, 0, 0, 8, 3, hairColor);
23458
+ fillTextureRect(backTexture, 0, 0, 8, 5, hairColor);
23459
+ fillTextureRect(backTexture, 1, 5, 6, 1, hairColor);
23460
+ if (hasHeadband) {
23461
+ fillTextureRect(sideTexture, 0, 2, 8, 1, headbandColor);
23462
+ fillTextureRect(backTexture, 0, 2, 8, 1, headbandColor);
23463
+ fillTextureRect(topTexture, 0, 4, 8, 1, headbandColor);
23464
+ }
23465
+ sideTexture[4][4] = `${palette.shadow}99`;
23466
+ sideTexture[5][4] = `${palette.shadow}cc`;
23467
+ backTexture[6][2] = `${palette.shadow}99`;
23468
+ backTexture[6][5] = `${palette.shadow}99`;
23469
+ return {
23470
+ front: faceTexture,
23471
+ back: backTexture,
23472
+ left: sideTexture,
23473
+ right: mirrorMinecraftTexture(sideTexture),
23474
+ top: topTexture,
23475
+ bottom: bottomTexture,
23476
+ };
23477
+ }
23478
+ /**
23479
+ * Builds the seeded six-face texture pack used by the Minecraft-style torso cuboid.
23480
+ *
23481
+ * @param random Seeded random generator.
23482
+ * @param palette Derived avatar palette.
23483
+ * @returns Torso cuboid textures.
23484
+ *
23485
+ * @private helper of the Minecraft avatar visuals
23486
+ */
23487
+ function createMinecraftTorsoTextures(random, palette) {
23488
+ const frontTexture = createMinecraftShirtTexture(random, palette);
23489
+ const sideTexture = createFilledTexture(palette.primary);
23490
+ const backTexture = createFilledTexture(palette.primary);
23491
+ const topTexture = createFilledTexture(`${palette.highlight}dd`);
23492
+ const bottomTexture = createFilledTexture(`${palette.shadow}dd`);
23493
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
23494
+ fillTextureRect(sideTexture, 0, 0, 8, 2, palette.shadow);
23495
+ fillTextureRect(backTexture, 0, 0, 8, 2, palette.shadow);
23496
+ fillTextureRect(backTexture, 3, 2, 2, 6, stripeColor);
23497
+ fillTextureRect(sideTexture, 4, 2, 1, 6, stripeColor);
23498
+ fillTextureRect(topTexture, 0, 0, 8, 2, palette.shadow);
23499
+ fillTextureRect(topTexture, 2, 2, 4, 4, stripeColor);
23500
+ return {
23501
+ front: frontTexture,
23502
+ back: backTexture,
23503
+ left: sideTexture,
23504
+ right: mirrorMinecraftTexture(sideTexture),
23505
+ top: topTexture,
23506
+ bottom: bottomTexture,
23507
+ };
23508
+ }
23509
+ /**
23510
+ * Mirrors one Minecraft texture horizontally.
23511
+ *
23512
+ * @param texture Source texture.
23513
+ * @returns Mirrored texture copy.
23514
+ *
23515
+ * @private helper of the Minecraft avatar visuals
23516
+ */
23517
+ function mirrorMinecraftTexture(texture) {
23518
+ return texture.map((row) => [...row].reverse());
23519
+ }
23520
+ /**
23521
+ * Creates the front-face pixel texture for the cube head.
23522
+ *
23523
+ * @param random Seeded random generator.
23524
+ * @param palette Derived avatar palette.
23525
+ * @param hasHeadband Whether the avatar should render a headband row.
23526
+ * @returns 8x8 pixel texture.
23527
+ *
23528
+ * @private helper of the Minecraft avatar visuals
23529
+ */
23530
+ function createMinecraftFaceTexture(random, palette, hasHeadband) {
23531
+ const texture = createFilledTexture(palette.highlight);
23532
+ const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
23533
+ const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
23534
+ fillTextureRect(texture, 0, 0, 8, 2, hairlineColor);
23535
+ texture[2][0] = hairlineColor;
23536
+ texture[2][7] = hairlineColor;
23537
+ texture[3][0] = hairlineColor;
23538
+ texture[3][7] = hairlineColor;
23539
+ if (hasHeadband) {
23540
+ fillTextureRect(texture, 0, 2, 8, 1, palette.accent);
23541
+ }
23542
+ texture[3][2] = palette.ink;
23543
+ texture[3][5] = palette.ink;
23544
+ texture[4][2] = '#ffffff';
23545
+ texture[4][5] = '#ffffff';
23546
+ texture[5][1] = cheekColor;
23547
+ texture[5][6] = cheekColor;
23548
+ texture[5][3] = palette.shadow;
23549
+ texture[5][4] = palette.shadow;
23550
+ texture[6][3] = palette.shadow;
23551
+ texture[6][4] = palette.shadow;
23552
+ return texture;
23553
+ }
23554
+ /**
23555
+ * Creates the front-face pixel texture for the torso.
23556
+ *
23557
+ * @param random Seeded random generator.
23558
+ * @param palette Derived avatar palette.
23559
+ * @returns 8x8 torso texture.
23560
+ *
23561
+ * @private helper of the Minecraft avatar visuals
23562
+ */
23563
+ function createMinecraftShirtTexture(random, palette) {
23564
+ const texture = createFilledTexture(palette.primary);
23565
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
23566
+ fillTextureRect(texture, 0, 0, 8, 2, palette.shadow);
23567
+ for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
23568
+ texture[rowIndex][3] = stripeColor;
23569
+ texture[rowIndex][4] = stripeColor;
23570
+ }
23571
+ texture[4][1] = palette.accent;
23572
+ texture[4][6] = palette.accent;
23573
+ texture[5][2] = palette.highlight;
23574
+ texture[5][5] = palette.highlight;
23575
+ return texture;
23576
+ }
23577
+ /**
23578
+ * Creates one solid-color 8x8 Minecraft texture.
23579
+ *
23580
+ * @param color Fill color.
23581
+ * @returns Filled 8x8 texture.
23582
+ *
23583
+ * @private helper of the Minecraft avatar visuals
23584
+ */
23585
+ function createFilledTexture(color) {
23586
+ return Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => color));
23587
+ }
23588
+ /**
23589
+ * Fills one rectangular area inside a mutable Minecraft texture.
23590
+ *
23591
+ * @param texture Mutable target texture.
23592
+ * @param x Left texture coordinate.
23593
+ * @param y Top texture coordinate.
23594
+ * @param width Rectangle width.
23595
+ * @param height Rectangle height.
23596
+ * @param color Fill color.
23597
+ *
23598
+ * @private helper of the Minecraft avatar visuals
23599
+ */
23600
+ function fillTextureRect(texture, x, y, width, height, color) {
23601
+ for (let rowIndex = y; rowIndex < y + height; rowIndex++) {
23602
+ for (let columnIndex = x; columnIndex < x + width; columnIndex++) {
23603
+ texture[rowIndex][columnIndex] = color;
23604
+ }
23605
+ }
23606
+ }
23607
+
23555
23608
  /* eslint-disable no-magic-numbers */
23556
23609
  /**
23557
23610
  * Minecraft-style 3D avatar visual.
@@ -23576,8 +23629,8 @@
23576
23629
  const bodyX = size * 0.33;
23577
23630
  const bodyY = headY + headSize * 0.96;
23578
23631
  const hasHeadband = random() < 0.5;
23579
- const faceTexture = createMinecraftFaceTexture(createRandom('minecraft-face'), palette, hasHeadband);
23580
- const shirtTexture = createMinecraftShirtTexture(createRandom('minecraft-shirt'), palette);
23632
+ const headTextures = createMinecraftHeadTextures(createRandom('minecraft-face'), palette, hasHeadband);
23633
+ const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft-shirt'), palette);
23581
23634
  drawAvatarFrame(context, size, palette);
23582
23635
  const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
23583
23636
  spotlight.addColorStop(0, `${palette.highlight}66`);
@@ -23597,7 +23650,7 @@
23597
23650
  width: bodyWidth,
23598
23651
  height: bodyHeight,
23599
23652
  depth: bodyDepth,
23600
- frontTexture: shirtTexture,
23653
+ frontTexture: torsoTextures.front,
23601
23654
  topColor: `${palette.highlight}cc`,
23602
23655
  sideColor: `${palette.secondary}dd`,
23603
23656
  outlineColor: `${palette.shadow}aa`,
@@ -23608,7 +23661,7 @@
23608
23661
  width: headSize,
23609
23662
  height: headSize,
23610
23663
  depth,
23611
- frontTexture: faceTexture,
23664
+ frontTexture: headTextures.front,
23612
23665
  topColor: `${palette.highlight}ee`,
23613
23666
  sideColor: `${palette.secondary}ee`,
23614
23667
  outlineColor: `${palette.shadow}cc`,
@@ -23673,72 +23726,505 @@
23673
23726
  context.closePath();
23674
23727
  context.stroke();
23675
23728
  }
23729
+
23730
+ /* eslint-disable no-magic-numbers */
23676
23731
  /**
23677
- * Creates the front-face pixel texture for the cube head.
23732
+ * Fixed scene camera distance used for the proper-3D projection.
23678
23733
  *
23679
- * @param random Seeded random generator.
23734
+ * @private helper of `minecraft2AvatarVisual`
23735
+ */
23736
+ const CAMERA_DISTANCE_RATIO = 1.4;
23737
+ /**
23738
+ * Shared light direction used to shade projected cuboid faces.
23739
+ *
23740
+ * @private helper of `minecraft2AvatarVisual`
23741
+ */
23742
+ const LIGHT_DIRECTION = normalizeVector3({
23743
+ x: 0.4,
23744
+ y: -0.65,
23745
+ z: 0.92,
23746
+ });
23747
+ /**
23748
+ * Minecraft 3D 2 avatar visual.
23749
+ *
23750
+ * @private built-in avatar visual
23751
+ */
23752
+ const minecraft2AvatarVisual = {
23753
+ id: 'minecraft2',
23754
+ title: 'Minecraft 3D 2',
23755
+ description: 'Proper 3D Minecraft-style portrait with textured cuboids and pointer-driven head turns.',
23756
+ isAnimated: true,
23757
+ supportsPointerTracking: true,
23758
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
23759
+ const spotlightY = size * 0.22;
23760
+ const headRandom = createRandom('minecraft2-head');
23761
+ const hasHeadband = headRandom() < 0.5;
23762
+ const headTextures = createMinecraftHeadTextures(createRandom('minecraft2-head-textures'), palette, hasHeadband);
23763
+ const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft2-body-textures'), palette);
23764
+ const bob = Math.sin(timeMs / 880) * size * 0.014;
23765
+ const bodyYaw = -0.24 + Math.sin(timeMs / 2300) * 0.06 + interaction.bodyOffsetX * 0.16;
23766
+ const bodyPitch = -0.12 + Math.cos(timeMs / 2800) * 0.02 - interaction.bodyOffsetY * 0.06;
23767
+ const headYaw = -0.18 + Math.sin(timeMs / 1900 + 0.6) * 0.05 + interaction.gazeX * 0.62;
23768
+ const headPitch = -0.12 + Math.cos(timeMs / 2400 + 1.1) * 0.03 - interaction.gazeY * 0.38;
23769
+ const sceneCenterX = size * 0.5;
23770
+ const sceneCenterY = size * 0.57;
23771
+ const bodyWidth = size * 0.225;
23772
+ const bodyHeight = size * 0.245;
23773
+ const bodyDepth = size * 0.145;
23774
+ const headSize = size * 0.24;
23775
+ const headLift = size * 0.205;
23776
+ const headForwardShift = interaction.intensity * size * 0.018;
23777
+ const sceneCuboids = [
23778
+ {
23779
+ center: {
23780
+ x: interaction.bodyOffsetX * size * 0.026,
23781
+ y: size * 0.05 + interaction.bodyOffsetY * size * 0.018 + bob,
23782
+ z: 0,
23783
+ },
23784
+ width: bodyWidth,
23785
+ height: bodyHeight,
23786
+ depth: bodyDepth,
23787
+ rotationX: bodyPitch,
23788
+ rotationY: bodyYaw,
23789
+ textures: torsoTextures,
23790
+ outlineColor: `${palette.shadow}cc`,
23791
+ },
23792
+ {
23793
+ center: {
23794
+ x: interaction.bodyOffsetX * size * 0.018 + interaction.gazeX * size * 0.016,
23795
+ y: -headLift + bob * 1.15,
23796
+ z: headForwardShift,
23797
+ },
23798
+ width: headSize,
23799
+ height: headSize,
23800
+ depth: headSize,
23801
+ rotationX: headPitch,
23802
+ rotationY: headYaw,
23803
+ textures: headTextures,
23804
+ outlineColor: `${palette.shadow}dd`,
23805
+ },
23806
+ ];
23807
+ const visibleFaces = sceneCuboids
23808
+ .flatMap((cuboid) => resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY))
23809
+ .sort((firstFace, secondFace) => firstFace.averageDepth - secondFace.averageDepth);
23810
+ drawAvatarFrame(context, size, palette);
23811
+ drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs);
23812
+ drawMinecraftShadow(context, size, palette, interaction, timeMs);
23813
+ for (const visibleFace of visibleFaces) {
23814
+ drawTexturedProjectedFace(context, visibleFace);
23815
+ }
23816
+ },
23817
+ };
23818
+ /**
23819
+ * Draws the shared background atmosphere behind the Minecraft 3D 2 portrait.
23820
+ *
23821
+ * @param context Canvas 2D context.
23822
+ * @param size Canvas size in CSS pixels.
23680
23823
  * @param palette Derived avatar palette.
23681
- * @param hasHeadband Whether the avatar should render a headband row.
23682
- * @returns 8x8 pixel texture.
23824
+ * @param sceneCenterX Horizontal scene center.
23825
+ * @param spotlightY Vertical spotlight anchor.
23826
+ * @param interaction Smoothed pointer-aware interaction state.
23827
+ * @param timeMs Current animation time in milliseconds.
23683
23828
  *
23684
- * @private helper of `minecraftAvatarVisual`
23829
+ * @private helper of `minecraft2AvatarVisual`
23685
23830
  */
23686
- function createMinecraftFaceTexture(random, palette, hasHeadband) {
23687
- const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.highlight));
23688
- const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
23689
- const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
23690
- for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
23691
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
23692
- texture[rowIndex][columnIndex] = hairlineColor;
23831
+ function drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs) {
23832
+ const spotlightGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.08, spotlightY + interaction.gazeY * size * 0.05, size * 0.03, sceneCenterX, spotlightY, size * 0.52);
23833
+ spotlightGradient.addColorStop(0, `${palette.highlight}66`);
23834
+ spotlightGradient.addColorStop(0.42, `${palette.accent}1d`);
23835
+ spotlightGradient.addColorStop(1, `${palette.highlight}00`);
23836
+ context.fillStyle = spotlightGradient;
23837
+ context.fillRect(0, 0, size, size);
23838
+ const rimGradient = context.createLinearGradient(0, size * 0.14, 0, size * 0.92);
23839
+ rimGradient.addColorStop(0, `${palette.highlight}12`);
23840
+ rimGradient.addColorStop(0.55, `${palette.secondary}0a`);
23841
+ rimGradient.addColorStop(1, `${palette.shadow}00`);
23842
+ context.fillStyle = rimGradient;
23843
+ context.fillRect(0, 0, size, size);
23844
+ context.save();
23845
+ context.globalAlpha = 0.08 + interaction.intensity * 0.04;
23846
+ context.fillStyle = palette.highlight;
23847
+ context.beginPath();
23848
+ context.arc(size * 0.72 + Math.sin(timeMs / 1600) * size * 0.03, size * 0.2 + Math.cos(timeMs / 1400) * size * 0.018, size * 0.025, 0, Math.PI * 2);
23849
+ context.fill();
23850
+ context.restore();
23851
+ }
23852
+ /**
23853
+ * Draws the soft floor shadow used to anchor the cuboids in the frame.
23854
+ *
23855
+ * @param context Canvas 2D context.
23856
+ * @param size Canvas size in CSS pixels.
23857
+ * @param palette Derived avatar palette.
23858
+ * @param interaction Smoothed pointer-aware interaction state.
23859
+ * @param timeMs Current animation time in milliseconds.
23860
+ *
23861
+ * @private helper of `minecraft2AvatarVisual`
23862
+ */
23863
+ function drawMinecraftShadow(context, size, palette, interaction, timeMs) {
23864
+ context.save();
23865
+ context.fillStyle = `${palette.shadow}66`;
23866
+ context.filter = `blur(${size * 0.02}px)`;
23867
+ context.beginPath();
23868
+ context.ellipse(size * 0.5 + interaction.gazeX * size * 0.03, size * 0.85 + Math.sin(timeMs / 880) * size * 0.01, size * (0.16 + interaction.intensity * 0.015), size * 0.055, 0, 0, Math.PI * 2);
23869
+ context.fill();
23870
+ context.restore();
23871
+ }
23872
+ /**
23873
+ * Resolves all visible projected faces for one scene cuboid.
23874
+ *
23875
+ * @param cuboid Scene cuboid definition.
23876
+ * @param size Canvas size in CSS pixels.
23877
+ * @param sceneCenterX Horizontal scene center.
23878
+ * @param sceneCenterY Vertical scene center.
23879
+ * @returns Visible faces sorted later by depth.
23880
+ *
23881
+ * @private helper of `minecraft2AvatarVisual`
23882
+ */
23883
+ function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
23884
+ const halfWidth = cuboid.width / 2;
23885
+ const halfHeight = cuboid.height / 2;
23886
+ const halfDepth = cuboid.depth / 2;
23887
+ const faceDefinitions = [
23888
+ {
23889
+ texture: cuboid.textures.front,
23890
+ corners: [
23891
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
23892
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
23893
+ { x: halfWidth, y: halfHeight, z: halfDepth },
23894
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
23895
+ ],
23896
+ },
23897
+ {
23898
+ texture: cuboid.textures.back,
23899
+ corners: [
23900
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
23901
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
23902
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
23903
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
23904
+ ],
23905
+ },
23906
+ {
23907
+ texture: cuboid.textures.right,
23908
+ corners: [
23909
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
23910
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
23911
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
23912
+ { x: halfWidth, y: halfHeight, z: halfDepth },
23913
+ ],
23914
+ },
23915
+ {
23916
+ texture: cuboid.textures.left,
23917
+ corners: [
23918
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
23919
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
23920
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
23921
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
23922
+ ],
23923
+ },
23924
+ {
23925
+ texture: cuboid.textures.top,
23926
+ corners: [
23927
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
23928
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
23929
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
23930
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
23931
+ ],
23932
+ },
23933
+ {
23934
+ texture: cuboid.textures.bottom,
23935
+ corners: [
23936
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
23937
+ { x: halfWidth, y: halfHeight, z: halfDepth },
23938
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
23939
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
23940
+ ],
23941
+ },
23942
+ ];
23943
+ const visibleFaces = faceDefinitions
23944
+ .map((faceDefinition) => {
23945
+ const transformedCorners = faceDefinition.corners.map((corner) => transformScenePoint(corner, cuboid.center, cuboid.rotationX, cuboid.rotationY));
23946
+ const faceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
23947
+ if (faceNormal.z <= 0.02) {
23948
+ return null;
23693
23949
  }
23950
+ const projectedCorners = transformedCorners.map((corner) => projectScenePoint(corner, size, sceneCenterX, sceneCenterY));
23951
+ return {
23952
+ corners: projectedCorners,
23953
+ texture: faceDefinition.texture,
23954
+ averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
23955
+ lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION), -1, 1),
23956
+ outlineColor: cuboid.outlineColor,
23957
+ };
23958
+ });
23959
+ return visibleFaces.filter((visibleFace) => visibleFace !== null);
23960
+ }
23961
+ /**
23962
+ * Draws one projected textured face by tessellating its texture cells into quads.
23963
+ *
23964
+ * @param context Canvas 2D context.
23965
+ * @param face Visible projected face.
23966
+ *
23967
+ * @private helper of `minecraft2AvatarVisual`
23968
+ */
23969
+ function drawTexturedProjectedFace(context, face) {
23970
+ var _a;
23971
+ const rows = face.texture.length;
23972
+ const columns = ((_a = face.texture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
23973
+ if (rows === 0 || columns === 0) {
23974
+ return;
23694
23975
  }
23695
- texture[2][0] = hairlineColor;
23696
- texture[2][7] = hairlineColor;
23697
- texture[3][0] = hairlineColor;
23698
- texture[3][7] = hairlineColor;
23699
- if (hasHeadband) {
23700
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
23701
- texture[2][columnIndex] = palette.accent;
23976
+ for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
23977
+ for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
23978
+ const startX = columnIndex / columns;
23979
+ const endX = (columnIndex + 1) / columns;
23980
+ const startY = rowIndex / rows;
23981
+ const endY = (rowIndex + 1) / rows;
23982
+ drawProjectedQuad(context, [
23983
+ interpolateProjectedQuad(face.corners, startX, startY),
23984
+ interpolateProjectedQuad(face.corners, endX, startY),
23985
+ interpolateProjectedQuad(face.corners, endX, endY),
23986
+ interpolateProjectedQuad(face.corners, startX, endY),
23987
+ ], face.texture[rowIndex][columnIndex]);
23702
23988
  }
23703
23989
  }
23704
- texture[3][2] = palette.ink;
23705
- texture[3][5] = palette.ink;
23706
- texture[4][2] = '#ffffff';
23707
- texture[4][5] = '#ffffff';
23708
- texture[5][1] = cheekColor;
23709
- texture[5][6] = cheekColor;
23710
- texture[5][3] = palette.shadow;
23711
- texture[5][4] = palette.shadow;
23712
- texture[6][3] = palette.shadow;
23713
- texture[6][4] = palette.shadow;
23714
- return texture;
23990
+ if (face.lightIntensity > 0) {
23991
+ drawProjectedQuad(context, face.corners, `rgba(255, 255, 255, ${0.15 * face.lightIntensity})`);
23992
+ }
23993
+ else if (face.lightIntensity < 0) {
23994
+ drawProjectedQuad(context, face.corners, `rgba(0, 0, 0, ${0.22 * Math.abs(face.lightIntensity)})`);
23995
+ }
23996
+ context.save();
23997
+ context.beginPath();
23998
+ context.moveTo(face.corners[0].x, face.corners[0].y);
23999
+ for (let cornerIndex = 1; cornerIndex < face.corners.length; cornerIndex++) {
24000
+ context.lineTo(face.corners[cornerIndex].x, face.corners[cornerIndex].y);
24001
+ }
24002
+ context.closePath();
24003
+ context.strokeStyle = face.outlineColor;
24004
+ context.lineWidth = Math.max(1.1, getProjectedQuadPerimeter(face.corners) * 0.0045);
24005
+ context.lineJoin = 'round';
24006
+ context.stroke();
24007
+ context.restore();
23715
24008
  }
23716
24009
  /**
23717
- * Creates the front-face pixel texture for the torso.
24010
+ * Draws one filled projected quad.
23718
24011
  *
23719
- * @param random Seeded random generator.
23720
- * @param palette Derived avatar palette.
23721
- * @returns 8x8 torso texture.
24012
+ * @param context Canvas 2D context.
24013
+ * @param corners Quad corners in clockwise order.
24014
+ * @param fillStyle CSS fill style.
23722
24015
  *
23723
- * @private helper of `minecraftAvatarVisual`
24016
+ * @private helper of `minecraft2AvatarVisual`
23724
24017
  */
23725
- function createMinecraftShirtTexture(random, palette) {
23726
- const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.primary));
23727
- const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
23728
- for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
23729
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
23730
- texture[rowIndex][columnIndex] = palette.shadow;
23731
- }
24018
+ function drawProjectedQuad(context, corners, fillStyle) {
24019
+ context.beginPath();
24020
+ context.moveTo(corners[0].x, corners[0].y);
24021
+ context.lineTo(corners[1].x, corners[1].y);
24022
+ context.lineTo(corners[2].x, corners[2].y);
24023
+ context.lineTo(corners[3].x, corners[3].y);
24024
+ context.closePath();
24025
+ context.fillStyle = fillStyle;
24026
+ context.fill();
24027
+ }
24028
+ /**
24029
+ * Interpolates one point inside a projected quad across both quad axes.
24030
+ *
24031
+ * @param corners Quad corners in clockwise order.
24032
+ * @param horizontalRatio Horizontal ratio in the range `[0, 1]`.
24033
+ * @param verticalRatio Vertical ratio in the range `[0, 1]`.
24034
+ * @returns Interpolated projected point.
24035
+ *
24036
+ * @private helper of `minecraft2AvatarVisual`
24037
+ */
24038
+ function interpolateProjectedQuad(corners, horizontalRatio, verticalRatio) {
24039
+ const topPoint = interpolateProjectedPoint(corners[0], corners[1], horizontalRatio);
24040
+ const bottomPoint = interpolateProjectedPoint(corners[3], corners[2], horizontalRatio);
24041
+ return interpolateProjectedPoint(topPoint, bottomPoint, verticalRatio);
24042
+ }
24043
+ /**
24044
+ * Interpolates between two projected points.
24045
+ *
24046
+ * @param startPoint Start point.
24047
+ * @param endPoint End point.
24048
+ * @param ratio Interpolation ratio in the range `[0, 1]`.
24049
+ * @returns Interpolated projected point.
24050
+ *
24051
+ * @private helper of `minecraft2AvatarVisual`
24052
+ */
24053
+ function interpolateProjectedPoint(startPoint, endPoint, ratio) {
24054
+ return {
24055
+ x: startPoint.x + (endPoint.x - startPoint.x) * ratio,
24056
+ y: startPoint.y + (endPoint.y - startPoint.y) * ratio,
24057
+ z: startPoint.z + (endPoint.z - startPoint.z) * ratio,
24058
+ };
24059
+ }
24060
+ /**
24061
+ * Projects one rotated scene point into canvas coordinates.
24062
+ *
24063
+ * @param point Scene point.
24064
+ * @param size Canvas size in CSS pixels.
24065
+ * @param sceneCenterX Horizontal scene center.
24066
+ * @param sceneCenterY Vertical scene center.
24067
+ * @returns Projected point.
24068
+ *
24069
+ * @private helper of `minecraft2AvatarVisual`
24070
+ */
24071
+ function projectScenePoint(point, size, sceneCenterX, sceneCenterY) {
24072
+ const cameraDistance = size * CAMERA_DISTANCE_RATIO;
24073
+ const perspectiveScale = cameraDistance / Math.max(cameraDistance - point.z, cameraDistance * 0.35);
24074
+ return {
24075
+ x: sceneCenterX + point.x * perspectiveScale,
24076
+ y: sceneCenterY + point.y * perspectiveScale,
24077
+ z: point.z,
24078
+ };
24079
+ }
24080
+ /**
24081
+ * Applies the local cuboid rotations and translation to one scene point.
24082
+ *
24083
+ * @param localPoint Point in cuboid-local space.
24084
+ * @param center Cuboid center in scene space.
24085
+ * @param rotationX Cuboid pitch in radians.
24086
+ * @param rotationY Cuboid yaw in radians.
24087
+ * @returns Transformed scene-space point.
24088
+ *
24089
+ * @private helper of `minecraft2AvatarVisual`
24090
+ */
24091
+ function transformScenePoint(localPoint, center, rotationX, rotationY) {
24092
+ const yawedPoint = rotatePointAroundY(localPoint, rotationY);
24093
+ const pitchedPoint = rotatePointAroundX(yawedPoint, rotationX);
24094
+ return {
24095
+ x: center.x + pitchedPoint.x,
24096
+ y: center.y + pitchedPoint.y,
24097
+ z: center.z + pitchedPoint.z,
24098
+ };
24099
+ }
24100
+ /**
24101
+ * Rotates one point around the local Y axis.
24102
+ *
24103
+ * @param point Source point.
24104
+ * @param angle Rotation angle in radians.
24105
+ * @returns Rotated point.
24106
+ *
24107
+ * @private helper of `minecraft2AvatarVisual`
24108
+ */
24109
+ function rotatePointAroundY(point, angle) {
24110
+ const cosine = Math.cos(angle);
24111
+ const sine = Math.sin(angle);
24112
+ return {
24113
+ x: point.x * cosine + point.z * sine,
24114
+ y: point.y,
24115
+ z: -point.x * sine + point.z * cosine,
24116
+ };
24117
+ }
24118
+ /**
24119
+ * Rotates one point around the local X axis.
24120
+ *
24121
+ * @param point Source point.
24122
+ * @param angle Rotation angle in radians.
24123
+ * @returns Rotated point.
24124
+ *
24125
+ * @private helper of `minecraft2AvatarVisual`
24126
+ */
24127
+ function rotatePointAroundX(point, angle) {
24128
+ const cosine = Math.cos(angle);
24129
+ const sine = Math.sin(angle);
24130
+ return {
24131
+ x: point.x,
24132
+ y: point.y * cosine - point.z * sine,
24133
+ z: point.y * sine + point.z * cosine,
24134
+ };
24135
+ }
24136
+ /**
24137
+ * Subtracts one 3D point from another.
24138
+ *
24139
+ * @param leftPoint Left point.
24140
+ * @param rightPoint Right point.
24141
+ * @returns Difference vector.
24142
+ *
24143
+ * @private helper of `minecraft2AvatarVisual`
24144
+ */
24145
+ function subtractPoint3D(leftPoint, rightPoint) {
24146
+ return {
24147
+ x: leftPoint.x - rightPoint.x,
24148
+ y: leftPoint.y - rightPoint.y,
24149
+ z: leftPoint.z - rightPoint.z,
24150
+ };
24151
+ }
24152
+ /**
24153
+ * Computes the 3D cross product of two vectors.
24154
+ *
24155
+ * @param leftVector Left vector.
24156
+ * @param rightVector Right vector.
24157
+ * @returns Cross product.
24158
+ *
24159
+ * @private helper of `minecraft2AvatarVisual`
24160
+ */
24161
+ function crossProduct3D(leftVector, rightVector) {
24162
+ return {
24163
+ x: leftVector.y * rightVector.z - leftVector.z * rightVector.y,
24164
+ y: leftVector.z * rightVector.x - leftVector.x * rightVector.z,
24165
+ z: leftVector.x * rightVector.y - leftVector.y * rightVector.x,
24166
+ };
24167
+ }
24168
+ /**
24169
+ * Computes the 3D dot product of two vectors.
24170
+ *
24171
+ * @param leftVector Left vector.
24172
+ * @param rightVector Right vector.
24173
+ * @returns Dot product.
24174
+ *
24175
+ * @private helper of `minecraft2AvatarVisual`
24176
+ */
24177
+ function dotProduct3D(leftVector, rightVector) {
24178
+ return leftVector.x * rightVector.x + leftVector.y * rightVector.y + leftVector.z * rightVector.z;
24179
+ }
24180
+ /**
24181
+ * Normalizes one 3D vector while keeping zero vectors stable.
24182
+ *
24183
+ * @param vector Source vector.
24184
+ * @returns Normalized vector.
24185
+ *
24186
+ * @private helper of `minecraft2AvatarVisual`
24187
+ */
24188
+ function normalizeVector3(vector) {
24189
+ const length = Math.hypot(vector.x, vector.y, vector.z);
24190
+ if (length === 0) {
24191
+ return vector;
23732
24192
  }
23733
- for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
23734
- texture[rowIndex][3] = stripeColor;
23735
- texture[rowIndex][4] = stripeColor;
24193
+ return {
24194
+ x: vector.x / length,
24195
+ y: vector.y / length,
24196
+ z: vector.z / length,
24197
+ };
24198
+ }
24199
+ /**
24200
+ * Clamps one number into the provided range.
24201
+ *
24202
+ * @param value Input value.
24203
+ * @param minimumValue Inclusive lower bound.
24204
+ * @param maximumValue Inclusive upper bound.
24205
+ * @returns Clamped value.
24206
+ *
24207
+ * @private helper of `minecraft2AvatarVisual`
24208
+ */
24209
+ function clampNumber$1(value, minimumValue, maximumValue) {
24210
+ return Math.min(maximumValue, Math.max(minimumValue, value));
24211
+ }
24212
+ /**
24213
+ * Measures the perimeter of one projected quad.
24214
+ *
24215
+ * @param corners Quad corners.
24216
+ * @returns Perimeter length.
24217
+ *
24218
+ * @private helper of `minecraft2AvatarVisual`
24219
+ */
24220
+ function getProjectedQuadPerimeter(corners) {
24221
+ let perimeter = 0;
24222
+ for (let cornerIndex = 0; cornerIndex < corners.length; cornerIndex++) {
24223
+ const currentCorner = corners[cornerIndex];
24224
+ const nextCorner = corners[(cornerIndex + 1) % corners.length];
24225
+ perimeter += Math.hypot(nextCorner.x - currentCorner.x, nextCorner.y - currentCorner.y);
23736
24226
  }
23737
- texture[4][1] = palette.accent;
23738
- texture[4][6] = palette.accent;
23739
- texture[5][2] = palette.highlight;
23740
- texture[5][5] = palette.highlight;
23741
- return texture;
24227
+ return perimeter;
23742
24228
  }
23743
24229
 
23744
24230
  /* eslint-disable no-magic-numbers */
@@ -25343,6 +25829,7 @@
25343
25829
  octopus3AvatarVisual,
25344
25830
  asciiOctopusAvatarVisual,
25345
25831
  minecraftAvatarVisual,
25832
+ minecraft2AvatarVisual,
25346
25833
  fractalAvatarVisual,
25347
25834
  orbAvatarVisual,
25348
25835
  ];
@@ -26645,7 +27132,11 @@
26645
27132
  // Create new system message with persona at the beginning
26646
27133
  // Format: "You are {agentName}\n{personaContent}"
26647
27134
  // The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
26648
- const personaSection = `# PERSONA\nYou are ${agentName}\n${mergedPersonaContent}`; // <- TODO: Use spaceTrim
27135
+ const personaSection = _spaceTrim.spaceTrim((block) => `
27136
+ # PERSONA
27137
+ You are ${agentName}
27138
+ ${block(mergedPersonaContent)}
27139
+ `);
26649
27140
  const newSystemMessage = cleanedMessage ? `${personaSection}\n\n${cleanedMessage}` : personaSection;
26650
27141
  return {
26651
27142
  ...requirements,
@@ -27547,7 +28038,10 @@
27547
28038
  */
27548
28039
  function buildTeamToolDescription(entry) {
27549
28040
  const detailLines = collectTeamEntryDetails(entry).map(({ label, content }) => `${label}: ${content}`);
27550
- return [`Consult teammate ${entry.teammate.label}`, ...detailLines].join('\n');
28041
+ return _spaceTrim.spaceTrim((block) => `
28042
+ Consult teammate ${entry.teammate.label}
28043
+ ${block(detailLines.join('\n'))}
28044
+ `);
27551
28045
  }
27552
28046
  /**
27553
28047
  * Collects structured teammate details that should stay visible to the model.
@@ -32834,7 +33328,10 @@
32834
33328
  if (hiddenCount > 0) {
32835
33329
  summaryRows.push(`...and ${hiddenCount} more.`);
32836
33330
  }
32837
- return [`Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:`, ...summaryRows].join('\n');
33331
+ return _spaceTrim.spaceTrim((block) => `
33332
+ Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
33333
+ ${block(summaryRows.join('\n'))}
33334
+ `);
32838
33335
  }
32839
33336
  /**
32840
33337
  * Formats one timeout row for assistant-visible timeout listings.
@@ -36246,7 +36743,7 @@
36246
36743
  */
36247
36744
  async function prepareSdkTranspilerContext(book, options) {
36248
36745
  const { agentName } = await parseAgentSource(book);
36249
- const rawModelRequirements = await createAgentModelRequirements(book, undefined, undefined, undefined, {
36746
+ const modelRequirements = await createAgentModelRequirements(book, undefined, undefined, undefined, {
36250
36747
  agentReferenceResolver: options === null || options === void 0 ? void 0 : options.agentReferenceResolver,
36251
36748
  inlineKnowledgeSourceUploader: options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader,
36252
36749
  teammateProfileResolver: options === null || options === void 0 ? void 0 : options.teammateProfileResolver,
@@ -36256,12 +36753,7 @@
36256
36753
  const knowledgeContent = knowledgeCommitments.map((commitment) => commitment.content.trim());
36257
36754
  const directKnowledge = knowledgeContent.filter((content) => !isKnowledgeSourceUrl(content));
36258
36755
  const knowledgeSources = knowledgeContent.filter((content) => isKnowledgeSourceUrl(content));
36259
- const isKnowledgeHandledWithRetrieval = directKnowledge.join('\n').length > SDK_TRANSPILER_KNOWLEDGE_THRESHOLD ||
36260
- knowledgeSources.length > 0 ||
36261
- knowledgeCommitments.length > 0;
36262
- const modelRequirements = normalizeSdkTranspilerModelRequirements(rawModelRequirements, {
36263
- isKnowledgeHandledWithRetrieval,
36264
- });
36756
+ const isKnowledgeHandledWithRetrieval = directKnowledge.join('\n').length > SDK_TRANSPILER_KNOWLEDGE_THRESHOLD || knowledgeSources.length > 0;
36265
36757
  const transpiledTeam = createTranspiledTeamExportForContext({
36266
36758
  agentName,
36267
36759
  agentSource: book,
@@ -36279,36 +36771,6 @@
36279
36771
  transpiledTeam,
36280
36772
  };
36281
36773
  }
36282
- /**
36283
- * Removes the runtime-only knowledge-search tool from SDK harnesses that provide
36284
- * their own generated retrieval scaffold.
36285
- *
36286
- * @param modelRequirements - Raw compiled model requirements.
36287
- * @param options - Knowledge handling mode selected for the generated harness.
36288
- * @returns Model requirements safe to embed into a standalone SDK export.
36289
- */
36290
- function normalizeSdkTranspilerModelRequirements(modelRequirements, options) {
36291
- var _a;
36292
- if (!options.isKnowledgeHandledWithRetrieval) {
36293
- return modelRequirements;
36294
- }
36295
- const tools = (_a = modelRequirements.tools) === null || _a === void 0 ? void 0 : _a.filter((tool) => tool.name !== KNOWLEDGE_SEARCH_TOOL_NAME);
36296
- return {
36297
- ...modelRequirements,
36298
- systemMessage: removeKnowledgeSearchSystemSection(modelRequirements.systemMessage),
36299
- ...(tools ? { tools } : {}),
36300
- };
36301
- }
36302
- /**
36303
- * Removes the generated `## Knowledge Search` instructions from SDK exports
36304
- * that answer with the transpiler's native retrieval scaffold instead.
36305
- *
36306
- * @param systemMessage - Raw system message from compiled model requirements.
36307
- * @returns System message without the runtime-only knowledge-search section.
36308
- */
36309
- function removeKnowledgeSearchSystemSection(systemMessage) {
36310
- return systemMessage.replace(/(?:^|\n\n)## Knowledge Search[\s\S]*?(?=\n\n##|$)/, '').trim();
36311
- }
36312
36774
  /**
36313
36775
  * Detects whether one knowledge commitment points to a URL instead of inline text.
36314
36776
  *
@@ -41581,8 +42043,10 @@
41581
42043
  */
41582
42044
  const MatcherFormfactorDefinition = {
41583
42045
  name: 'EXPERIMENTAL_MATCHER',
41584
- description: `An evaluation system that determines whether content meets specific criteria or patterns.
41585
- Used for content validation, quality assessment, and intelligent filtering tasks. Currently in experimental phase.`,
42046
+ description: _spaceTrim.spaceTrim(`
42047
+ An evaluation system that determines whether content meets specific criteria or patterns.
42048
+ Used for content validation, quality assessment, and intelligent filtering tasks. Currently in experimental phase.
42049
+ `),
41586
42050
  documentationUrl: `https://github.com/webgptorg/promptbook/discussions/177`,
41587
42051
  pipelineInterface: {
41588
42052
  inputParameters: [
@@ -41639,9 +42103,11 @@
41639
42103
  */
41640
42104
  const TranslatorFormfactorDefinition = {
41641
42105
  name: 'TRANSLATOR',
41642
- description: `A text transformation system that converts input content into different forms,
41643
- including language translations, paraphrasing, style conversions, and tone adjustments.
41644
- This form factor takes one input and produces one transformed output.`,
42106
+ description: _spaceTrim.spaceTrim(`
42107
+ A text transformation system that converts input content into different forms,
42108
+ including language translations, paraphrasing, style conversions, and tone adjustments.
42109
+ This form factor takes one input and produces one transformed output.
42110
+ `),
41645
42111
  documentationUrl: `https://github.com/webgptorg/promptbook/discussions/175`,
41646
42112
  pipelineInterface: {
41647
42113
  inputParameters: [
@@ -43001,12 +43467,21 @@
43001
43467
  // <- TODO: [🧠] Make this dynamic, async, prepare-phase HLAs
43002
43468
  ],
43003
43469
  });
43004
- // TODO: Use spaceTrim in multiline strings
43005
43470
  $pipelineJson.tasks.push({
43006
43471
  taskType: 'PROMPT_TASK',
43007
43472
  name: 'create-an-answer',
43008
43473
  title: 'Create an answer',
43009
- content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
43474
+ content: _spaceTrim.spaceTrim(`
43475
+ Write a response to the user message:
43476
+
43477
+ **Question from user**
43478
+
43479
+ > {userMessage}
43480
+
43481
+ **Previous conversation**
43482
+
43483
+ > {previousConversationSummary}
43484
+ `),
43010
43485
  resultingParameterName: 'chatbotResponse',
43011
43486
  personaName,
43012
43487
  dependentParameterNames: [
@@ -43018,7 +43493,26 @@
43018
43493
  taskType: 'PROMPT_TASK',
43019
43494
  name: 'summarize-the-conversation',
43020
43495
  title: 'Summarize the conversation',
43021
- content: 'Summarize the conversation in a few words:\n\n## Rules\n\n- Summarise the text of the conversation in a few words\n- Convert the text to its basic idea\n- Imagine you are writing the headline or subject line of an email\n- Respond with a few words of summary only\n\n## Conversation\n\n**User:**\n\n> {userMessage}\n\n**You:**\n\n> {chatbotResponse}',
43496
+ content: _spaceTrim.spaceTrim(`
43497
+ Summarize the conversation in a few words:
43498
+
43499
+ ## Rules
43500
+
43501
+ - Summarise the text of the conversation in a few words
43502
+ - Convert the text to its basic idea
43503
+ - Imagine you are writing the headline or subject line of an email
43504
+ - Respond with a few words of summary only
43505
+
43506
+ ## Conversation
43507
+
43508
+ **User:**
43509
+
43510
+ > {userMessage}
43511
+
43512
+ **You:**
43513
+
43514
+ > {chatbotResponse}
43515
+ `),
43022
43516
  resultingParameterName: 'conversationSummary',
43023
43517
  personaName,
43024
43518
  expectations: {
@@ -45401,11 +45895,11 @@
45401
45895
  if (attachments.length === 0) {
45402
45896
  return '';
45403
45897
  }
45404
- return [
45405
- CHAT_ATTACHMENTS_HEADING,
45406
- ...attachments.map((attachment) => formatChatAttachmentLine(attachment)),
45407
- CHAT_ATTACHMENTS_INSTRUCTION,
45408
- ].join('\n');
45898
+ return _spaceTrim.spaceTrim((block) => `
45899
+ ${CHAT_ATTACHMENTS_HEADING}
45900
+ ${block(attachments.map((attachment) => formatChatAttachmentLine(attachment)).join('\n'))}
45901
+ ${CHAT_ATTACHMENTS_INSTRUCTION}
45902
+ `);
45409
45903
  }
45410
45904
 
45411
45905
  /**
@@ -45646,24 +46140,24 @@
45646
46140
  : ''}`
45647
46141
  : null;
45648
46142
  const warningsLine = contentResolution.warnings.length > 0 ? `Warnings: ${contentResolution.warnings.join(' | ')}` : null;
45649
- if (!contentResolution.content) {
46143
+ const metadataLines = [decodingLine, warningsLine].filter((line) => Boolean(line)).join('\n');
46144
+ const resolvedContent = contentResolution.content;
46145
+ if (!resolvedContent) {
45650
46146
  const reason = contentResolution.reason || 'content unavailable';
45651
- return [`- ${attachmentLabel}: ${reason}. URL: ${contentResolution.attachment.url}`, decodingLine, warningsLine]
45652
- .filter(Boolean)
45653
- .join('\n');
46147
+ return _spaceTrim.spaceTrim((block) => `
46148
+ - ${attachmentLabel}: ${reason}. URL: ${contentResolution.attachment.url}
46149
+ ${block(metadataLines)}
46150
+ `);
45654
46151
  }
45655
46152
  const truncatedLabel = contentResolution.isTruncated ? ' [truncated]' : '';
45656
- return [
45657
- `File: ${attachmentLabel}${truncatedLabel}`,
45658
- `URL: ${contentResolution.attachment.url}`,
45659
- decodingLine,
45660
- warningsLine,
45661
- '```text',
45662
- contentResolution.content,
45663
- '```',
45664
- ]
45665
- .filter(Boolean)
45666
- .join('\n');
46153
+ return _spaceTrim.spaceTrim((block) => `
46154
+ File: ${attachmentLabel}${truncatedLabel}
46155
+ URL: ${contentResolution.attachment.url}
46156
+ ${block(metadataLines)}
46157
+ \`\`\`text
46158
+ ${block(resolvedContent)}
46159
+ \`\`\`
46160
+ `);
45667
46161
  }
45668
46162
  /**
45669
46163
  * Formats inline attachment-content context section for the model.
@@ -45677,11 +46171,14 @@
45677
46171
  if (resolvedContents.length === 0) {
45678
46172
  return '';
45679
46173
  }
45680
- return [
45681
- CHAT_ATTACHMENT_CONTENT_HEADING,
45682
- CHAT_ATTACHMENT_CONTENT_INSTRUCTION,
45683
- ...resolvedContents.map((resolvedContent) => formatResolvedChatAttachmentContent(resolvedContent)),
45684
- ].join('\n\n');
46174
+ return _spaceTrim.spaceTrim((block) => `
46175
+ ${CHAT_ATTACHMENT_CONTENT_HEADING}
46176
+ ${CHAT_ATTACHMENT_CONTENT_INSTRUCTION}
46177
+
46178
+ ${block(resolvedContents
46179
+ .map((resolvedContent) => formatResolvedChatAttachmentContent(resolvedContent))
46180
+ .join('\n\n'))}
46181
+ `);
45685
46182
  }
45686
46183
 
45687
46184
  /**
@@ -46299,7 +46796,7 @@
46299
46796
  });
46300
46797
  }
46301
46798
  let vectorStoreId = cachedVectorStoreId;
46302
- if (this.isNativeKnowledgeSearchEnabled && !vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
46799
+ if (!vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
46303
46800
  const vectorStoreResult = await this.createVectorStoreWithKnowledgeSources({
46304
46801
  client: await this.getClient(),
46305
46802
  name,
@@ -46308,19 +46805,13 @@
46308
46805
  });
46309
46806
  vectorStoreId = vectorStoreResult.vectorStoreId;
46310
46807
  }
46311
- else if (this.isNativeKnowledgeSearchEnabled && vectorStoreId && this.options.isVerbose) {
46808
+ else if (vectorStoreId && this.options.isVerbose) {
46312
46809
  console.info('[🤰]', 'Using cached vector store for AgentKit agent', {
46313
46810
  name,
46314
46811
  vectorStoreId,
46315
46812
  });
46316
46813
  }
46317
- if (!this.isNativeKnowledgeSearchEnabled) {
46318
- vectorStoreId = undefined;
46319
- }
46320
- const agentKitTools = this.buildAgentKitTools({
46321
- tools,
46322
- vectorStoreId,
46323
- });
46814
+ const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
46324
46815
  const openAiAgentKitAgent = new agents.Agent({
46325
46816
  name,
46326
46817
  model: this.agentKitModelName,
@@ -46339,7 +46830,7 @@
46339
46830
  name,
46340
46831
  model: this.agentKitModelName,
46341
46832
  toolCount: agentKitTools.length,
46342
- hasVectorStore: this.isNativeKnowledgeSearchEnabled && Boolean(vectorStoreId),
46833
+ hasVectorStore: Boolean(vectorStoreId),
46343
46834
  });
46344
46835
  }
46345
46836
  return preparedAgent;
@@ -46838,12 +47329,6 @@
46838
47329
  get agentKitOptions() {
46839
47330
  return this.options;
46840
47331
  }
46841
- /**
46842
- * Returns true when hosted OpenAI vector-store search should back `knowledgeSources`.
46843
- */
46844
- get isNativeKnowledgeSearchEnabled() {
46845
- return this.agentKitOptions.isNativeKnowledgeSearchEnabled !== false;
46846
- }
46847
47332
  /**
46848
47333
  * Discriminant for type guards.
46849
47334
  */