@promptbook/components 0.112.0-65 โ†’ 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.
package/esm/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { spaceTrim as spaceTrim$1 } from 'spacetrim';
3
+ import { posix, basename, join, dirname, isAbsolute } from 'path';
3
4
  import { useMemo, useId, useState, memo, useRef, useEffect, createContext, useContext, useCallback, forwardRef } from 'react';
4
5
  import { SHA256 } from 'crypto-js';
5
6
  import hexEncoder from 'crypto-js/enc-hex';
6
- import { basename, join, dirname, isAbsolute } from 'path';
7
7
  import { randomBytes } from 'crypto';
8
8
  import moment from 'moment';
9
9
  import { lookup, extension } from 'mime-types';
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
40
40
  * @generated
41
41
  * @see https://github.com/webgptorg/promptbook
42
42
  */
43
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-65';
43
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-66';
44
44
  /**
45
45
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
46
46
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -973,6 +973,29 @@ function saturate(amount) {
973
973
  }
974
974
  // TODO: Maybe implement by mix+hsl
975
975
 
976
+ /**
977
+ * Relative directory name without the `./` prefix for Git ignore rules and glob patterns.
978
+ *
979
+ * @private internal utility for Promptbook-owned temp files
980
+ */
981
+ const PROMPTBOOK_TEMP_DIRECTORY_NAME = '.promptbook';
982
+ /**
983
+ * Builds one project-relative path inside the shared Promptbook working directory.
984
+ *
985
+ * @private internal utility for Promptbook-owned temp files
986
+ */
987
+ function getPromptbookTempPath(...pathSegments) {
988
+ return `./${getPromptbookTempPosixPath(...pathSegments)}`;
989
+ }
990
+ /**
991
+ * Builds one POSIX path fragment inside the shared Promptbook working directory for globs and generated text files.
992
+ *
993
+ * @private internal utility for Promptbook-owned temp files
994
+ */
995
+ function getPromptbookTempPosixPath(...pathSegments) {
996
+ return posix.join(PROMPTBOOK_TEMP_DIRECTORY_NAME, ...pathSegments);
997
+ }
998
+
976
999
  /**
977
1000
  * Returns the same value that is passed as argument.
978
1001
  * No side effects.
@@ -1175,7 +1198,6 @@ const DEFAULT_MAX_CONCURRENT_UPLOADS = 5;
1175
1198
  */
1176
1199
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
1177
1200
  // <- TODO: [๐Ÿ•] Make also `AGENTS_DIRNAME_ALTERNATIVES`
1178
- // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
1179
1201
  /**
1180
1202
  * Where to store the temporary downloads
1181
1203
  *
@@ -1183,7 +1205,15 @@ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
1183
1205
  *
1184
1206
  * @public exported from `@promptbook/core`
1185
1207
  */
1186
- const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
1208
+ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = getPromptbookTempPath('download-cache');
1209
+ /**
1210
+ * Where to store the cache of executions for promptbook CLI
1211
+ *
1212
+ * Note: When the folder does not exist, it is created recursively
1213
+ *
1214
+ * @public exported from `@promptbook/core`
1215
+ */
1216
+ getPromptbookTempPath('execution-cache');
1187
1217
  /**
1188
1218
  * Where to store the scrape cache
1189
1219
  *
@@ -1191,7 +1221,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
1191
1221
  *
1192
1222
  * @public exported from `@promptbook/core`
1193
1223
  */
1194
- const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
1224
+ const DEFAULT_SCRAPE_CACHE_DIRNAME = getPromptbookTempPath('scrape-cache');
1195
1225
  /**
1196
1226
  * Default remote server URL for the Promptbook
1197
1227
  *
@@ -2825,6 +2855,177 @@ function drawFractalCore(context, size, palette, timeMs, corePhase) {
2825
2855
  context.restore();
2826
2856
  }
2827
2857
 
2858
+ /* eslint-disable no-magic-numbers */
2859
+ /**
2860
+ * Builds the seeded six-face texture pack used by the Minecraft-style head cuboid.
2861
+ *
2862
+ * @param random Seeded random generator.
2863
+ * @param palette Derived avatar palette.
2864
+ * @param hasHeadband Whether the generated avatar should include a colored headband.
2865
+ * @returns Head cuboid textures.
2866
+ *
2867
+ * @private helper of the Minecraft avatar visuals
2868
+ */
2869
+ function createMinecraftHeadTextures(random, palette, hasHeadband) {
2870
+ const faceTexture = createMinecraftFaceTexture(random, palette, hasHeadband);
2871
+ const hairColor = random() < 0.5 ? palette.primary : palette.secondary;
2872
+ const skinColor = palette.highlight;
2873
+ const headbandColor = hasHeadband ? palette.accent : hairColor;
2874
+ const sideTexture = createFilledTexture(skinColor);
2875
+ const backTexture = createFilledTexture(skinColor);
2876
+ const topTexture = createFilledTexture(hairColor);
2877
+ const bottomTexture = createFilledTexture(`${palette.shadow}cc`);
2878
+ fillTextureRect(sideTexture, 0, 0, 8, 3, hairColor);
2879
+ fillTextureRect(backTexture, 0, 0, 8, 5, hairColor);
2880
+ fillTextureRect(backTexture, 1, 5, 6, 1, hairColor);
2881
+ if (hasHeadband) {
2882
+ fillTextureRect(sideTexture, 0, 2, 8, 1, headbandColor);
2883
+ fillTextureRect(backTexture, 0, 2, 8, 1, headbandColor);
2884
+ fillTextureRect(topTexture, 0, 4, 8, 1, headbandColor);
2885
+ }
2886
+ sideTexture[4][4] = `${palette.shadow}99`;
2887
+ sideTexture[5][4] = `${palette.shadow}cc`;
2888
+ backTexture[6][2] = `${palette.shadow}99`;
2889
+ backTexture[6][5] = `${palette.shadow}99`;
2890
+ return {
2891
+ front: faceTexture,
2892
+ back: backTexture,
2893
+ left: sideTexture,
2894
+ right: mirrorMinecraftTexture(sideTexture),
2895
+ top: topTexture,
2896
+ bottom: bottomTexture,
2897
+ };
2898
+ }
2899
+ /**
2900
+ * Builds the seeded six-face texture pack used by the Minecraft-style torso cuboid.
2901
+ *
2902
+ * @param random Seeded random generator.
2903
+ * @param palette Derived avatar palette.
2904
+ * @returns Torso cuboid textures.
2905
+ *
2906
+ * @private helper of the Minecraft avatar visuals
2907
+ */
2908
+ function createMinecraftTorsoTextures(random, palette) {
2909
+ const frontTexture = createMinecraftShirtTexture(random, palette);
2910
+ const sideTexture = createFilledTexture(palette.primary);
2911
+ const backTexture = createFilledTexture(palette.primary);
2912
+ const topTexture = createFilledTexture(`${palette.highlight}dd`);
2913
+ const bottomTexture = createFilledTexture(`${palette.shadow}dd`);
2914
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
2915
+ fillTextureRect(sideTexture, 0, 0, 8, 2, palette.shadow);
2916
+ fillTextureRect(backTexture, 0, 0, 8, 2, palette.shadow);
2917
+ fillTextureRect(backTexture, 3, 2, 2, 6, stripeColor);
2918
+ fillTextureRect(sideTexture, 4, 2, 1, 6, stripeColor);
2919
+ fillTextureRect(topTexture, 0, 0, 8, 2, palette.shadow);
2920
+ fillTextureRect(topTexture, 2, 2, 4, 4, stripeColor);
2921
+ return {
2922
+ front: frontTexture,
2923
+ back: backTexture,
2924
+ left: sideTexture,
2925
+ right: mirrorMinecraftTexture(sideTexture),
2926
+ top: topTexture,
2927
+ bottom: bottomTexture,
2928
+ };
2929
+ }
2930
+ /**
2931
+ * Mirrors one Minecraft texture horizontally.
2932
+ *
2933
+ * @param texture Source texture.
2934
+ * @returns Mirrored texture copy.
2935
+ *
2936
+ * @private helper of the Minecraft avatar visuals
2937
+ */
2938
+ function mirrorMinecraftTexture(texture) {
2939
+ return texture.map((row) => [...row].reverse());
2940
+ }
2941
+ /**
2942
+ * Creates the front-face pixel texture for the cube head.
2943
+ *
2944
+ * @param random Seeded random generator.
2945
+ * @param palette Derived avatar palette.
2946
+ * @param hasHeadband Whether the avatar should render a headband row.
2947
+ * @returns 8x8 pixel texture.
2948
+ *
2949
+ * @private helper of the Minecraft avatar visuals
2950
+ */
2951
+ function createMinecraftFaceTexture(random, palette, hasHeadband) {
2952
+ const texture = createFilledTexture(palette.highlight);
2953
+ const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
2954
+ const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
2955
+ fillTextureRect(texture, 0, 0, 8, 2, hairlineColor);
2956
+ texture[2][0] = hairlineColor;
2957
+ texture[2][7] = hairlineColor;
2958
+ texture[3][0] = hairlineColor;
2959
+ texture[3][7] = hairlineColor;
2960
+ if (hasHeadband) {
2961
+ fillTextureRect(texture, 0, 2, 8, 1, palette.accent);
2962
+ }
2963
+ texture[3][2] = palette.ink;
2964
+ texture[3][5] = palette.ink;
2965
+ texture[4][2] = '#ffffff';
2966
+ texture[4][5] = '#ffffff';
2967
+ texture[5][1] = cheekColor;
2968
+ texture[5][6] = cheekColor;
2969
+ texture[5][3] = palette.shadow;
2970
+ texture[5][4] = palette.shadow;
2971
+ texture[6][3] = palette.shadow;
2972
+ texture[6][4] = palette.shadow;
2973
+ return texture;
2974
+ }
2975
+ /**
2976
+ * Creates the front-face pixel texture for the torso.
2977
+ *
2978
+ * @param random Seeded random generator.
2979
+ * @param palette Derived avatar palette.
2980
+ * @returns 8x8 torso texture.
2981
+ *
2982
+ * @private helper of the Minecraft avatar visuals
2983
+ */
2984
+ function createMinecraftShirtTexture(random, palette) {
2985
+ const texture = createFilledTexture(palette.primary);
2986
+ const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
2987
+ fillTextureRect(texture, 0, 0, 8, 2, palette.shadow);
2988
+ for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
2989
+ texture[rowIndex][3] = stripeColor;
2990
+ texture[rowIndex][4] = stripeColor;
2991
+ }
2992
+ texture[4][1] = palette.accent;
2993
+ texture[4][6] = palette.accent;
2994
+ texture[5][2] = palette.highlight;
2995
+ texture[5][5] = palette.highlight;
2996
+ return texture;
2997
+ }
2998
+ /**
2999
+ * Creates one solid-color 8x8 Minecraft texture.
3000
+ *
3001
+ * @param color Fill color.
3002
+ * @returns Filled 8x8 texture.
3003
+ *
3004
+ * @private helper of the Minecraft avatar visuals
3005
+ */
3006
+ function createFilledTexture(color) {
3007
+ return Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => color));
3008
+ }
3009
+ /**
3010
+ * Fills one rectangular area inside a mutable Minecraft texture.
3011
+ *
3012
+ * @param texture Mutable target texture.
3013
+ * @param x Left texture coordinate.
3014
+ * @param y Top texture coordinate.
3015
+ * @param width Rectangle width.
3016
+ * @param height Rectangle height.
3017
+ * @param color Fill color.
3018
+ *
3019
+ * @private helper of the Minecraft avatar visuals
3020
+ */
3021
+ function fillTextureRect(texture, x, y, width, height, color) {
3022
+ for (let rowIndex = y; rowIndex < y + height; rowIndex++) {
3023
+ for (let columnIndex = x; columnIndex < x + width; columnIndex++) {
3024
+ texture[rowIndex][columnIndex] = color;
3025
+ }
3026
+ }
3027
+ }
3028
+
2828
3029
  /* eslint-disable no-magic-numbers */
2829
3030
  /**
2830
3031
  * Minecraft-style 3D avatar visual.
@@ -2849,8 +3050,8 @@ const minecraftAvatarVisual = {
2849
3050
  const bodyX = size * 0.33;
2850
3051
  const bodyY = headY + headSize * 0.96;
2851
3052
  const hasHeadband = random() < 0.5;
2852
- const faceTexture = createMinecraftFaceTexture(createRandom('minecraft-face'), palette, hasHeadband);
2853
- const shirtTexture = createMinecraftShirtTexture(createRandom('minecraft-shirt'), palette);
3053
+ const headTextures = createMinecraftHeadTextures(createRandom('minecraft-face'), palette, hasHeadband);
3054
+ const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft-shirt'), palette);
2854
3055
  drawAvatarFrame(context, size, palette);
2855
3056
  const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
2856
3057
  spotlight.addColorStop(0, `${palette.highlight}66`);
@@ -2870,7 +3071,7 @@ const minecraftAvatarVisual = {
2870
3071
  width: bodyWidth,
2871
3072
  height: bodyHeight,
2872
3073
  depth: bodyDepth,
2873
- frontTexture: shirtTexture,
3074
+ frontTexture: torsoTextures.front,
2874
3075
  topColor: `${palette.highlight}cc`,
2875
3076
  sideColor: `${palette.secondary}dd`,
2876
3077
  outlineColor: `${palette.shadow}aa`,
@@ -2881,7 +3082,7 @@ const minecraftAvatarVisual = {
2881
3082
  width: headSize,
2882
3083
  height: headSize,
2883
3084
  depth,
2884
- frontTexture: faceTexture,
3085
+ frontTexture: headTextures.front,
2885
3086
  topColor: `${palette.highlight}ee`,
2886
3087
  sideColor: `${palette.secondary}ee`,
2887
3088
  outlineColor: `${palette.shadow}cc`,
@@ -2946,72 +3147,505 @@ function drawVoxelCuboid(context, cuboid) {
2946
3147
  context.closePath();
2947
3148
  context.stroke();
2948
3149
  }
3150
+
3151
+ /* eslint-disable no-magic-numbers */
2949
3152
  /**
2950
- * Creates the front-face pixel texture for the cube head.
3153
+ * Fixed scene camera distance used for the proper-3D projection.
2951
3154
  *
2952
- * @param random Seeded random generator.
3155
+ * @private helper of `minecraft2AvatarVisual`
3156
+ */
3157
+ const CAMERA_DISTANCE_RATIO = 1.4;
3158
+ /**
3159
+ * Shared light direction used to shade projected cuboid faces.
3160
+ *
3161
+ * @private helper of `minecraft2AvatarVisual`
3162
+ */
3163
+ const LIGHT_DIRECTION = normalizeVector3({
3164
+ x: 0.4,
3165
+ y: -0.65,
3166
+ z: 0.92,
3167
+ });
3168
+ /**
3169
+ * Minecraft 3D 2 avatar visual.
3170
+ *
3171
+ * @private built-in avatar visual
3172
+ */
3173
+ const minecraft2AvatarVisual = {
3174
+ id: 'minecraft2',
3175
+ title: 'Minecraft 3D 2',
3176
+ description: 'Proper 3D Minecraft-style portrait with textured cuboids and pointer-driven head turns.',
3177
+ isAnimated: true,
3178
+ supportsPointerTracking: true,
3179
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
3180
+ const spotlightY = size * 0.22;
3181
+ const headRandom = createRandom('minecraft2-head');
3182
+ const hasHeadband = headRandom() < 0.5;
3183
+ const headTextures = createMinecraftHeadTextures(createRandom('minecraft2-head-textures'), palette, hasHeadband);
3184
+ const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft2-body-textures'), palette);
3185
+ const bob = Math.sin(timeMs / 880) * size * 0.014;
3186
+ const bodyYaw = -0.24 + Math.sin(timeMs / 2300) * 0.06 + interaction.bodyOffsetX * 0.16;
3187
+ const bodyPitch = -0.12 + Math.cos(timeMs / 2800) * 0.02 - interaction.bodyOffsetY * 0.06;
3188
+ const headYaw = -0.18 + Math.sin(timeMs / 1900 + 0.6) * 0.05 + interaction.gazeX * 0.62;
3189
+ const headPitch = -0.12 + Math.cos(timeMs / 2400 + 1.1) * 0.03 - interaction.gazeY * 0.38;
3190
+ const sceneCenterX = size * 0.5;
3191
+ const sceneCenterY = size * 0.57;
3192
+ const bodyWidth = size * 0.225;
3193
+ const bodyHeight = size * 0.245;
3194
+ const bodyDepth = size * 0.145;
3195
+ const headSize = size * 0.24;
3196
+ const headLift = size * 0.205;
3197
+ const headForwardShift = interaction.intensity * size * 0.018;
3198
+ const sceneCuboids = [
3199
+ {
3200
+ center: {
3201
+ x: interaction.bodyOffsetX * size * 0.026,
3202
+ y: size * 0.05 + interaction.bodyOffsetY * size * 0.018 + bob,
3203
+ z: 0,
3204
+ },
3205
+ width: bodyWidth,
3206
+ height: bodyHeight,
3207
+ depth: bodyDepth,
3208
+ rotationX: bodyPitch,
3209
+ rotationY: bodyYaw,
3210
+ textures: torsoTextures,
3211
+ outlineColor: `${palette.shadow}cc`,
3212
+ },
3213
+ {
3214
+ center: {
3215
+ x: interaction.bodyOffsetX * size * 0.018 + interaction.gazeX * size * 0.016,
3216
+ y: -headLift + bob * 1.15,
3217
+ z: headForwardShift,
3218
+ },
3219
+ width: headSize,
3220
+ height: headSize,
3221
+ depth: headSize,
3222
+ rotationX: headPitch,
3223
+ rotationY: headYaw,
3224
+ textures: headTextures,
3225
+ outlineColor: `${palette.shadow}dd`,
3226
+ },
3227
+ ];
3228
+ const visibleFaces = sceneCuboids
3229
+ .flatMap((cuboid) => resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY))
3230
+ .sort((firstFace, secondFace) => firstFace.averageDepth - secondFace.averageDepth);
3231
+ drawAvatarFrame(context, size, palette);
3232
+ drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs);
3233
+ drawMinecraftShadow(context, size, palette, interaction, timeMs);
3234
+ for (const visibleFace of visibleFaces) {
3235
+ drawTexturedProjectedFace(context, visibleFace);
3236
+ }
3237
+ },
3238
+ };
3239
+ /**
3240
+ * Draws the shared background atmosphere behind the Minecraft 3D 2 portrait.
3241
+ *
3242
+ * @param context Canvas 2D context.
3243
+ * @param size Canvas size in CSS pixels.
2953
3244
  * @param palette Derived avatar palette.
2954
- * @param hasHeadband Whether the avatar should render a headband row.
2955
- * @returns 8x8 pixel texture.
3245
+ * @param sceneCenterX Horizontal scene center.
3246
+ * @param spotlightY Vertical spotlight anchor.
3247
+ * @param interaction Smoothed pointer-aware interaction state.
3248
+ * @param timeMs Current animation time in milliseconds.
2956
3249
  *
2957
- * @private helper of `minecraftAvatarVisual`
3250
+ * @private helper of `minecraft2AvatarVisual`
2958
3251
  */
2959
- function createMinecraftFaceTexture(random, palette, hasHeadband) {
2960
- const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.highlight));
2961
- const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
2962
- const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
2963
- for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
2964
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
2965
- texture[rowIndex][columnIndex] = hairlineColor;
3252
+ function drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs) {
3253
+ const spotlightGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.08, spotlightY + interaction.gazeY * size * 0.05, size * 0.03, sceneCenterX, spotlightY, size * 0.52);
3254
+ spotlightGradient.addColorStop(0, `${palette.highlight}66`);
3255
+ spotlightGradient.addColorStop(0.42, `${palette.accent}1d`);
3256
+ spotlightGradient.addColorStop(1, `${palette.highlight}00`);
3257
+ context.fillStyle = spotlightGradient;
3258
+ context.fillRect(0, 0, size, size);
3259
+ const rimGradient = context.createLinearGradient(0, size * 0.14, 0, size * 0.92);
3260
+ rimGradient.addColorStop(0, `${palette.highlight}12`);
3261
+ rimGradient.addColorStop(0.55, `${palette.secondary}0a`);
3262
+ rimGradient.addColorStop(1, `${palette.shadow}00`);
3263
+ context.fillStyle = rimGradient;
3264
+ context.fillRect(0, 0, size, size);
3265
+ context.save();
3266
+ context.globalAlpha = 0.08 + interaction.intensity * 0.04;
3267
+ context.fillStyle = palette.highlight;
3268
+ context.beginPath();
3269
+ 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);
3270
+ context.fill();
3271
+ context.restore();
3272
+ }
3273
+ /**
3274
+ * Draws the soft floor shadow used to anchor the cuboids in the frame.
3275
+ *
3276
+ * @param context Canvas 2D context.
3277
+ * @param size Canvas size in CSS pixels.
3278
+ * @param palette Derived avatar palette.
3279
+ * @param interaction Smoothed pointer-aware interaction state.
3280
+ * @param timeMs Current animation time in milliseconds.
3281
+ *
3282
+ * @private helper of `minecraft2AvatarVisual`
3283
+ */
3284
+ function drawMinecraftShadow(context, size, palette, interaction, timeMs) {
3285
+ context.save();
3286
+ context.fillStyle = `${palette.shadow}66`;
3287
+ context.filter = `blur(${size * 0.02}px)`;
3288
+ context.beginPath();
3289
+ 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);
3290
+ context.fill();
3291
+ context.restore();
3292
+ }
3293
+ /**
3294
+ * Resolves all visible projected faces for one scene cuboid.
3295
+ *
3296
+ * @param cuboid Scene cuboid definition.
3297
+ * @param size Canvas size in CSS pixels.
3298
+ * @param sceneCenterX Horizontal scene center.
3299
+ * @param sceneCenterY Vertical scene center.
3300
+ * @returns Visible faces sorted later by depth.
3301
+ *
3302
+ * @private helper of `minecraft2AvatarVisual`
3303
+ */
3304
+ function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
3305
+ const halfWidth = cuboid.width / 2;
3306
+ const halfHeight = cuboid.height / 2;
3307
+ const halfDepth = cuboid.depth / 2;
3308
+ const faceDefinitions = [
3309
+ {
3310
+ texture: cuboid.textures.front,
3311
+ corners: [
3312
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
3313
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
3314
+ { x: halfWidth, y: halfHeight, z: halfDepth },
3315
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
3316
+ ],
3317
+ },
3318
+ {
3319
+ texture: cuboid.textures.back,
3320
+ corners: [
3321
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
3322
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
3323
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
3324
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
3325
+ ],
3326
+ },
3327
+ {
3328
+ texture: cuboid.textures.right,
3329
+ corners: [
3330
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
3331
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
3332
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
3333
+ { x: halfWidth, y: halfHeight, z: halfDepth },
3334
+ ],
3335
+ },
3336
+ {
3337
+ texture: cuboid.textures.left,
3338
+ corners: [
3339
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
3340
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
3341
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
3342
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
3343
+ ],
3344
+ },
3345
+ {
3346
+ texture: cuboid.textures.top,
3347
+ corners: [
3348
+ { x: -halfWidth, y: -halfHeight, z: -halfDepth },
3349
+ { x: halfWidth, y: -halfHeight, z: -halfDepth },
3350
+ { x: halfWidth, y: -halfHeight, z: halfDepth },
3351
+ { x: -halfWidth, y: -halfHeight, z: halfDepth },
3352
+ ],
3353
+ },
3354
+ {
3355
+ texture: cuboid.textures.bottom,
3356
+ corners: [
3357
+ { x: -halfWidth, y: halfHeight, z: halfDepth },
3358
+ { x: halfWidth, y: halfHeight, z: halfDepth },
3359
+ { x: halfWidth, y: halfHeight, z: -halfDepth },
3360
+ { x: -halfWidth, y: halfHeight, z: -halfDepth },
3361
+ ],
3362
+ },
3363
+ ];
3364
+ const visibleFaces = faceDefinitions
3365
+ .map((faceDefinition) => {
3366
+ const transformedCorners = faceDefinition.corners.map((corner) => transformScenePoint(corner, cuboid.center, cuboid.rotationX, cuboid.rotationY));
3367
+ const faceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
3368
+ if (faceNormal.z <= 0.02) {
3369
+ return null;
2966
3370
  }
3371
+ const projectedCorners = transformedCorners.map((corner) => projectScenePoint(corner, size, sceneCenterX, sceneCenterY));
3372
+ return {
3373
+ corners: projectedCorners,
3374
+ texture: faceDefinition.texture,
3375
+ averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
3376
+ lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION), -1, 1),
3377
+ outlineColor: cuboid.outlineColor,
3378
+ };
3379
+ });
3380
+ return visibleFaces.filter((visibleFace) => visibleFace !== null);
3381
+ }
3382
+ /**
3383
+ * Draws one projected textured face by tessellating its texture cells into quads.
3384
+ *
3385
+ * @param context Canvas 2D context.
3386
+ * @param face Visible projected face.
3387
+ *
3388
+ * @private helper of `minecraft2AvatarVisual`
3389
+ */
3390
+ function drawTexturedProjectedFace(context, face) {
3391
+ var _a;
3392
+ const rows = face.texture.length;
3393
+ const columns = ((_a = face.texture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
3394
+ if (rows === 0 || columns === 0) {
3395
+ return;
2967
3396
  }
2968
- texture[2][0] = hairlineColor;
2969
- texture[2][7] = hairlineColor;
2970
- texture[3][0] = hairlineColor;
2971
- texture[3][7] = hairlineColor;
2972
- if (hasHeadband) {
2973
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
2974
- texture[2][columnIndex] = palette.accent;
3397
+ for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
3398
+ for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
3399
+ const startX = columnIndex / columns;
3400
+ const endX = (columnIndex + 1) / columns;
3401
+ const startY = rowIndex / rows;
3402
+ const endY = (rowIndex + 1) / rows;
3403
+ drawProjectedQuad(context, [
3404
+ interpolateProjectedQuad(face.corners, startX, startY),
3405
+ interpolateProjectedQuad(face.corners, endX, startY),
3406
+ interpolateProjectedQuad(face.corners, endX, endY),
3407
+ interpolateProjectedQuad(face.corners, startX, endY),
3408
+ ], face.texture[rowIndex][columnIndex]);
2975
3409
  }
2976
3410
  }
2977
- texture[3][2] = palette.ink;
2978
- texture[3][5] = palette.ink;
2979
- texture[4][2] = '#ffffff';
2980
- texture[4][5] = '#ffffff';
2981
- texture[5][1] = cheekColor;
2982
- texture[5][6] = cheekColor;
2983
- texture[5][3] = palette.shadow;
2984
- texture[5][4] = palette.shadow;
2985
- texture[6][3] = palette.shadow;
2986
- texture[6][4] = palette.shadow;
2987
- return texture;
3411
+ if (face.lightIntensity > 0) {
3412
+ drawProjectedQuad(context, face.corners, `rgba(255, 255, 255, ${0.15 * face.lightIntensity})`);
3413
+ }
3414
+ else if (face.lightIntensity < 0) {
3415
+ drawProjectedQuad(context, face.corners, `rgba(0, 0, 0, ${0.22 * Math.abs(face.lightIntensity)})`);
3416
+ }
3417
+ context.save();
3418
+ context.beginPath();
3419
+ context.moveTo(face.corners[0].x, face.corners[0].y);
3420
+ for (let cornerIndex = 1; cornerIndex < face.corners.length; cornerIndex++) {
3421
+ context.lineTo(face.corners[cornerIndex].x, face.corners[cornerIndex].y);
3422
+ }
3423
+ context.closePath();
3424
+ context.strokeStyle = face.outlineColor;
3425
+ context.lineWidth = Math.max(1.1, getProjectedQuadPerimeter(face.corners) * 0.0045);
3426
+ context.lineJoin = 'round';
3427
+ context.stroke();
3428
+ context.restore();
2988
3429
  }
2989
3430
  /**
2990
- * Creates the front-face pixel texture for the torso.
3431
+ * Draws one filled projected quad.
2991
3432
  *
2992
- * @param random Seeded random generator.
2993
- * @param palette Derived avatar palette.
2994
- * @returns 8x8 torso texture.
3433
+ * @param context Canvas 2D context.
3434
+ * @param corners Quad corners in clockwise order.
3435
+ * @param fillStyle CSS fill style.
2995
3436
  *
2996
- * @private helper of `minecraftAvatarVisual`
3437
+ * @private helper of `minecraft2AvatarVisual`
2997
3438
  */
2998
- function createMinecraftShirtTexture(random, palette) {
2999
- const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.primary));
3000
- const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
3001
- for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
3002
- for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
3003
- texture[rowIndex][columnIndex] = palette.shadow;
3004
- }
3439
+ function drawProjectedQuad(context, corners, fillStyle) {
3440
+ context.beginPath();
3441
+ context.moveTo(corners[0].x, corners[0].y);
3442
+ context.lineTo(corners[1].x, corners[1].y);
3443
+ context.lineTo(corners[2].x, corners[2].y);
3444
+ context.lineTo(corners[3].x, corners[3].y);
3445
+ context.closePath();
3446
+ context.fillStyle = fillStyle;
3447
+ context.fill();
3448
+ }
3449
+ /**
3450
+ * Interpolates one point inside a projected quad across both quad axes.
3451
+ *
3452
+ * @param corners Quad corners in clockwise order.
3453
+ * @param horizontalRatio Horizontal ratio in the range `[0, 1]`.
3454
+ * @param verticalRatio Vertical ratio in the range `[0, 1]`.
3455
+ * @returns Interpolated projected point.
3456
+ *
3457
+ * @private helper of `minecraft2AvatarVisual`
3458
+ */
3459
+ function interpolateProjectedQuad(corners, horizontalRatio, verticalRatio) {
3460
+ const topPoint = interpolateProjectedPoint(corners[0], corners[1], horizontalRatio);
3461
+ const bottomPoint = interpolateProjectedPoint(corners[3], corners[2], horizontalRatio);
3462
+ return interpolateProjectedPoint(topPoint, bottomPoint, verticalRatio);
3463
+ }
3464
+ /**
3465
+ * Interpolates between two projected points.
3466
+ *
3467
+ * @param startPoint Start point.
3468
+ * @param endPoint End point.
3469
+ * @param ratio Interpolation ratio in the range `[0, 1]`.
3470
+ * @returns Interpolated projected point.
3471
+ *
3472
+ * @private helper of `minecraft2AvatarVisual`
3473
+ */
3474
+ function interpolateProjectedPoint(startPoint, endPoint, ratio) {
3475
+ return {
3476
+ x: startPoint.x + (endPoint.x - startPoint.x) * ratio,
3477
+ y: startPoint.y + (endPoint.y - startPoint.y) * ratio,
3478
+ z: startPoint.z + (endPoint.z - startPoint.z) * ratio,
3479
+ };
3480
+ }
3481
+ /**
3482
+ * Projects one rotated scene point into canvas coordinates.
3483
+ *
3484
+ * @param point Scene point.
3485
+ * @param size Canvas size in CSS pixels.
3486
+ * @param sceneCenterX Horizontal scene center.
3487
+ * @param sceneCenterY Vertical scene center.
3488
+ * @returns Projected point.
3489
+ *
3490
+ * @private helper of `minecraft2AvatarVisual`
3491
+ */
3492
+ function projectScenePoint(point, size, sceneCenterX, sceneCenterY) {
3493
+ const cameraDistance = size * CAMERA_DISTANCE_RATIO;
3494
+ const perspectiveScale = cameraDistance / Math.max(cameraDistance - point.z, cameraDistance * 0.35);
3495
+ return {
3496
+ x: sceneCenterX + point.x * perspectiveScale,
3497
+ y: sceneCenterY + point.y * perspectiveScale,
3498
+ z: point.z,
3499
+ };
3500
+ }
3501
+ /**
3502
+ * Applies the local cuboid rotations and translation to one scene point.
3503
+ *
3504
+ * @param localPoint Point in cuboid-local space.
3505
+ * @param center Cuboid center in scene space.
3506
+ * @param rotationX Cuboid pitch in radians.
3507
+ * @param rotationY Cuboid yaw in radians.
3508
+ * @returns Transformed scene-space point.
3509
+ *
3510
+ * @private helper of `minecraft2AvatarVisual`
3511
+ */
3512
+ function transformScenePoint(localPoint, center, rotationX, rotationY) {
3513
+ const yawedPoint = rotatePointAroundY(localPoint, rotationY);
3514
+ const pitchedPoint = rotatePointAroundX(yawedPoint, rotationX);
3515
+ return {
3516
+ x: center.x + pitchedPoint.x,
3517
+ y: center.y + pitchedPoint.y,
3518
+ z: center.z + pitchedPoint.z,
3519
+ };
3520
+ }
3521
+ /**
3522
+ * Rotates one point around the local Y axis.
3523
+ *
3524
+ * @param point Source point.
3525
+ * @param angle Rotation angle in radians.
3526
+ * @returns Rotated point.
3527
+ *
3528
+ * @private helper of `minecraft2AvatarVisual`
3529
+ */
3530
+ function rotatePointAroundY(point, angle) {
3531
+ const cosine = Math.cos(angle);
3532
+ const sine = Math.sin(angle);
3533
+ return {
3534
+ x: point.x * cosine + point.z * sine,
3535
+ y: point.y,
3536
+ z: -point.x * sine + point.z * cosine,
3537
+ };
3538
+ }
3539
+ /**
3540
+ * Rotates one point around the local X axis.
3541
+ *
3542
+ * @param point Source point.
3543
+ * @param angle Rotation angle in radians.
3544
+ * @returns Rotated point.
3545
+ *
3546
+ * @private helper of `minecraft2AvatarVisual`
3547
+ */
3548
+ function rotatePointAroundX(point, angle) {
3549
+ const cosine = Math.cos(angle);
3550
+ const sine = Math.sin(angle);
3551
+ return {
3552
+ x: point.x,
3553
+ y: point.y * cosine - point.z * sine,
3554
+ z: point.y * sine + point.z * cosine,
3555
+ };
3556
+ }
3557
+ /**
3558
+ * Subtracts one 3D point from another.
3559
+ *
3560
+ * @param leftPoint Left point.
3561
+ * @param rightPoint Right point.
3562
+ * @returns Difference vector.
3563
+ *
3564
+ * @private helper of `minecraft2AvatarVisual`
3565
+ */
3566
+ function subtractPoint3D(leftPoint, rightPoint) {
3567
+ return {
3568
+ x: leftPoint.x - rightPoint.x,
3569
+ y: leftPoint.y - rightPoint.y,
3570
+ z: leftPoint.z - rightPoint.z,
3571
+ };
3572
+ }
3573
+ /**
3574
+ * Computes the 3D cross product of two vectors.
3575
+ *
3576
+ * @param leftVector Left vector.
3577
+ * @param rightVector Right vector.
3578
+ * @returns Cross product.
3579
+ *
3580
+ * @private helper of `minecraft2AvatarVisual`
3581
+ */
3582
+ function crossProduct3D(leftVector, rightVector) {
3583
+ return {
3584
+ x: leftVector.y * rightVector.z - leftVector.z * rightVector.y,
3585
+ y: leftVector.z * rightVector.x - leftVector.x * rightVector.z,
3586
+ z: leftVector.x * rightVector.y - leftVector.y * rightVector.x,
3587
+ };
3588
+ }
3589
+ /**
3590
+ * Computes the 3D dot product of two vectors.
3591
+ *
3592
+ * @param leftVector Left vector.
3593
+ * @param rightVector Right vector.
3594
+ * @returns Dot product.
3595
+ *
3596
+ * @private helper of `minecraft2AvatarVisual`
3597
+ */
3598
+ function dotProduct3D(leftVector, rightVector) {
3599
+ return leftVector.x * rightVector.x + leftVector.y * rightVector.y + leftVector.z * rightVector.z;
3600
+ }
3601
+ /**
3602
+ * Normalizes one 3D vector while keeping zero vectors stable.
3603
+ *
3604
+ * @param vector Source vector.
3605
+ * @returns Normalized vector.
3606
+ *
3607
+ * @private helper of `minecraft2AvatarVisual`
3608
+ */
3609
+ function normalizeVector3(vector) {
3610
+ const length = Math.hypot(vector.x, vector.y, vector.z);
3611
+ if (length === 0) {
3612
+ return vector;
3005
3613
  }
3006
- for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
3007
- texture[rowIndex][3] = stripeColor;
3008
- texture[rowIndex][4] = stripeColor;
3614
+ return {
3615
+ x: vector.x / length,
3616
+ y: vector.y / length,
3617
+ z: vector.z / length,
3618
+ };
3619
+ }
3620
+ /**
3621
+ * Clamps one number into the provided range.
3622
+ *
3623
+ * @param value Input value.
3624
+ * @param minimumValue Inclusive lower bound.
3625
+ * @param maximumValue Inclusive upper bound.
3626
+ * @returns Clamped value.
3627
+ *
3628
+ * @private helper of `minecraft2AvatarVisual`
3629
+ */
3630
+ function clampNumber$1(value, minimumValue, maximumValue) {
3631
+ return Math.min(maximumValue, Math.max(minimumValue, value));
3632
+ }
3633
+ /**
3634
+ * Measures the perimeter of one projected quad.
3635
+ *
3636
+ * @param corners Quad corners.
3637
+ * @returns Perimeter length.
3638
+ *
3639
+ * @private helper of `minecraft2AvatarVisual`
3640
+ */
3641
+ function getProjectedQuadPerimeter(corners) {
3642
+ let perimeter = 0;
3643
+ for (let cornerIndex = 0; cornerIndex < corners.length; cornerIndex++) {
3644
+ const currentCorner = corners[cornerIndex];
3645
+ const nextCorner = corners[(cornerIndex + 1) % corners.length];
3646
+ perimeter += Math.hypot(nextCorner.x - currentCorner.x, nextCorner.y - currentCorner.y);
3009
3647
  }
3010
- texture[4][1] = palette.accent;
3011
- texture[4][6] = palette.accent;
3012
- texture[5][2] = palette.highlight;
3013
- texture[5][5] = palette.highlight;
3014
- return texture;
3648
+ return perimeter;
3015
3649
  }
3016
3650
 
3017
3651
  /* eslint-disable no-magic-numbers */
@@ -4616,6 +5250,7 @@ const AVATAR_VISUALS = [
4616
5250
  octopus3AvatarVisual,
4617
5251
  asciiOctopusAvatarVisual,
4618
5252
  minecraftAvatarVisual,
5253
+ minecraft2AvatarVisual,
4619
5254
  fractalAvatarVisual,
4620
5255
  orbAvatarVisual,
4621
5256
  ];
@@ -14528,7 +15163,10 @@ function buildTeamSystemMessageBody(teamEntries) {
14528
15163
  */
14529
15164
  function buildTeamToolDescription(entry) {
14530
15165
  const detailLines = collectTeamEntryDetails(entry).map(({ label, content }) => `${label}: ${content}`);
14531
- return [`Consult teammate ${entry.teammate.label}`, ...detailLines].join('\n');
15166
+ return spaceTrim$1((block) => `
15167
+ Consult teammate ${entry.teammate.label}
15168
+ ${block(detailLines.join('\n'))}
15169
+ `);
14532
15170
  }
14533
15171
  /**
14534
15172
  * Collects structured teammate details that should stay visible to the model.
@@ -20044,7 +20682,10 @@ function createListedTimeoutsAssistantMessage(options) {
20044
20682
  if (hiddenCount > 0) {
20045
20683
  summaryRows.push(`...and ${hiddenCount} more.`);
20046
20684
  }
20047
- return [`Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:`, ...summaryRows].join('\n');
20685
+ return spaceTrim$1((block) => `
20686
+ Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
20687
+ ${block(summaryRows.join('\n'))}
20688
+ `);
20048
20689
  }
20049
20690
  /**
20050
20691
  * Formats one timeout row for assistant-visible timeout listings.