@promptbook/browser 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.
- package/esm/index.es.js +746 -250
- package/esm/index.es.js.map +1 -1
- package/esm/src/_packages/components.index.d.ts +0 -2
- package/esm/src/_packages/core.index.d.ts +2 -2
- package/esm/src/_packages/types.index.d.ts +0 -2
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
- package/esm/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
- package/esm/src/book-2.0/book-language-documentation/BookLanguageDocumentationExample.d.ts +27 -0
- package/esm/src/book-2.0/book-language-documentation/bookLanguageCommonPitfalls.d.ts +25 -0
- package/esm/src/book-2.0/book-language-documentation/bookLanguageDocumentationExamples.d.ts +10 -0
- package/esm/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.d.ts +14 -0
- package/esm/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.d.ts +43 -0
- package/esm/src/book-components/Chat/types/ChatMessage.d.ts +0 -34
- package/esm/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
- package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -11
- package/esm/src/commitments/_common/toolRuntimeContext.d.ts +0 -6
- package/esm/src/config.d.ts +3 -3
- package/esm/src/formfactors/index.d.ts +2 -2
- package/esm/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +1 -1
- package/esm/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +1 -1
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +0 -4
- package/esm/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +0 -9
- package/esm/src/utils/files/getPromptbookTempPath.d.ts +24 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +749 -253
- package/umd/index.umd.js.map +1 -1
- package/umd/src/_packages/components.index.d.ts +0 -2
- package/umd/src/_packages/core.index.d.ts +2 -2
- package/umd/src/_packages/types.index.d.ts +0 -2
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
- package/umd/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
- package/umd/src/book-2.0/book-language-documentation/BookLanguageDocumentationExample.d.ts +27 -0
- package/umd/src/book-2.0/book-language-documentation/bookLanguageCommonPitfalls.d.ts +25 -0
- package/umd/src/book-2.0/book-language-documentation/bookLanguageDocumentationExamples.d.ts +10 -0
- package/umd/src/book-2.0/book-language-documentation/createStandaloneBookLanguageMarkdown.d.ts +14 -0
- package/umd/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.d.ts +43 -0
- package/umd/src/book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.test.d.ts +1 -0
- package/umd/src/book-components/Chat/types/ChatMessage.d.ts +0 -34
- package/umd/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
- package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +0 -11
- package/umd/src/commitments/_common/toolRuntimeContext.d.ts +0 -6
- package/umd/src/config.d.ts +3 -3
- package/umd/src/formfactors/index.d.ts +2 -2
- package/umd/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +1 -1
- package/umd/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +1 -1
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionTools.d.ts +0 -4
- package/umd/src/llm-providers/openai/OpenAiAgentKitExecutionToolsOptions.d.ts +0 -9
- package/umd/src/utils/files/getPromptbookTempPath.d.ts +24 -0
- package/umd/src/utils/files/getPromptbookTempPath.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
- /package/esm/src/{commitments/KNOWLEDGE/KNOWLEDGE.test.d.ts → book-2.0/book-language-documentation/renderGroupedCommitmentDocumentationMarkdown.test.d.ts} +0 -0
- /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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('destroyable'), require('rxjs'), require('crypto'), require('crypto-js'), require('crypto-js/enc-hex'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'destroyable', 'rxjs', 'crypto', 'crypto-js', 'crypto-js/enc-hex', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-browser"] = {}, global.spacetrim, global.destroyable, global.rxjs, global.
|
|
5
|
-
})(this, (function (exports, spacetrim, destroyable, rxjs, crypto, cryptoJs, hexEncoder,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('destroyable'), require('rxjs'), require('path'), require('crypto'), require('crypto-js'), require('crypto-js/enc-hex'), require('moment'), require('mime-types'), require('waitasecond'), require('crypto-js/sha256'), require('papaparse'), require('@openai/agents'), require('bottleneck'), require('colors'), require('openai')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'destroyable', 'rxjs', 'path', 'crypto', 'crypto-js', 'crypto-js/enc-hex', 'moment', 'mime-types', 'waitasecond', 'crypto-js/sha256', 'papaparse', '@openai/agents', 'bottleneck', 'colors', 'openai'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-browser"] = {}, global.spacetrim, global.destroyable, global.rxjs, global.path, global.crypto, global.cryptoJs, global.hexEncoder, global.moment, global.mimeTypes, global.waitasecond, global.sha256, global.papaparse, global.agents, global.Bottleneck, global.colors, global.OpenAI));
|
|
5
|
+
})(this, (function (exports, spacetrim, destroyable, rxjs, path, crypto, cryptoJs, hexEncoder, moment, mimeTypes, waitasecond, sha256, papaparse, agents, Bottleneck, colors, OpenAI) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-66';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -946,6 +946,29 @@
|
|
|
946
946
|
}
|
|
947
947
|
// TODO: Maybe implement by mix+hsl
|
|
948
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Relative directory name without the `./` prefix for Git ignore rules and glob patterns.
|
|
951
|
+
*
|
|
952
|
+
* @private internal utility for Promptbook-owned temp files
|
|
953
|
+
*/
|
|
954
|
+
const PROMPTBOOK_TEMP_DIRECTORY_NAME = '.promptbook';
|
|
955
|
+
/**
|
|
956
|
+
* Builds one project-relative path inside the shared Promptbook working directory.
|
|
957
|
+
*
|
|
958
|
+
* @private internal utility for Promptbook-owned temp files
|
|
959
|
+
*/
|
|
960
|
+
function getPromptbookTempPath(...pathSegments) {
|
|
961
|
+
return `./${getPromptbookTempPosixPath(...pathSegments)}`;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Builds one POSIX path fragment inside the shared Promptbook working directory for globs and generated text files.
|
|
965
|
+
*
|
|
966
|
+
* @private internal utility for Promptbook-owned temp files
|
|
967
|
+
*/
|
|
968
|
+
function getPromptbookTempPosixPath(...pathSegments) {
|
|
969
|
+
return path.posix.join(PROMPTBOOK_TEMP_DIRECTORY_NAME, ...pathSegments);
|
|
970
|
+
}
|
|
971
|
+
|
|
949
972
|
/**
|
|
950
973
|
* Returns the same value that is passed as argument.
|
|
951
974
|
* No side effects.
|
|
@@ -1128,7 +1151,6 @@
|
|
|
1128
1151
|
*/
|
|
1129
1152
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [🤹♂️]
|
|
1130
1153
|
// <- TODO: [🕝] Make also `AGENTS_DIRNAME_ALTERNATIVES`
|
|
1131
|
-
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
1132
1154
|
/**
|
|
1133
1155
|
* Where to store the temporary downloads
|
|
1134
1156
|
*
|
|
@@ -1136,7 +1158,15 @@
|
|
|
1136
1158
|
*
|
|
1137
1159
|
* @public exported from `@promptbook/core`
|
|
1138
1160
|
*/
|
|
1139
|
-
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = '
|
|
1161
|
+
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = getPromptbookTempPath('download-cache');
|
|
1162
|
+
/**
|
|
1163
|
+
* Where to store the cache of executions for promptbook CLI
|
|
1164
|
+
*
|
|
1165
|
+
* Note: When the folder does not exist, it is created recursively
|
|
1166
|
+
*
|
|
1167
|
+
* @public exported from `@promptbook/core`
|
|
1168
|
+
*/
|
|
1169
|
+
getPromptbookTempPath('execution-cache');
|
|
1140
1170
|
/**
|
|
1141
1171
|
* Where to store the scrape cache
|
|
1142
1172
|
*
|
|
@@ -1144,7 +1174,7 @@
|
|
|
1144
1174
|
*
|
|
1145
1175
|
* @public exported from `@promptbook/core`
|
|
1146
1176
|
*/
|
|
1147
|
-
const DEFAULT_SCRAPE_CACHE_DIRNAME = '
|
|
1177
|
+
const DEFAULT_SCRAPE_CACHE_DIRNAME = getPromptbookTempPath('scrape-cache');
|
|
1148
1178
|
// <- TODO: [🧜♂️]
|
|
1149
1179
|
/**
|
|
1150
1180
|
* Default settings for parsing and generating CSV files in Promptbook.
|
|
@@ -6975,18 +7005,6 @@
|
|
|
6975
7005
|
}
|
|
6976
7006
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
6977
7007
|
|
|
6978
|
-
/**
|
|
6979
|
-
* Name of the tool used by agents to search configured `KNOWLEDGE` sources.
|
|
6980
|
-
*
|
|
6981
|
-
* @public exported from `@promptbook/core`
|
|
6982
|
-
*/
|
|
6983
|
-
const KNOWLEDGE_SEARCH_TOOL_NAME = 'knowledge_search';
|
|
6984
|
-
/**
|
|
6985
|
-
* Title of the system-message section generated for `KNOWLEDGE` commitments.
|
|
6986
|
-
*
|
|
6987
|
-
* @private constant of `KnowledgeCommitmentDefinition`
|
|
6988
|
-
*/
|
|
6989
|
-
const KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE = 'Knowledge Search';
|
|
6990
7008
|
/**
|
|
6991
7009
|
* KNOWLEDGE commitment definition
|
|
6992
7010
|
*
|
|
@@ -7108,17 +7126,9 @@
|
|
|
7108
7126
|
knowledgeInfoEntries.push(`Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`);
|
|
7109
7127
|
}
|
|
7110
7128
|
if (knowledgeInfoEntries.length === 0) {
|
|
7111
|
-
return
|
|
7129
|
+
return nextRequirements;
|
|
7112
7130
|
}
|
|
7113
|
-
return
|
|
7114
|
-
}
|
|
7115
|
-
/**
|
|
7116
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
7117
|
-
*/
|
|
7118
|
-
getToolTitles() {
|
|
7119
|
-
return {
|
|
7120
|
-
[KNOWLEDGE_SEARCH_TOOL_NAME]: 'Knowledge search',
|
|
7121
|
-
};
|
|
7131
|
+
return this.appendToSystemMessage(nextRequirements, knowledgeInfoEntries.join('\n'), '\n\n');
|
|
7122
7132
|
}
|
|
7123
7133
|
}
|
|
7124
7134
|
/**
|
|
@@ -7132,128 +7142,6 @@
|
|
|
7132
7142
|
const significantText = contentWithoutUrls.replace(/[\s.,!?;:'"`()[\]{}<>/-]+/g, '');
|
|
7133
7143
|
return significantText.length > 0;
|
|
7134
7144
|
}
|
|
7135
|
-
/**
|
|
7136
|
-
* Adds the shared `knowledge_search` tool definition and the consolidated system-message section.
|
|
7137
|
-
*
|
|
7138
|
-
* @param requirements - Requirements after one `KNOWLEDGE` commitment was applied.
|
|
7139
|
-
* @returns Requirements with the knowledge search instructions and tool definition.
|
|
7140
|
-
*
|
|
7141
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7142
|
-
*/
|
|
7143
|
-
function addKnowledgeSearchToolAndSystemSection(requirements) {
|
|
7144
|
-
const nextRequirements = addKnowledgeSearchTool(requirements);
|
|
7145
|
-
const section = createKnowledgeSearchSystemSection(nextRequirements);
|
|
7146
|
-
const sectionHeader = `## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}`;
|
|
7147
|
-
if (nextRequirements.systemMessage.includes(sectionHeader)) {
|
|
7148
|
-
return {
|
|
7149
|
-
...nextRequirements,
|
|
7150
|
-
systemMessage: nextRequirements.systemMessage.replace(new RegExp(`## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), section),
|
|
7151
|
-
};
|
|
7152
|
-
}
|
|
7153
|
-
return {
|
|
7154
|
-
...nextRequirements,
|
|
7155
|
-
systemMessage: nextRequirements.systemMessage.trim()
|
|
7156
|
-
? `${nextRequirements.systemMessage}\n\n${section}`
|
|
7157
|
-
: section,
|
|
7158
|
-
};
|
|
7159
|
-
}
|
|
7160
|
-
/**
|
|
7161
|
-
* Adds the `knowledge_search` model tool when it is not already present.
|
|
7162
|
-
*
|
|
7163
|
-
* @param requirements - Current model requirements.
|
|
7164
|
-
* @returns Requirements with the tool definition available to the model.
|
|
7165
|
-
*
|
|
7166
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7167
|
-
*/
|
|
7168
|
-
function addKnowledgeSearchTool(requirements) {
|
|
7169
|
-
const existingTools = requirements.tools || [];
|
|
7170
|
-
if (existingTools.some((tool) => tool.name === KNOWLEDGE_SEARCH_TOOL_NAME)) {
|
|
7171
|
-
return requirements;
|
|
7172
|
-
}
|
|
7173
|
-
return {
|
|
7174
|
-
...requirements,
|
|
7175
|
-
tools: [
|
|
7176
|
-
...existingTools,
|
|
7177
|
-
{
|
|
7178
|
-
name: KNOWLEDGE_SEARCH_TOOL_NAME,
|
|
7179
|
-
description: spacetrim.spaceTrim(`
|
|
7180
|
-
Search the agent's configured knowledge sources and return relevant excerpts with citation ids.
|
|
7181
|
-
Use this before answering questions that may depend on the agent's KNOWLEDGE commitments.
|
|
7182
|
-
`),
|
|
7183
|
-
parameters: {
|
|
7184
|
-
type: 'object',
|
|
7185
|
-
properties: {
|
|
7186
|
-
query: {
|
|
7187
|
-
type: 'string',
|
|
7188
|
-
description: 'The natural-language search query for the knowledge base.',
|
|
7189
|
-
},
|
|
7190
|
-
limit: {
|
|
7191
|
-
type: 'integer',
|
|
7192
|
-
description: 'Maximum number of matching source excerpts to return.',
|
|
7193
|
-
},
|
|
7194
|
-
},
|
|
7195
|
-
required: ['query'],
|
|
7196
|
-
},
|
|
7197
|
-
},
|
|
7198
|
-
],
|
|
7199
|
-
};
|
|
7200
|
-
}
|
|
7201
|
-
/**
|
|
7202
|
-
* Creates the model-facing system-message section for knowledge search.
|
|
7203
|
-
*
|
|
7204
|
-
* @param requirements - Current model requirements.
|
|
7205
|
-
* @returns Markdown system-message section.
|
|
7206
|
-
*
|
|
7207
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7208
|
-
*/
|
|
7209
|
-
function createKnowledgeSearchSystemSection(requirements) {
|
|
7210
|
-
const sourceEntries = createKnowledgeSourceSystemEntries(requirements);
|
|
7211
|
-
const sourceList = sourceEntries.length > 0 ? sourceEntries.map((entry) => `- ${entry}`).join('\n') : '- None';
|
|
7212
|
-
return spacetrim.spaceTrim(`
|
|
7213
|
-
## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}
|
|
7214
|
-
|
|
7215
|
-
- Use \`${KNOWLEDGE_SEARCH_TOOL_NAME}\` to search the configured knowledge sources before answering questions that depend on this agent's knowledge base.
|
|
7216
|
-
- Base source-backed factual answers on the returned excerpts.
|
|
7217
|
-
- When you use a returned excerpt, include its citation marker in the answer body, for example \`[0:0]\`.
|
|
7218
|
-
- If the search returns no relevant information, say that the knowledge base did not contain the answer instead of inventing it.
|
|
7219
|
-
|
|
7220
|
-
Configured knowledge sources:
|
|
7221
|
-
${sourceList}
|
|
7222
|
-
`);
|
|
7223
|
-
}
|
|
7224
|
-
/**
|
|
7225
|
-
* Builds a stable list of configured knowledge sources for system-message diagnostics.
|
|
7226
|
-
*
|
|
7227
|
-
* @param requirements - Current model requirements.
|
|
7228
|
-
* @returns Human-readable source entries.
|
|
7229
|
-
*
|
|
7230
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
7231
|
-
*/
|
|
7232
|
-
function createKnowledgeSourceSystemEntries(requirements) {
|
|
7233
|
-
var _a;
|
|
7234
|
-
const entries = [];
|
|
7235
|
-
const seenEntries = new Set();
|
|
7236
|
-
for (const source of requirements.knowledgeSources || []) {
|
|
7237
|
-
const entry = `Source URL: ${source} (processed for retrieval during chat)`;
|
|
7238
|
-
if (seenEntries.has(entry)) {
|
|
7239
|
-
continue;
|
|
7240
|
-
}
|
|
7241
|
-
seenEntries.add(entry);
|
|
7242
|
-
entries.push(entry);
|
|
7243
|
-
}
|
|
7244
|
-
const inlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || [])
|
|
7245
|
-
.map((source) => source.filename)
|
|
7246
|
-
.filter(Boolean);
|
|
7247
|
-
for (const filename of inlineSources) {
|
|
7248
|
-
const entry = `Knowledge Source Inline: ${filename} (Inline source: processed for retrieval during chat)`;
|
|
7249
|
-
if (seenEntries.has(entry)) {
|
|
7250
|
-
continue;
|
|
7251
|
-
}
|
|
7252
|
-
seenEntries.add(entry);
|
|
7253
|
-
entries.push(entry);
|
|
7254
|
-
}
|
|
7255
|
-
return entries;
|
|
7256
|
-
}
|
|
7257
7145
|
|
|
7258
7146
|
/**
|
|
7259
7147
|
* LANGUAGE commitment definition
|
|
@@ -9905,6 +9793,177 @@
|
|
|
9905
9793
|
context.restore();
|
|
9906
9794
|
}
|
|
9907
9795
|
|
|
9796
|
+
/* eslint-disable no-magic-numbers */
|
|
9797
|
+
/**
|
|
9798
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style head cuboid.
|
|
9799
|
+
*
|
|
9800
|
+
* @param random Seeded random generator.
|
|
9801
|
+
* @param palette Derived avatar palette.
|
|
9802
|
+
* @param hasHeadband Whether the generated avatar should include a colored headband.
|
|
9803
|
+
* @returns Head cuboid textures.
|
|
9804
|
+
*
|
|
9805
|
+
* @private helper of the Minecraft avatar visuals
|
|
9806
|
+
*/
|
|
9807
|
+
function createMinecraftHeadTextures(random, palette, hasHeadband) {
|
|
9808
|
+
const faceTexture = createMinecraftFaceTexture(random, palette, hasHeadband);
|
|
9809
|
+
const hairColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
9810
|
+
const skinColor = palette.highlight;
|
|
9811
|
+
const headbandColor = hasHeadband ? palette.accent : hairColor;
|
|
9812
|
+
const sideTexture = createFilledTexture(skinColor);
|
|
9813
|
+
const backTexture = createFilledTexture(skinColor);
|
|
9814
|
+
const topTexture = createFilledTexture(hairColor);
|
|
9815
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}cc`);
|
|
9816
|
+
fillTextureRect(sideTexture, 0, 0, 8, 3, hairColor);
|
|
9817
|
+
fillTextureRect(backTexture, 0, 0, 8, 5, hairColor);
|
|
9818
|
+
fillTextureRect(backTexture, 1, 5, 6, 1, hairColor);
|
|
9819
|
+
if (hasHeadband) {
|
|
9820
|
+
fillTextureRect(sideTexture, 0, 2, 8, 1, headbandColor);
|
|
9821
|
+
fillTextureRect(backTexture, 0, 2, 8, 1, headbandColor);
|
|
9822
|
+
fillTextureRect(topTexture, 0, 4, 8, 1, headbandColor);
|
|
9823
|
+
}
|
|
9824
|
+
sideTexture[4][4] = `${palette.shadow}99`;
|
|
9825
|
+
sideTexture[5][4] = `${palette.shadow}cc`;
|
|
9826
|
+
backTexture[6][2] = `${palette.shadow}99`;
|
|
9827
|
+
backTexture[6][5] = `${palette.shadow}99`;
|
|
9828
|
+
return {
|
|
9829
|
+
front: faceTexture,
|
|
9830
|
+
back: backTexture,
|
|
9831
|
+
left: sideTexture,
|
|
9832
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
9833
|
+
top: topTexture,
|
|
9834
|
+
bottom: bottomTexture,
|
|
9835
|
+
};
|
|
9836
|
+
}
|
|
9837
|
+
/**
|
|
9838
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style torso cuboid.
|
|
9839
|
+
*
|
|
9840
|
+
* @param random Seeded random generator.
|
|
9841
|
+
* @param palette Derived avatar palette.
|
|
9842
|
+
* @returns Torso cuboid textures.
|
|
9843
|
+
*
|
|
9844
|
+
* @private helper of the Minecraft avatar visuals
|
|
9845
|
+
*/
|
|
9846
|
+
function createMinecraftTorsoTextures(random, palette) {
|
|
9847
|
+
const frontTexture = createMinecraftShirtTexture(random, palette);
|
|
9848
|
+
const sideTexture = createFilledTexture(palette.primary);
|
|
9849
|
+
const backTexture = createFilledTexture(palette.primary);
|
|
9850
|
+
const topTexture = createFilledTexture(`${palette.highlight}dd`);
|
|
9851
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}dd`);
|
|
9852
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
9853
|
+
fillTextureRect(sideTexture, 0, 0, 8, 2, palette.shadow);
|
|
9854
|
+
fillTextureRect(backTexture, 0, 0, 8, 2, palette.shadow);
|
|
9855
|
+
fillTextureRect(backTexture, 3, 2, 2, 6, stripeColor);
|
|
9856
|
+
fillTextureRect(sideTexture, 4, 2, 1, 6, stripeColor);
|
|
9857
|
+
fillTextureRect(topTexture, 0, 0, 8, 2, palette.shadow);
|
|
9858
|
+
fillTextureRect(topTexture, 2, 2, 4, 4, stripeColor);
|
|
9859
|
+
return {
|
|
9860
|
+
front: frontTexture,
|
|
9861
|
+
back: backTexture,
|
|
9862
|
+
left: sideTexture,
|
|
9863
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
9864
|
+
top: topTexture,
|
|
9865
|
+
bottom: bottomTexture,
|
|
9866
|
+
};
|
|
9867
|
+
}
|
|
9868
|
+
/**
|
|
9869
|
+
* Mirrors one Minecraft texture horizontally.
|
|
9870
|
+
*
|
|
9871
|
+
* @param texture Source texture.
|
|
9872
|
+
* @returns Mirrored texture copy.
|
|
9873
|
+
*
|
|
9874
|
+
* @private helper of the Minecraft avatar visuals
|
|
9875
|
+
*/
|
|
9876
|
+
function mirrorMinecraftTexture(texture) {
|
|
9877
|
+
return texture.map((row) => [...row].reverse());
|
|
9878
|
+
}
|
|
9879
|
+
/**
|
|
9880
|
+
* Creates the front-face pixel texture for the cube head.
|
|
9881
|
+
*
|
|
9882
|
+
* @param random Seeded random generator.
|
|
9883
|
+
* @param palette Derived avatar palette.
|
|
9884
|
+
* @param hasHeadband Whether the avatar should render a headband row.
|
|
9885
|
+
* @returns 8x8 pixel texture.
|
|
9886
|
+
*
|
|
9887
|
+
* @private helper of the Minecraft avatar visuals
|
|
9888
|
+
*/
|
|
9889
|
+
function createMinecraftFaceTexture(random, palette, hasHeadband) {
|
|
9890
|
+
const texture = createFilledTexture(palette.highlight);
|
|
9891
|
+
const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
9892
|
+
const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
|
|
9893
|
+
fillTextureRect(texture, 0, 0, 8, 2, hairlineColor);
|
|
9894
|
+
texture[2][0] = hairlineColor;
|
|
9895
|
+
texture[2][7] = hairlineColor;
|
|
9896
|
+
texture[3][0] = hairlineColor;
|
|
9897
|
+
texture[3][7] = hairlineColor;
|
|
9898
|
+
if (hasHeadband) {
|
|
9899
|
+
fillTextureRect(texture, 0, 2, 8, 1, palette.accent);
|
|
9900
|
+
}
|
|
9901
|
+
texture[3][2] = palette.ink;
|
|
9902
|
+
texture[3][5] = palette.ink;
|
|
9903
|
+
texture[4][2] = '#ffffff';
|
|
9904
|
+
texture[4][5] = '#ffffff';
|
|
9905
|
+
texture[5][1] = cheekColor;
|
|
9906
|
+
texture[5][6] = cheekColor;
|
|
9907
|
+
texture[5][3] = palette.shadow;
|
|
9908
|
+
texture[5][4] = palette.shadow;
|
|
9909
|
+
texture[6][3] = palette.shadow;
|
|
9910
|
+
texture[6][4] = palette.shadow;
|
|
9911
|
+
return texture;
|
|
9912
|
+
}
|
|
9913
|
+
/**
|
|
9914
|
+
* Creates the front-face pixel texture for the torso.
|
|
9915
|
+
*
|
|
9916
|
+
* @param random Seeded random generator.
|
|
9917
|
+
* @param palette Derived avatar palette.
|
|
9918
|
+
* @returns 8x8 torso texture.
|
|
9919
|
+
*
|
|
9920
|
+
* @private helper of the Minecraft avatar visuals
|
|
9921
|
+
*/
|
|
9922
|
+
function createMinecraftShirtTexture(random, palette) {
|
|
9923
|
+
const texture = createFilledTexture(palette.primary);
|
|
9924
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
9925
|
+
fillTextureRect(texture, 0, 0, 8, 2, palette.shadow);
|
|
9926
|
+
for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
|
|
9927
|
+
texture[rowIndex][3] = stripeColor;
|
|
9928
|
+
texture[rowIndex][4] = stripeColor;
|
|
9929
|
+
}
|
|
9930
|
+
texture[4][1] = palette.accent;
|
|
9931
|
+
texture[4][6] = palette.accent;
|
|
9932
|
+
texture[5][2] = palette.highlight;
|
|
9933
|
+
texture[5][5] = palette.highlight;
|
|
9934
|
+
return texture;
|
|
9935
|
+
}
|
|
9936
|
+
/**
|
|
9937
|
+
* Creates one solid-color 8x8 Minecraft texture.
|
|
9938
|
+
*
|
|
9939
|
+
* @param color Fill color.
|
|
9940
|
+
* @returns Filled 8x8 texture.
|
|
9941
|
+
*
|
|
9942
|
+
* @private helper of the Minecraft avatar visuals
|
|
9943
|
+
*/
|
|
9944
|
+
function createFilledTexture(color) {
|
|
9945
|
+
return Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => color));
|
|
9946
|
+
}
|
|
9947
|
+
/**
|
|
9948
|
+
* Fills one rectangular area inside a mutable Minecraft texture.
|
|
9949
|
+
*
|
|
9950
|
+
* @param texture Mutable target texture.
|
|
9951
|
+
* @param x Left texture coordinate.
|
|
9952
|
+
* @param y Top texture coordinate.
|
|
9953
|
+
* @param width Rectangle width.
|
|
9954
|
+
* @param height Rectangle height.
|
|
9955
|
+
* @param color Fill color.
|
|
9956
|
+
*
|
|
9957
|
+
* @private helper of the Minecraft avatar visuals
|
|
9958
|
+
*/
|
|
9959
|
+
function fillTextureRect(texture, x, y, width, height, color) {
|
|
9960
|
+
for (let rowIndex = y; rowIndex < y + height; rowIndex++) {
|
|
9961
|
+
for (let columnIndex = x; columnIndex < x + width; columnIndex++) {
|
|
9962
|
+
texture[rowIndex][columnIndex] = color;
|
|
9963
|
+
}
|
|
9964
|
+
}
|
|
9965
|
+
}
|
|
9966
|
+
|
|
9908
9967
|
/* eslint-disable no-magic-numbers */
|
|
9909
9968
|
/**
|
|
9910
9969
|
* Minecraft-style 3D avatar visual.
|
|
@@ -9929,8 +9988,8 @@
|
|
|
9929
9988
|
const bodyX = size * 0.33;
|
|
9930
9989
|
const bodyY = headY + headSize * 0.96;
|
|
9931
9990
|
const hasHeadband = random() < 0.5;
|
|
9932
|
-
const
|
|
9933
|
-
const
|
|
9991
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft-face'), palette, hasHeadband);
|
|
9992
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft-shirt'), palette);
|
|
9934
9993
|
drawAvatarFrame(context, size, palette);
|
|
9935
9994
|
const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
|
|
9936
9995
|
spotlight.addColorStop(0, `${palette.highlight}66`);
|
|
@@ -9950,7 +10009,7 @@
|
|
|
9950
10009
|
width: bodyWidth,
|
|
9951
10010
|
height: bodyHeight,
|
|
9952
10011
|
depth: bodyDepth,
|
|
9953
|
-
frontTexture:
|
|
10012
|
+
frontTexture: torsoTextures.front,
|
|
9954
10013
|
topColor: `${palette.highlight}cc`,
|
|
9955
10014
|
sideColor: `${palette.secondary}dd`,
|
|
9956
10015
|
outlineColor: `${palette.shadow}aa`,
|
|
@@ -9961,7 +10020,7 @@
|
|
|
9961
10020
|
width: headSize,
|
|
9962
10021
|
height: headSize,
|
|
9963
10022
|
depth,
|
|
9964
|
-
frontTexture:
|
|
10023
|
+
frontTexture: headTextures.front,
|
|
9965
10024
|
topColor: `${palette.highlight}ee`,
|
|
9966
10025
|
sideColor: `${palette.secondary}ee`,
|
|
9967
10026
|
outlineColor: `${palette.shadow}cc`,
|
|
@@ -10026,72 +10085,505 @@
|
|
|
10026
10085
|
context.closePath();
|
|
10027
10086
|
context.stroke();
|
|
10028
10087
|
}
|
|
10088
|
+
|
|
10089
|
+
/* eslint-disable no-magic-numbers */
|
|
10029
10090
|
/**
|
|
10030
|
-
*
|
|
10091
|
+
* Fixed scene camera distance used for the proper-3D projection.
|
|
10031
10092
|
*
|
|
10032
|
-
* @
|
|
10093
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10094
|
+
*/
|
|
10095
|
+
const CAMERA_DISTANCE_RATIO = 1.4;
|
|
10096
|
+
/**
|
|
10097
|
+
* Shared light direction used to shade projected cuboid faces.
|
|
10098
|
+
*
|
|
10099
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10100
|
+
*/
|
|
10101
|
+
const LIGHT_DIRECTION = normalizeVector3({
|
|
10102
|
+
x: 0.4,
|
|
10103
|
+
y: -0.65,
|
|
10104
|
+
z: 0.92,
|
|
10105
|
+
});
|
|
10106
|
+
/**
|
|
10107
|
+
* Minecraft 3D 2 avatar visual.
|
|
10108
|
+
*
|
|
10109
|
+
* @private built-in avatar visual
|
|
10110
|
+
*/
|
|
10111
|
+
const minecraft2AvatarVisual = {
|
|
10112
|
+
id: 'minecraft2',
|
|
10113
|
+
title: 'Minecraft 3D 2',
|
|
10114
|
+
description: 'Proper 3D Minecraft-style portrait with textured cuboids and pointer-driven head turns.',
|
|
10115
|
+
isAnimated: true,
|
|
10116
|
+
supportsPointerTracking: true,
|
|
10117
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
10118
|
+
const spotlightY = size * 0.22;
|
|
10119
|
+
const headRandom = createRandom('minecraft2-head');
|
|
10120
|
+
const hasHeadband = headRandom() < 0.5;
|
|
10121
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft2-head-textures'), palette, hasHeadband);
|
|
10122
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft2-body-textures'), palette);
|
|
10123
|
+
const bob = Math.sin(timeMs / 880) * size * 0.014;
|
|
10124
|
+
const bodyYaw = -0.24 + Math.sin(timeMs / 2300) * 0.06 + interaction.bodyOffsetX * 0.16;
|
|
10125
|
+
const bodyPitch = -0.12 + Math.cos(timeMs / 2800) * 0.02 - interaction.bodyOffsetY * 0.06;
|
|
10126
|
+
const headYaw = -0.18 + Math.sin(timeMs / 1900 + 0.6) * 0.05 + interaction.gazeX * 0.62;
|
|
10127
|
+
const headPitch = -0.12 + Math.cos(timeMs / 2400 + 1.1) * 0.03 - interaction.gazeY * 0.38;
|
|
10128
|
+
const sceneCenterX = size * 0.5;
|
|
10129
|
+
const sceneCenterY = size * 0.57;
|
|
10130
|
+
const bodyWidth = size * 0.225;
|
|
10131
|
+
const bodyHeight = size * 0.245;
|
|
10132
|
+
const bodyDepth = size * 0.145;
|
|
10133
|
+
const headSize = size * 0.24;
|
|
10134
|
+
const headLift = size * 0.205;
|
|
10135
|
+
const headForwardShift = interaction.intensity * size * 0.018;
|
|
10136
|
+
const sceneCuboids = [
|
|
10137
|
+
{
|
|
10138
|
+
center: {
|
|
10139
|
+
x: interaction.bodyOffsetX * size * 0.026,
|
|
10140
|
+
y: size * 0.05 + interaction.bodyOffsetY * size * 0.018 + bob,
|
|
10141
|
+
z: 0,
|
|
10142
|
+
},
|
|
10143
|
+
width: bodyWidth,
|
|
10144
|
+
height: bodyHeight,
|
|
10145
|
+
depth: bodyDepth,
|
|
10146
|
+
rotationX: bodyPitch,
|
|
10147
|
+
rotationY: bodyYaw,
|
|
10148
|
+
textures: torsoTextures,
|
|
10149
|
+
outlineColor: `${palette.shadow}cc`,
|
|
10150
|
+
},
|
|
10151
|
+
{
|
|
10152
|
+
center: {
|
|
10153
|
+
x: interaction.bodyOffsetX * size * 0.018 + interaction.gazeX * size * 0.016,
|
|
10154
|
+
y: -headLift + bob * 1.15,
|
|
10155
|
+
z: headForwardShift,
|
|
10156
|
+
},
|
|
10157
|
+
width: headSize,
|
|
10158
|
+
height: headSize,
|
|
10159
|
+
depth: headSize,
|
|
10160
|
+
rotationX: headPitch,
|
|
10161
|
+
rotationY: headYaw,
|
|
10162
|
+
textures: headTextures,
|
|
10163
|
+
outlineColor: `${palette.shadow}dd`,
|
|
10164
|
+
},
|
|
10165
|
+
];
|
|
10166
|
+
const visibleFaces = sceneCuboids
|
|
10167
|
+
.flatMap((cuboid) => resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY))
|
|
10168
|
+
.sort((firstFace, secondFace) => firstFace.averageDepth - secondFace.averageDepth);
|
|
10169
|
+
drawAvatarFrame(context, size, palette);
|
|
10170
|
+
drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs);
|
|
10171
|
+
drawMinecraftShadow(context, size, palette, interaction, timeMs);
|
|
10172
|
+
for (const visibleFace of visibleFaces) {
|
|
10173
|
+
drawTexturedProjectedFace(context, visibleFace);
|
|
10174
|
+
}
|
|
10175
|
+
},
|
|
10176
|
+
};
|
|
10177
|
+
/**
|
|
10178
|
+
* Draws the shared background atmosphere behind the Minecraft 3D 2 portrait.
|
|
10179
|
+
*
|
|
10180
|
+
* @param context Canvas 2D context.
|
|
10181
|
+
* @param size Canvas size in CSS pixels.
|
|
10033
10182
|
* @param palette Derived avatar palette.
|
|
10034
|
-
* @param
|
|
10035
|
-
* @
|
|
10183
|
+
* @param sceneCenterX Horizontal scene center.
|
|
10184
|
+
* @param spotlightY Vertical spotlight anchor.
|
|
10185
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
10186
|
+
* @param timeMs Current animation time in milliseconds.
|
|
10036
10187
|
*
|
|
10037
|
-
* @private helper of `
|
|
10188
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10038
10189
|
*/
|
|
10039
|
-
function
|
|
10040
|
-
const
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10190
|
+
function drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs) {
|
|
10191
|
+
const spotlightGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.08, spotlightY + interaction.gazeY * size * 0.05, size * 0.03, sceneCenterX, spotlightY, size * 0.52);
|
|
10192
|
+
spotlightGradient.addColorStop(0, `${palette.highlight}66`);
|
|
10193
|
+
spotlightGradient.addColorStop(0.42, `${palette.accent}1d`);
|
|
10194
|
+
spotlightGradient.addColorStop(1, `${palette.highlight}00`);
|
|
10195
|
+
context.fillStyle = spotlightGradient;
|
|
10196
|
+
context.fillRect(0, 0, size, size);
|
|
10197
|
+
const rimGradient = context.createLinearGradient(0, size * 0.14, 0, size * 0.92);
|
|
10198
|
+
rimGradient.addColorStop(0, `${palette.highlight}12`);
|
|
10199
|
+
rimGradient.addColorStop(0.55, `${palette.secondary}0a`);
|
|
10200
|
+
rimGradient.addColorStop(1, `${palette.shadow}00`);
|
|
10201
|
+
context.fillStyle = rimGradient;
|
|
10202
|
+
context.fillRect(0, 0, size, size);
|
|
10203
|
+
context.save();
|
|
10204
|
+
context.globalAlpha = 0.08 + interaction.intensity * 0.04;
|
|
10205
|
+
context.fillStyle = palette.highlight;
|
|
10206
|
+
context.beginPath();
|
|
10207
|
+
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);
|
|
10208
|
+
context.fill();
|
|
10209
|
+
context.restore();
|
|
10210
|
+
}
|
|
10211
|
+
/**
|
|
10212
|
+
* Draws the soft floor shadow used to anchor the cuboids in the frame.
|
|
10213
|
+
*
|
|
10214
|
+
* @param context Canvas 2D context.
|
|
10215
|
+
* @param size Canvas size in CSS pixels.
|
|
10216
|
+
* @param palette Derived avatar palette.
|
|
10217
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
10218
|
+
* @param timeMs Current animation time in milliseconds.
|
|
10219
|
+
*
|
|
10220
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10221
|
+
*/
|
|
10222
|
+
function drawMinecraftShadow(context, size, palette, interaction, timeMs) {
|
|
10223
|
+
context.save();
|
|
10224
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
10225
|
+
context.filter = `blur(${size * 0.02}px)`;
|
|
10226
|
+
context.beginPath();
|
|
10227
|
+
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);
|
|
10228
|
+
context.fill();
|
|
10229
|
+
context.restore();
|
|
10230
|
+
}
|
|
10231
|
+
/**
|
|
10232
|
+
* Resolves all visible projected faces for one scene cuboid.
|
|
10233
|
+
*
|
|
10234
|
+
* @param cuboid Scene cuboid definition.
|
|
10235
|
+
* @param size Canvas size in CSS pixels.
|
|
10236
|
+
* @param sceneCenterX Horizontal scene center.
|
|
10237
|
+
* @param sceneCenterY Vertical scene center.
|
|
10238
|
+
* @returns Visible faces sorted later by depth.
|
|
10239
|
+
*
|
|
10240
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10241
|
+
*/
|
|
10242
|
+
function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
|
|
10243
|
+
const halfWidth = cuboid.width / 2;
|
|
10244
|
+
const halfHeight = cuboid.height / 2;
|
|
10245
|
+
const halfDepth = cuboid.depth / 2;
|
|
10246
|
+
const faceDefinitions = [
|
|
10247
|
+
{
|
|
10248
|
+
texture: cuboid.textures.front,
|
|
10249
|
+
corners: [
|
|
10250
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
10251
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
10252
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
10253
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
10254
|
+
],
|
|
10255
|
+
},
|
|
10256
|
+
{
|
|
10257
|
+
texture: cuboid.textures.back,
|
|
10258
|
+
corners: [
|
|
10259
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10260
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10261
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
10262
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
10263
|
+
],
|
|
10264
|
+
},
|
|
10265
|
+
{
|
|
10266
|
+
texture: cuboid.textures.right,
|
|
10267
|
+
corners: [
|
|
10268
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
10269
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10270
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
10271
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
10272
|
+
],
|
|
10273
|
+
},
|
|
10274
|
+
{
|
|
10275
|
+
texture: cuboid.textures.left,
|
|
10276
|
+
corners: [
|
|
10277
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10278
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
10279
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
10280
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
10281
|
+
],
|
|
10282
|
+
},
|
|
10283
|
+
{
|
|
10284
|
+
texture: cuboid.textures.top,
|
|
10285
|
+
corners: [
|
|
10286
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10287
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
10288
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
10289
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
10290
|
+
],
|
|
10291
|
+
},
|
|
10292
|
+
{
|
|
10293
|
+
texture: cuboid.textures.bottom,
|
|
10294
|
+
corners: [
|
|
10295
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
10296
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
10297
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
10298
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
10299
|
+
],
|
|
10300
|
+
},
|
|
10301
|
+
];
|
|
10302
|
+
const visibleFaces = faceDefinitions
|
|
10303
|
+
.map((faceDefinition) => {
|
|
10304
|
+
const transformedCorners = faceDefinition.corners.map((corner) => transformScenePoint(corner, cuboid.center, cuboid.rotationX, cuboid.rotationY));
|
|
10305
|
+
const faceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
|
|
10306
|
+
if (faceNormal.z <= 0.02) {
|
|
10307
|
+
return null;
|
|
10046
10308
|
}
|
|
10309
|
+
const projectedCorners = transformedCorners.map((corner) => projectScenePoint(corner, size, sceneCenterX, sceneCenterY));
|
|
10310
|
+
return {
|
|
10311
|
+
corners: projectedCorners,
|
|
10312
|
+
texture: faceDefinition.texture,
|
|
10313
|
+
averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
|
|
10314
|
+
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION), -1, 1),
|
|
10315
|
+
outlineColor: cuboid.outlineColor,
|
|
10316
|
+
};
|
|
10317
|
+
});
|
|
10318
|
+
return visibleFaces.filter((visibleFace) => visibleFace !== null);
|
|
10319
|
+
}
|
|
10320
|
+
/**
|
|
10321
|
+
* Draws one projected textured face by tessellating its texture cells into quads.
|
|
10322
|
+
*
|
|
10323
|
+
* @param context Canvas 2D context.
|
|
10324
|
+
* @param face Visible projected face.
|
|
10325
|
+
*
|
|
10326
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10327
|
+
*/
|
|
10328
|
+
function drawTexturedProjectedFace(context, face) {
|
|
10329
|
+
var _a;
|
|
10330
|
+
const rows = face.texture.length;
|
|
10331
|
+
const columns = ((_a = face.texture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
10332
|
+
if (rows === 0 || columns === 0) {
|
|
10333
|
+
return;
|
|
10047
10334
|
}
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10335
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
10336
|
+
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
|
|
10337
|
+
const startX = columnIndex / columns;
|
|
10338
|
+
const endX = (columnIndex + 1) / columns;
|
|
10339
|
+
const startY = rowIndex / rows;
|
|
10340
|
+
const endY = (rowIndex + 1) / rows;
|
|
10341
|
+
drawProjectedQuad(context, [
|
|
10342
|
+
interpolateProjectedQuad(face.corners, startX, startY),
|
|
10343
|
+
interpolateProjectedQuad(face.corners, endX, startY),
|
|
10344
|
+
interpolateProjectedQuad(face.corners, endX, endY),
|
|
10345
|
+
interpolateProjectedQuad(face.corners, startX, endY),
|
|
10346
|
+
], face.texture[rowIndex][columnIndex]);
|
|
10055
10347
|
}
|
|
10056
10348
|
}
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10349
|
+
if (face.lightIntensity > 0) {
|
|
10350
|
+
drawProjectedQuad(context, face.corners, `rgba(255, 255, 255, ${0.15 * face.lightIntensity})`);
|
|
10351
|
+
}
|
|
10352
|
+
else if (face.lightIntensity < 0) {
|
|
10353
|
+
drawProjectedQuad(context, face.corners, `rgba(0, 0, 0, ${0.22 * Math.abs(face.lightIntensity)})`);
|
|
10354
|
+
}
|
|
10355
|
+
context.save();
|
|
10356
|
+
context.beginPath();
|
|
10357
|
+
context.moveTo(face.corners[0].x, face.corners[0].y);
|
|
10358
|
+
for (let cornerIndex = 1; cornerIndex < face.corners.length; cornerIndex++) {
|
|
10359
|
+
context.lineTo(face.corners[cornerIndex].x, face.corners[cornerIndex].y);
|
|
10360
|
+
}
|
|
10361
|
+
context.closePath();
|
|
10362
|
+
context.strokeStyle = face.outlineColor;
|
|
10363
|
+
context.lineWidth = Math.max(1.1, getProjectedQuadPerimeter(face.corners) * 0.0045);
|
|
10364
|
+
context.lineJoin = 'round';
|
|
10365
|
+
context.stroke();
|
|
10366
|
+
context.restore();
|
|
10068
10367
|
}
|
|
10069
10368
|
/**
|
|
10070
|
-
*
|
|
10369
|
+
* Draws one filled projected quad.
|
|
10071
10370
|
*
|
|
10072
|
-
* @param
|
|
10073
|
-
* @param
|
|
10074
|
-
* @
|
|
10371
|
+
* @param context Canvas 2D context.
|
|
10372
|
+
* @param corners Quad corners in clockwise order.
|
|
10373
|
+
* @param fillStyle CSS fill style.
|
|
10075
10374
|
*
|
|
10076
|
-
* @private helper of `
|
|
10375
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10077
10376
|
*/
|
|
10078
|
-
function
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10377
|
+
function drawProjectedQuad(context, corners, fillStyle) {
|
|
10378
|
+
context.beginPath();
|
|
10379
|
+
context.moveTo(corners[0].x, corners[0].y);
|
|
10380
|
+
context.lineTo(corners[1].x, corners[1].y);
|
|
10381
|
+
context.lineTo(corners[2].x, corners[2].y);
|
|
10382
|
+
context.lineTo(corners[3].x, corners[3].y);
|
|
10383
|
+
context.closePath();
|
|
10384
|
+
context.fillStyle = fillStyle;
|
|
10385
|
+
context.fill();
|
|
10386
|
+
}
|
|
10387
|
+
/**
|
|
10388
|
+
* Interpolates one point inside a projected quad across both quad axes.
|
|
10389
|
+
*
|
|
10390
|
+
* @param corners Quad corners in clockwise order.
|
|
10391
|
+
* @param horizontalRatio Horizontal ratio in the range `[0, 1]`.
|
|
10392
|
+
* @param verticalRatio Vertical ratio in the range `[0, 1]`.
|
|
10393
|
+
* @returns Interpolated projected point.
|
|
10394
|
+
*
|
|
10395
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10396
|
+
*/
|
|
10397
|
+
function interpolateProjectedQuad(corners, horizontalRatio, verticalRatio) {
|
|
10398
|
+
const topPoint = interpolateProjectedPoint(corners[0], corners[1], horizontalRatio);
|
|
10399
|
+
const bottomPoint = interpolateProjectedPoint(corners[3], corners[2], horizontalRatio);
|
|
10400
|
+
return interpolateProjectedPoint(topPoint, bottomPoint, verticalRatio);
|
|
10401
|
+
}
|
|
10402
|
+
/**
|
|
10403
|
+
* Interpolates between two projected points.
|
|
10404
|
+
*
|
|
10405
|
+
* @param startPoint Start point.
|
|
10406
|
+
* @param endPoint End point.
|
|
10407
|
+
* @param ratio Interpolation ratio in the range `[0, 1]`.
|
|
10408
|
+
* @returns Interpolated projected point.
|
|
10409
|
+
*
|
|
10410
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10411
|
+
*/
|
|
10412
|
+
function interpolateProjectedPoint(startPoint, endPoint, ratio) {
|
|
10413
|
+
return {
|
|
10414
|
+
x: startPoint.x + (endPoint.x - startPoint.x) * ratio,
|
|
10415
|
+
y: startPoint.y + (endPoint.y - startPoint.y) * ratio,
|
|
10416
|
+
z: startPoint.z + (endPoint.z - startPoint.z) * ratio,
|
|
10417
|
+
};
|
|
10418
|
+
}
|
|
10419
|
+
/**
|
|
10420
|
+
* Projects one rotated scene point into canvas coordinates.
|
|
10421
|
+
*
|
|
10422
|
+
* @param point Scene point.
|
|
10423
|
+
* @param size Canvas size in CSS pixels.
|
|
10424
|
+
* @param sceneCenterX Horizontal scene center.
|
|
10425
|
+
* @param sceneCenterY Vertical scene center.
|
|
10426
|
+
* @returns Projected point.
|
|
10427
|
+
*
|
|
10428
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10429
|
+
*/
|
|
10430
|
+
function projectScenePoint(point, size, sceneCenterX, sceneCenterY) {
|
|
10431
|
+
const cameraDistance = size * CAMERA_DISTANCE_RATIO;
|
|
10432
|
+
const perspectiveScale = cameraDistance / Math.max(cameraDistance - point.z, cameraDistance * 0.35);
|
|
10433
|
+
return {
|
|
10434
|
+
x: sceneCenterX + point.x * perspectiveScale,
|
|
10435
|
+
y: sceneCenterY + point.y * perspectiveScale,
|
|
10436
|
+
z: point.z,
|
|
10437
|
+
};
|
|
10438
|
+
}
|
|
10439
|
+
/**
|
|
10440
|
+
* Applies the local cuboid rotations and translation to one scene point.
|
|
10441
|
+
*
|
|
10442
|
+
* @param localPoint Point in cuboid-local space.
|
|
10443
|
+
* @param center Cuboid center in scene space.
|
|
10444
|
+
* @param rotationX Cuboid pitch in radians.
|
|
10445
|
+
* @param rotationY Cuboid yaw in radians.
|
|
10446
|
+
* @returns Transformed scene-space point.
|
|
10447
|
+
*
|
|
10448
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10449
|
+
*/
|
|
10450
|
+
function transformScenePoint(localPoint, center, rotationX, rotationY) {
|
|
10451
|
+
const yawedPoint = rotatePointAroundY(localPoint, rotationY);
|
|
10452
|
+
const pitchedPoint = rotatePointAroundX(yawedPoint, rotationX);
|
|
10453
|
+
return {
|
|
10454
|
+
x: center.x + pitchedPoint.x,
|
|
10455
|
+
y: center.y + pitchedPoint.y,
|
|
10456
|
+
z: center.z + pitchedPoint.z,
|
|
10457
|
+
};
|
|
10458
|
+
}
|
|
10459
|
+
/**
|
|
10460
|
+
* Rotates one point around the local Y axis.
|
|
10461
|
+
*
|
|
10462
|
+
* @param point Source point.
|
|
10463
|
+
* @param angle Rotation angle in radians.
|
|
10464
|
+
* @returns Rotated point.
|
|
10465
|
+
*
|
|
10466
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10467
|
+
*/
|
|
10468
|
+
function rotatePointAroundY(point, angle) {
|
|
10469
|
+
const cosine = Math.cos(angle);
|
|
10470
|
+
const sine = Math.sin(angle);
|
|
10471
|
+
return {
|
|
10472
|
+
x: point.x * cosine + point.z * sine,
|
|
10473
|
+
y: point.y,
|
|
10474
|
+
z: -point.x * sine + point.z * cosine,
|
|
10475
|
+
};
|
|
10476
|
+
}
|
|
10477
|
+
/**
|
|
10478
|
+
* Rotates one point around the local X axis.
|
|
10479
|
+
*
|
|
10480
|
+
* @param point Source point.
|
|
10481
|
+
* @param angle Rotation angle in radians.
|
|
10482
|
+
* @returns Rotated point.
|
|
10483
|
+
*
|
|
10484
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10485
|
+
*/
|
|
10486
|
+
function rotatePointAroundX(point, angle) {
|
|
10487
|
+
const cosine = Math.cos(angle);
|
|
10488
|
+
const sine = Math.sin(angle);
|
|
10489
|
+
return {
|
|
10490
|
+
x: point.x,
|
|
10491
|
+
y: point.y * cosine - point.z * sine,
|
|
10492
|
+
z: point.y * sine + point.z * cosine,
|
|
10493
|
+
};
|
|
10494
|
+
}
|
|
10495
|
+
/**
|
|
10496
|
+
* Subtracts one 3D point from another.
|
|
10497
|
+
*
|
|
10498
|
+
* @param leftPoint Left point.
|
|
10499
|
+
* @param rightPoint Right point.
|
|
10500
|
+
* @returns Difference vector.
|
|
10501
|
+
*
|
|
10502
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10503
|
+
*/
|
|
10504
|
+
function subtractPoint3D(leftPoint, rightPoint) {
|
|
10505
|
+
return {
|
|
10506
|
+
x: leftPoint.x - rightPoint.x,
|
|
10507
|
+
y: leftPoint.y - rightPoint.y,
|
|
10508
|
+
z: leftPoint.z - rightPoint.z,
|
|
10509
|
+
};
|
|
10510
|
+
}
|
|
10511
|
+
/**
|
|
10512
|
+
* Computes the 3D cross product of two vectors.
|
|
10513
|
+
*
|
|
10514
|
+
* @param leftVector Left vector.
|
|
10515
|
+
* @param rightVector Right vector.
|
|
10516
|
+
* @returns Cross product.
|
|
10517
|
+
*
|
|
10518
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10519
|
+
*/
|
|
10520
|
+
function crossProduct3D(leftVector, rightVector) {
|
|
10521
|
+
return {
|
|
10522
|
+
x: leftVector.y * rightVector.z - leftVector.z * rightVector.y,
|
|
10523
|
+
y: leftVector.z * rightVector.x - leftVector.x * rightVector.z,
|
|
10524
|
+
z: leftVector.x * rightVector.y - leftVector.y * rightVector.x,
|
|
10525
|
+
};
|
|
10526
|
+
}
|
|
10527
|
+
/**
|
|
10528
|
+
* Computes the 3D dot product of two vectors.
|
|
10529
|
+
*
|
|
10530
|
+
* @param leftVector Left vector.
|
|
10531
|
+
* @param rightVector Right vector.
|
|
10532
|
+
* @returns Dot product.
|
|
10533
|
+
*
|
|
10534
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10535
|
+
*/
|
|
10536
|
+
function dotProduct3D(leftVector, rightVector) {
|
|
10537
|
+
return leftVector.x * rightVector.x + leftVector.y * rightVector.y + leftVector.z * rightVector.z;
|
|
10538
|
+
}
|
|
10539
|
+
/**
|
|
10540
|
+
* Normalizes one 3D vector while keeping zero vectors stable.
|
|
10541
|
+
*
|
|
10542
|
+
* @param vector Source vector.
|
|
10543
|
+
* @returns Normalized vector.
|
|
10544
|
+
*
|
|
10545
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10546
|
+
*/
|
|
10547
|
+
function normalizeVector3(vector) {
|
|
10548
|
+
const length = Math.hypot(vector.x, vector.y, vector.z);
|
|
10549
|
+
if (length === 0) {
|
|
10550
|
+
return vector;
|
|
10085
10551
|
}
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10552
|
+
return {
|
|
10553
|
+
x: vector.x / length,
|
|
10554
|
+
y: vector.y / length,
|
|
10555
|
+
z: vector.z / length,
|
|
10556
|
+
};
|
|
10557
|
+
}
|
|
10558
|
+
/**
|
|
10559
|
+
* Clamps one number into the provided range.
|
|
10560
|
+
*
|
|
10561
|
+
* @param value Input value.
|
|
10562
|
+
* @param minimumValue Inclusive lower bound.
|
|
10563
|
+
* @param maximumValue Inclusive upper bound.
|
|
10564
|
+
* @returns Clamped value.
|
|
10565
|
+
*
|
|
10566
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10567
|
+
*/
|
|
10568
|
+
function clampNumber$1(value, minimumValue, maximumValue) {
|
|
10569
|
+
return Math.min(maximumValue, Math.max(minimumValue, value));
|
|
10570
|
+
}
|
|
10571
|
+
/**
|
|
10572
|
+
* Measures the perimeter of one projected quad.
|
|
10573
|
+
*
|
|
10574
|
+
* @param corners Quad corners.
|
|
10575
|
+
* @returns Perimeter length.
|
|
10576
|
+
*
|
|
10577
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
10578
|
+
*/
|
|
10579
|
+
function getProjectedQuadPerimeter(corners) {
|
|
10580
|
+
let perimeter = 0;
|
|
10581
|
+
for (let cornerIndex = 0; cornerIndex < corners.length; cornerIndex++) {
|
|
10582
|
+
const currentCorner = corners[cornerIndex];
|
|
10583
|
+
const nextCorner = corners[(cornerIndex + 1) % corners.length];
|
|
10584
|
+
perimeter += Math.hypot(nextCorner.x - currentCorner.x, nextCorner.y - currentCorner.y);
|
|
10089
10585
|
}
|
|
10090
|
-
|
|
10091
|
-
texture[4][6] = palette.accent;
|
|
10092
|
-
texture[5][2] = palette.highlight;
|
|
10093
|
-
texture[5][5] = palette.highlight;
|
|
10094
|
-
return texture;
|
|
10586
|
+
return perimeter;
|
|
10095
10587
|
}
|
|
10096
10588
|
|
|
10097
10589
|
/* eslint-disable no-magic-numbers */
|
|
@@ -11696,6 +12188,7 @@
|
|
|
11696
12188
|
octopus3AvatarVisual,
|
|
11697
12189
|
asciiOctopusAvatarVisual,
|
|
11698
12190
|
minecraftAvatarVisual,
|
|
12191
|
+
minecraft2AvatarVisual,
|
|
11699
12192
|
fractalAvatarVisual,
|
|
11700
12193
|
orbAvatarVisual,
|
|
11701
12194
|
];
|
|
@@ -12998,7 +13491,11 @@
|
|
|
12998
13491
|
// Create new system message with persona at the beginning
|
|
12999
13492
|
// Format: "You are {agentName}\n{personaContent}"
|
|
13000
13493
|
// The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
|
|
13001
|
-
const personaSection =
|
|
13494
|
+
const personaSection = spacetrim.spaceTrim((block) => `
|
|
13495
|
+
# PERSONA
|
|
13496
|
+
You are ${agentName}
|
|
13497
|
+
${block(mergedPersonaContent)}
|
|
13498
|
+
`);
|
|
13002
13499
|
const newSystemMessage = cleanedMessage ? `${personaSection}\n\n${cleanedMessage}` : personaSection;
|
|
13003
13500
|
return {
|
|
13004
13501
|
...requirements,
|
|
@@ -13900,7 +14397,10 @@
|
|
|
13900
14397
|
*/
|
|
13901
14398
|
function buildTeamToolDescription(entry) {
|
|
13902
14399
|
const detailLines = collectTeamEntryDetails(entry).map(({ label, content }) => `${label}: ${content}`);
|
|
13903
|
-
return
|
|
14400
|
+
return spacetrim.spaceTrim((block) => `
|
|
14401
|
+
Consult teammate ${entry.teammate.label}
|
|
14402
|
+
${block(detailLines.join('\n'))}
|
|
14403
|
+
`);
|
|
13904
14404
|
}
|
|
13905
14405
|
/**
|
|
13906
14406
|
* Collects structured teammate details that should stay visible to the model.
|
|
@@ -19416,7 +19916,10 @@
|
|
|
19416
19916
|
if (hiddenCount > 0) {
|
|
19417
19917
|
summaryRows.push(`...and ${hiddenCount} more.`);
|
|
19418
19918
|
}
|
|
19419
|
-
return
|
|
19919
|
+
return spacetrim.spaceTrim((block) => `
|
|
19920
|
+
Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
|
|
19921
|
+
${block(summaryRows.join('\n'))}
|
|
19922
|
+
`);
|
|
19420
19923
|
}
|
|
19421
19924
|
/**
|
|
19422
19925
|
* Formats one timeout row for assistant-visible timeout listings.
|
|
@@ -28302,11 +28805,11 @@
|
|
|
28302
28805
|
if (attachments.length === 0) {
|
|
28303
28806
|
return '';
|
|
28304
28807
|
}
|
|
28305
|
-
return
|
|
28306
|
-
CHAT_ATTACHMENTS_HEADING
|
|
28307
|
-
|
|
28308
|
-
CHAT_ATTACHMENTS_INSTRUCTION
|
|
28309
|
-
|
|
28808
|
+
return spacetrim.spaceTrim((block) => `
|
|
28809
|
+
${CHAT_ATTACHMENTS_HEADING}
|
|
28810
|
+
${block(attachments.map((attachment) => formatChatAttachmentLine(attachment)).join('\n'))}
|
|
28811
|
+
${CHAT_ATTACHMENTS_INSTRUCTION}
|
|
28812
|
+
`);
|
|
28310
28813
|
}
|
|
28311
28814
|
|
|
28312
28815
|
/**
|
|
@@ -28547,24 +29050,24 @@
|
|
|
28547
29050
|
: ''}`
|
|
28548
29051
|
: null;
|
|
28549
29052
|
const warningsLine = contentResolution.warnings.length > 0 ? `Warnings: ${contentResolution.warnings.join(' | ')}` : null;
|
|
28550
|
-
|
|
29053
|
+
const metadataLines = [decodingLine, warningsLine].filter((line) => Boolean(line)).join('\n');
|
|
29054
|
+
const resolvedContent = contentResolution.content;
|
|
29055
|
+
if (!resolvedContent) {
|
|
28551
29056
|
const reason = contentResolution.reason || 'content unavailable';
|
|
28552
|
-
return
|
|
28553
|
-
.
|
|
28554
|
-
|
|
29057
|
+
return spacetrim.spaceTrim((block) => `
|
|
29058
|
+
- ${attachmentLabel}: ${reason}. URL: ${contentResolution.attachment.url}
|
|
29059
|
+
${block(metadataLines)}
|
|
29060
|
+
`);
|
|
28555
29061
|
}
|
|
28556
29062
|
const truncatedLabel = contentResolution.isTruncated ? ' [truncated]' : '';
|
|
28557
|
-
return
|
|
28558
|
-
|
|
28559
|
-
|
|
28560
|
-
|
|
28561
|
-
|
|
28562
|
-
|
|
28563
|
-
|
|
28564
|
-
|
|
28565
|
-
]
|
|
28566
|
-
.filter(Boolean)
|
|
28567
|
-
.join('\n');
|
|
29063
|
+
return spacetrim.spaceTrim((block) => `
|
|
29064
|
+
File: ${attachmentLabel}${truncatedLabel}
|
|
29065
|
+
URL: ${contentResolution.attachment.url}
|
|
29066
|
+
${block(metadataLines)}
|
|
29067
|
+
\`\`\`text
|
|
29068
|
+
${block(resolvedContent)}
|
|
29069
|
+
\`\`\`
|
|
29070
|
+
`);
|
|
28568
29071
|
}
|
|
28569
29072
|
/**
|
|
28570
29073
|
* Formats inline attachment-content context section for the model.
|
|
@@ -28578,11 +29081,14 @@
|
|
|
28578
29081
|
if (resolvedContents.length === 0) {
|
|
28579
29082
|
return '';
|
|
28580
29083
|
}
|
|
28581
|
-
return
|
|
28582
|
-
CHAT_ATTACHMENT_CONTENT_HEADING
|
|
28583
|
-
CHAT_ATTACHMENT_CONTENT_INSTRUCTION
|
|
28584
|
-
|
|
28585
|
-
|
|
29084
|
+
return spacetrim.spaceTrim((block) => `
|
|
29085
|
+
${CHAT_ATTACHMENT_CONTENT_HEADING}
|
|
29086
|
+
${CHAT_ATTACHMENT_CONTENT_INSTRUCTION}
|
|
29087
|
+
|
|
29088
|
+
${block(resolvedContents
|
|
29089
|
+
.map((resolvedContent) => formatResolvedChatAttachmentContent(resolvedContent))
|
|
29090
|
+
.join('\n\n'))}
|
|
29091
|
+
`);
|
|
28586
29092
|
}
|
|
28587
29093
|
|
|
28588
29094
|
/**
|
|
@@ -29727,9 +30233,11 @@
|
|
|
29727
30233
|
* Creates the retry-history error message shared by all OpenAI-compatible model variants.
|
|
29728
30234
|
*/
|
|
29729
30235
|
createAttemptHistoryError(finalErrorMessage) {
|
|
29730
|
-
return new PipelineExecutionError(
|
|
29731
|
-
|
|
29732
|
-
|
|
30236
|
+
return new PipelineExecutionError(spacetrim.spaceTrim((block) => `
|
|
30237
|
+
All attempts failed. Attempt history:
|
|
30238
|
+
${block(formatUnsupportedParameterAttemptHistory(this.attemptStack))}
|
|
30239
|
+
Final error: ${finalErrorMessage}
|
|
30240
|
+
`));
|
|
29733
30241
|
}
|
|
29734
30242
|
}
|
|
29735
30243
|
|
|
@@ -32323,7 +32831,7 @@
|
|
|
32323
32831
|
});
|
|
32324
32832
|
}
|
|
32325
32833
|
let vectorStoreId = cachedVectorStoreId;
|
|
32326
|
-
if (
|
|
32834
|
+
if (!vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
32327
32835
|
const vectorStoreResult = await this.createVectorStoreWithKnowledgeSources({
|
|
32328
32836
|
client: await this.getClient(),
|
|
32329
32837
|
name,
|
|
@@ -32332,19 +32840,13 @@
|
|
|
32332
32840
|
});
|
|
32333
32841
|
vectorStoreId = vectorStoreResult.vectorStoreId;
|
|
32334
32842
|
}
|
|
32335
|
-
else if (
|
|
32843
|
+
else if (vectorStoreId && this.options.isVerbose) {
|
|
32336
32844
|
console.info('[🤰]', 'Using cached vector store for AgentKit agent', {
|
|
32337
32845
|
name,
|
|
32338
32846
|
vectorStoreId,
|
|
32339
32847
|
});
|
|
32340
32848
|
}
|
|
32341
|
-
|
|
32342
|
-
vectorStoreId = undefined;
|
|
32343
|
-
}
|
|
32344
|
-
const agentKitTools = this.buildAgentKitTools({
|
|
32345
|
-
tools,
|
|
32346
|
-
vectorStoreId,
|
|
32347
|
-
});
|
|
32849
|
+
const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
|
|
32348
32850
|
const openAiAgentKitAgent = new agents.Agent({
|
|
32349
32851
|
name,
|
|
32350
32852
|
model: this.agentKitModelName,
|
|
@@ -32363,7 +32865,7 @@
|
|
|
32363
32865
|
name,
|
|
32364
32866
|
model: this.agentKitModelName,
|
|
32365
32867
|
toolCount: agentKitTools.length,
|
|
32366
|
-
hasVectorStore:
|
|
32868
|
+
hasVectorStore: Boolean(vectorStoreId),
|
|
32367
32869
|
});
|
|
32368
32870
|
}
|
|
32369
32871
|
return preparedAgent;
|
|
@@ -32862,12 +33364,6 @@
|
|
|
32862
33364
|
get agentKitOptions() {
|
|
32863
33365
|
return this.options;
|
|
32864
33366
|
}
|
|
32865
|
-
/**
|
|
32866
|
-
* Returns true when hosted OpenAI vector-store search should back `knowledgeSources`.
|
|
32867
|
-
*/
|
|
32868
|
-
get isNativeKnowledgeSearchEnabled() {
|
|
32869
|
-
return this.agentKitOptions.isNativeKnowledgeSearchEnabled !== false;
|
|
32870
|
-
}
|
|
32871
33367
|
/**
|
|
32872
33368
|
* Discriminant for type guards.
|
|
32873
33369
|
*/
|