@promptbook/core 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 +1567 -297
- 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 +1 -2
- package/umd/index.umd.js +1570 -300
- 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('crypto-js'), require('crypto-js/enc-hex'), require('spacetrim'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/sha256'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'crypto-js', 'crypto-js/enc-hex', 'spacetrim', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/sha256', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.cryptoJs, global.hexEncoder, global.spacetrim, global.crypto, global.rxjs, global.waitasecond, global.sha256, global.
|
|
5
|
-
})(this, (function (exports, cryptoJs, hexEncoder, spacetrim, crypto, rxjs, waitasecond, sha256,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('crypto-js'), require('crypto-js/enc-hex'), require('spacetrim'), require('path'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse'), require('moment'), require('colors'), require('@openai/agents'), require('bottleneck'), require('openai')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'crypto-js', 'crypto-js/enc-hex', 'spacetrim', 'path', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse', 'moment', 'colors', '@openai/agents', 'bottleneck', 'openai'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.cryptoJs, global.hexEncoder, global.spacetrim, global.path, global.crypto, global.rxjs, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse, global.moment, global.colors, global.agents, global.Bottleneck, global.OpenAI));
|
|
5
|
+
})(this, (function (exports, cryptoJs, hexEncoder, spacetrim, path, crypto, rxjs, waitasecond, sha256, mimeTypes, papaparse, moment, colors, agents, Bottleneck, 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.
|
|
@@ -1216,7 +1239,6 @@
|
|
|
1216
1239
|
*/
|
|
1217
1240
|
const DEFAULT_AGENTS_DIRNAME = './agents';
|
|
1218
1241
|
// <- TODO: [🕝] Make also `AGENTS_DIRNAME_ALTERNATIVES`
|
|
1219
|
-
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
1220
1242
|
/**
|
|
1221
1243
|
* Where to store the temporary downloads
|
|
1222
1244
|
*
|
|
@@ -1224,7 +1246,7 @@
|
|
|
1224
1246
|
*
|
|
1225
1247
|
* @public exported from `@promptbook/core`
|
|
1226
1248
|
*/
|
|
1227
|
-
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = '
|
|
1249
|
+
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = getPromptbookTempPath('download-cache');
|
|
1228
1250
|
/**
|
|
1229
1251
|
* Where to store the cache of executions for promptbook CLI
|
|
1230
1252
|
*
|
|
@@ -1232,7 +1254,7 @@
|
|
|
1232
1254
|
*
|
|
1233
1255
|
* @public exported from `@promptbook/core`
|
|
1234
1256
|
*/
|
|
1235
|
-
const DEFAULT_EXECUTION_CACHE_DIRNAME = '
|
|
1257
|
+
const DEFAULT_EXECUTION_CACHE_DIRNAME = getPromptbookTempPath('execution-cache');
|
|
1236
1258
|
/**
|
|
1237
1259
|
* Where to store the scrape cache
|
|
1238
1260
|
*
|
|
@@ -1240,7 +1262,7 @@
|
|
|
1240
1262
|
*
|
|
1241
1263
|
* @public exported from `@promptbook/core`
|
|
1242
1264
|
*/
|
|
1243
|
-
const DEFAULT_SCRAPE_CACHE_DIRNAME = '
|
|
1265
|
+
const DEFAULT_SCRAPE_CACHE_DIRNAME = getPromptbookTempPath('scrape-cache');
|
|
1244
1266
|
/**
|
|
1245
1267
|
* Id of application for the CLI when using remote server
|
|
1246
1268
|
*
|
|
@@ -12087,18 +12109,6 @@
|
|
|
12087
12109
|
}
|
|
12088
12110
|
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12089
12111
|
|
|
12090
|
-
/**
|
|
12091
|
-
* Name of the tool used by agents to search configured `KNOWLEDGE` sources.
|
|
12092
|
-
*
|
|
12093
|
-
* @public exported from `@promptbook/core`
|
|
12094
|
-
*/
|
|
12095
|
-
const KNOWLEDGE_SEARCH_TOOL_NAME = 'knowledge_search';
|
|
12096
|
-
/**
|
|
12097
|
-
* Title of the system-message section generated for `KNOWLEDGE` commitments.
|
|
12098
|
-
*
|
|
12099
|
-
* @private constant of `KnowledgeCommitmentDefinition`
|
|
12100
|
-
*/
|
|
12101
|
-
const KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE = 'Knowledge Search';
|
|
12102
12112
|
/**
|
|
12103
12113
|
* KNOWLEDGE commitment definition
|
|
12104
12114
|
*
|
|
@@ -12220,17 +12230,9 @@
|
|
|
12220
12230
|
knowledgeInfoEntries.push(`Knowledge Source Inline: ${inlineSource.filename} (derived from inline content and processed for retrieval during chat)`);
|
|
12221
12231
|
}
|
|
12222
12232
|
if (knowledgeInfoEntries.length === 0) {
|
|
12223
|
-
return
|
|
12233
|
+
return nextRequirements;
|
|
12224
12234
|
}
|
|
12225
|
-
return
|
|
12226
|
-
}
|
|
12227
|
-
/**
|
|
12228
|
-
* Gets human-readable titles for tool functions provided by this commitment.
|
|
12229
|
-
*/
|
|
12230
|
-
getToolTitles() {
|
|
12231
|
-
return {
|
|
12232
|
-
[KNOWLEDGE_SEARCH_TOOL_NAME]: 'Knowledge search',
|
|
12233
|
-
};
|
|
12235
|
+
return this.appendToSystemMessage(nextRequirements, knowledgeInfoEntries.join('\n'), '\n\n');
|
|
12234
12236
|
}
|
|
12235
12237
|
}
|
|
12236
12238
|
/**
|
|
@@ -12244,128 +12246,6 @@
|
|
|
12244
12246
|
const significantText = contentWithoutUrls.replace(/[\s.,!?;:'"`()[\]{}<>/-]+/g, '');
|
|
12245
12247
|
return significantText.length > 0;
|
|
12246
12248
|
}
|
|
12247
|
-
/**
|
|
12248
|
-
* Adds the shared `knowledge_search` tool definition and the consolidated system-message section.
|
|
12249
|
-
*
|
|
12250
|
-
* @param requirements - Requirements after one `KNOWLEDGE` commitment was applied.
|
|
12251
|
-
* @returns Requirements with the knowledge search instructions and tool definition.
|
|
12252
|
-
*
|
|
12253
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12254
|
-
*/
|
|
12255
|
-
function addKnowledgeSearchToolAndSystemSection(requirements) {
|
|
12256
|
-
const nextRequirements = addKnowledgeSearchTool(requirements);
|
|
12257
|
-
const section = createKnowledgeSearchSystemSection(nextRequirements);
|
|
12258
|
-
const sectionHeader = `## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}`;
|
|
12259
|
-
if (nextRequirements.systemMessage.includes(sectionHeader)) {
|
|
12260
|
-
return {
|
|
12261
|
-
...nextRequirements,
|
|
12262
|
-
systemMessage: nextRequirements.systemMessage.replace(new RegExp(`## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?(?=\\n\\n##|$)`), section),
|
|
12263
|
-
};
|
|
12264
|
-
}
|
|
12265
|
-
return {
|
|
12266
|
-
...nextRequirements,
|
|
12267
|
-
systemMessage: nextRequirements.systemMessage.trim()
|
|
12268
|
-
? `${nextRequirements.systemMessage}\n\n${section}`
|
|
12269
|
-
: section,
|
|
12270
|
-
};
|
|
12271
|
-
}
|
|
12272
|
-
/**
|
|
12273
|
-
* Adds the `knowledge_search` model tool when it is not already present.
|
|
12274
|
-
*
|
|
12275
|
-
* @param requirements - Current model requirements.
|
|
12276
|
-
* @returns Requirements with the tool definition available to the model.
|
|
12277
|
-
*
|
|
12278
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12279
|
-
*/
|
|
12280
|
-
function addKnowledgeSearchTool(requirements) {
|
|
12281
|
-
const existingTools = requirements.tools || [];
|
|
12282
|
-
if (existingTools.some((tool) => tool.name === KNOWLEDGE_SEARCH_TOOL_NAME)) {
|
|
12283
|
-
return requirements;
|
|
12284
|
-
}
|
|
12285
|
-
return {
|
|
12286
|
-
...requirements,
|
|
12287
|
-
tools: [
|
|
12288
|
-
...existingTools,
|
|
12289
|
-
{
|
|
12290
|
-
name: KNOWLEDGE_SEARCH_TOOL_NAME,
|
|
12291
|
-
description: spacetrim.spaceTrim(`
|
|
12292
|
-
Search the agent's configured knowledge sources and return relevant excerpts with citation ids.
|
|
12293
|
-
Use this before answering questions that may depend on the agent's KNOWLEDGE commitments.
|
|
12294
|
-
`),
|
|
12295
|
-
parameters: {
|
|
12296
|
-
type: 'object',
|
|
12297
|
-
properties: {
|
|
12298
|
-
query: {
|
|
12299
|
-
type: 'string',
|
|
12300
|
-
description: 'The natural-language search query for the knowledge base.',
|
|
12301
|
-
},
|
|
12302
|
-
limit: {
|
|
12303
|
-
type: 'integer',
|
|
12304
|
-
description: 'Maximum number of matching source excerpts to return.',
|
|
12305
|
-
},
|
|
12306
|
-
},
|
|
12307
|
-
required: ['query'],
|
|
12308
|
-
},
|
|
12309
|
-
},
|
|
12310
|
-
],
|
|
12311
|
-
};
|
|
12312
|
-
}
|
|
12313
|
-
/**
|
|
12314
|
-
* Creates the model-facing system-message section for knowledge search.
|
|
12315
|
-
*
|
|
12316
|
-
* @param requirements - Current model requirements.
|
|
12317
|
-
* @returns Markdown system-message section.
|
|
12318
|
-
*
|
|
12319
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12320
|
-
*/
|
|
12321
|
-
function createKnowledgeSearchSystemSection(requirements) {
|
|
12322
|
-
const sourceEntries = createKnowledgeSourceSystemEntries(requirements);
|
|
12323
|
-
const sourceList = sourceEntries.length > 0 ? sourceEntries.map((entry) => `- ${entry}`).join('\n') : '- None';
|
|
12324
|
-
return spacetrim.spaceTrim(`
|
|
12325
|
-
## ${KNOWLEDGE_SEARCH_SYSTEM_SECTION_TITLE}
|
|
12326
|
-
|
|
12327
|
-
- Use \`${KNOWLEDGE_SEARCH_TOOL_NAME}\` to search the configured knowledge sources before answering questions that depend on this agent's knowledge base.
|
|
12328
|
-
- Base source-backed factual answers on the returned excerpts.
|
|
12329
|
-
- When you use a returned excerpt, include its citation marker in the answer body, for example \`[0:0]\`.
|
|
12330
|
-
- If the search returns no relevant information, say that the knowledge base did not contain the answer instead of inventing it.
|
|
12331
|
-
|
|
12332
|
-
Configured knowledge sources:
|
|
12333
|
-
${sourceList}
|
|
12334
|
-
`);
|
|
12335
|
-
}
|
|
12336
|
-
/**
|
|
12337
|
-
* Builds a stable list of configured knowledge sources for system-message diagnostics.
|
|
12338
|
-
*
|
|
12339
|
-
* @param requirements - Current model requirements.
|
|
12340
|
-
* @returns Human-readable source entries.
|
|
12341
|
-
*
|
|
12342
|
-
* @private internal utility of `KnowledgeCommitmentDefinition`
|
|
12343
|
-
*/
|
|
12344
|
-
function createKnowledgeSourceSystemEntries(requirements) {
|
|
12345
|
-
var _a;
|
|
12346
|
-
const entries = [];
|
|
12347
|
-
const seenEntries = new Set();
|
|
12348
|
-
for (const source of requirements.knowledgeSources || []) {
|
|
12349
|
-
const entry = `Source URL: ${source} (processed for retrieval during chat)`;
|
|
12350
|
-
if (seenEntries.has(entry)) {
|
|
12351
|
-
continue;
|
|
12352
|
-
}
|
|
12353
|
-
seenEntries.add(entry);
|
|
12354
|
-
entries.push(entry);
|
|
12355
|
-
}
|
|
12356
|
-
const inlineSources = (((_a = requirements._metadata) === null || _a === void 0 ? void 0 : _a.inlineKnowledgeSources) || [])
|
|
12357
|
-
.map((source) => source.filename)
|
|
12358
|
-
.filter(Boolean);
|
|
12359
|
-
for (const filename of inlineSources) {
|
|
12360
|
-
const entry = `Knowledge Source Inline: ${filename} (Inline source: processed for retrieval during chat)`;
|
|
12361
|
-
if (seenEntries.has(entry)) {
|
|
12362
|
-
continue;
|
|
12363
|
-
}
|
|
12364
|
-
seenEntries.add(entry);
|
|
12365
|
-
entries.push(entry);
|
|
12366
|
-
}
|
|
12367
|
-
return entries;
|
|
12368
|
-
}
|
|
12369
12249
|
|
|
12370
12250
|
/**
|
|
12371
12251
|
* LANGUAGE commitment definition
|
|
@@ -14998,6 +14878,177 @@
|
|
|
14998
14878
|
context.restore();
|
|
14999
14879
|
}
|
|
15000
14880
|
|
|
14881
|
+
/* eslint-disable no-magic-numbers */
|
|
14882
|
+
/**
|
|
14883
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style head cuboid.
|
|
14884
|
+
*
|
|
14885
|
+
* @param random Seeded random generator.
|
|
14886
|
+
* @param palette Derived avatar palette.
|
|
14887
|
+
* @param hasHeadband Whether the generated avatar should include a colored headband.
|
|
14888
|
+
* @returns Head cuboid textures.
|
|
14889
|
+
*
|
|
14890
|
+
* @private helper of the Minecraft avatar visuals
|
|
14891
|
+
*/
|
|
14892
|
+
function createMinecraftHeadTextures(random, palette, hasHeadband) {
|
|
14893
|
+
const faceTexture = createMinecraftFaceTexture(random, palette, hasHeadband);
|
|
14894
|
+
const hairColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
14895
|
+
const skinColor = palette.highlight;
|
|
14896
|
+
const headbandColor = hasHeadband ? palette.accent : hairColor;
|
|
14897
|
+
const sideTexture = createFilledTexture(skinColor);
|
|
14898
|
+
const backTexture = createFilledTexture(skinColor);
|
|
14899
|
+
const topTexture = createFilledTexture(hairColor);
|
|
14900
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}cc`);
|
|
14901
|
+
fillTextureRect(sideTexture, 0, 0, 8, 3, hairColor);
|
|
14902
|
+
fillTextureRect(backTexture, 0, 0, 8, 5, hairColor);
|
|
14903
|
+
fillTextureRect(backTexture, 1, 5, 6, 1, hairColor);
|
|
14904
|
+
if (hasHeadband) {
|
|
14905
|
+
fillTextureRect(sideTexture, 0, 2, 8, 1, headbandColor);
|
|
14906
|
+
fillTextureRect(backTexture, 0, 2, 8, 1, headbandColor);
|
|
14907
|
+
fillTextureRect(topTexture, 0, 4, 8, 1, headbandColor);
|
|
14908
|
+
}
|
|
14909
|
+
sideTexture[4][4] = `${palette.shadow}99`;
|
|
14910
|
+
sideTexture[5][4] = `${palette.shadow}cc`;
|
|
14911
|
+
backTexture[6][2] = `${palette.shadow}99`;
|
|
14912
|
+
backTexture[6][5] = `${palette.shadow}99`;
|
|
14913
|
+
return {
|
|
14914
|
+
front: faceTexture,
|
|
14915
|
+
back: backTexture,
|
|
14916
|
+
left: sideTexture,
|
|
14917
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
14918
|
+
top: topTexture,
|
|
14919
|
+
bottom: bottomTexture,
|
|
14920
|
+
};
|
|
14921
|
+
}
|
|
14922
|
+
/**
|
|
14923
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style torso cuboid.
|
|
14924
|
+
*
|
|
14925
|
+
* @param random Seeded random generator.
|
|
14926
|
+
* @param palette Derived avatar palette.
|
|
14927
|
+
* @returns Torso cuboid textures.
|
|
14928
|
+
*
|
|
14929
|
+
* @private helper of the Minecraft avatar visuals
|
|
14930
|
+
*/
|
|
14931
|
+
function createMinecraftTorsoTextures(random, palette) {
|
|
14932
|
+
const frontTexture = createMinecraftShirtTexture(random, palette);
|
|
14933
|
+
const sideTexture = createFilledTexture(palette.primary);
|
|
14934
|
+
const backTexture = createFilledTexture(palette.primary);
|
|
14935
|
+
const topTexture = createFilledTexture(`${palette.highlight}dd`);
|
|
14936
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}dd`);
|
|
14937
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
14938
|
+
fillTextureRect(sideTexture, 0, 0, 8, 2, palette.shadow);
|
|
14939
|
+
fillTextureRect(backTexture, 0, 0, 8, 2, palette.shadow);
|
|
14940
|
+
fillTextureRect(backTexture, 3, 2, 2, 6, stripeColor);
|
|
14941
|
+
fillTextureRect(sideTexture, 4, 2, 1, 6, stripeColor);
|
|
14942
|
+
fillTextureRect(topTexture, 0, 0, 8, 2, palette.shadow);
|
|
14943
|
+
fillTextureRect(topTexture, 2, 2, 4, 4, stripeColor);
|
|
14944
|
+
return {
|
|
14945
|
+
front: frontTexture,
|
|
14946
|
+
back: backTexture,
|
|
14947
|
+
left: sideTexture,
|
|
14948
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
14949
|
+
top: topTexture,
|
|
14950
|
+
bottom: bottomTexture,
|
|
14951
|
+
};
|
|
14952
|
+
}
|
|
14953
|
+
/**
|
|
14954
|
+
* Mirrors one Minecraft texture horizontally.
|
|
14955
|
+
*
|
|
14956
|
+
* @param texture Source texture.
|
|
14957
|
+
* @returns Mirrored texture copy.
|
|
14958
|
+
*
|
|
14959
|
+
* @private helper of the Minecraft avatar visuals
|
|
14960
|
+
*/
|
|
14961
|
+
function mirrorMinecraftTexture(texture) {
|
|
14962
|
+
return texture.map((row) => [...row].reverse());
|
|
14963
|
+
}
|
|
14964
|
+
/**
|
|
14965
|
+
* Creates the front-face pixel texture for the cube head.
|
|
14966
|
+
*
|
|
14967
|
+
* @param random Seeded random generator.
|
|
14968
|
+
* @param palette Derived avatar palette.
|
|
14969
|
+
* @param hasHeadband Whether the avatar should render a headband row.
|
|
14970
|
+
* @returns 8x8 pixel texture.
|
|
14971
|
+
*
|
|
14972
|
+
* @private helper of the Minecraft avatar visuals
|
|
14973
|
+
*/
|
|
14974
|
+
function createMinecraftFaceTexture(random, palette, hasHeadband) {
|
|
14975
|
+
const texture = createFilledTexture(palette.highlight);
|
|
14976
|
+
const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
14977
|
+
const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
|
|
14978
|
+
fillTextureRect(texture, 0, 0, 8, 2, hairlineColor);
|
|
14979
|
+
texture[2][0] = hairlineColor;
|
|
14980
|
+
texture[2][7] = hairlineColor;
|
|
14981
|
+
texture[3][0] = hairlineColor;
|
|
14982
|
+
texture[3][7] = hairlineColor;
|
|
14983
|
+
if (hasHeadband) {
|
|
14984
|
+
fillTextureRect(texture, 0, 2, 8, 1, palette.accent);
|
|
14985
|
+
}
|
|
14986
|
+
texture[3][2] = palette.ink;
|
|
14987
|
+
texture[3][5] = palette.ink;
|
|
14988
|
+
texture[4][2] = '#ffffff';
|
|
14989
|
+
texture[4][5] = '#ffffff';
|
|
14990
|
+
texture[5][1] = cheekColor;
|
|
14991
|
+
texture[5][6] = cheekColor;
|
|
14992
|
+
texture[5][3] = palette.shadow;
|
|
14993
|
+
texture[5][4] = palette.shadow;
|
|
14994
|
+
texture[6][3] = palette.shadow;
|
|
14995
|
+
texture[6][4] = palette.shadow;
|
|
14996
|
+
return texture;
|
|
14997
|
+
}
|
|
14998
|
+
/**
|
|
14999
|
+
* Creates the front-face pixel texture for the torso.
|
|
15000
|
+
*
|
|
15001
|
+
* @param random Seeded random generator.
|
|
15002
|
+
* @param palette Derived avatar palette.
|
|
15003
|
+
* @returns 8x8 torso texture.
|
|
15004
|
+
*
|
|
15005
|
+
* @private helper of the Minecraft avatar visuals
|
|
15006
|
+
*/
|
|
15007
|
+
function createMinecraftShirtTexture(random, palette) {
|
|
15008
|
+
const texture = createFilledTexture(palette.primary);
|
|
15009
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
15010
|
+
fillTextureRect(texture, 0, 0, 8, 2, palette.shadow);
|
|
15011
|
+
for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
|
|
15012
|
+
texture[rowIndex][3] = stripeColor;
|
|
15013
|
+
texture[rowIndex][4] = stripeColor;
|
|
15014
|
+
}
|
|
15015
|
+
texture[4][1] = palette.accent;
|
|
15016
|
+
texture[4][6] = palette.accent;
|
|
15017
|
+
texture[5][2] = palette.highlight;
|
|
15018
|
+
texture[5][5] = palette.highlight;
|
|
15019
|
+
return texture;
|
|
15020
|
+
}
|
|
15021
|
+
/**
|
|
15022
|
+
* Creates one solid-color 8x8 Minecraft texture.
|
|
15023
|
+
*
|
|
15024
|
+
* @param color Fill color.
|
|
15025
|
+
* @returns Filled 8x8 texture.
|
|
15026
|
+
*
|
|
15027
|
+
* @private helper of the Minecraft avatar visuals
|
|
15028
|
+
*/
|
|
15029
|
+
function createFilledTexture(color) {
|
|
15030
|
+
return Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => color));
|
|
15031
|
+
}
|
|
15032
|
+
/**
|
|
15033
|
+
* Fills one rectangular area inside a mutable Minecraft texture.
|
|
15034
|
+
*
|
|
15035
|
+
* @param texture Mutable target texture.
|
|
15036
|
+
* @param x Left texture coordinate.
|
|
15037
|
+
* @param y Top texture coordinate.
|
|
15038
|
+
* @param width Rectangle width.
|
|
15039
|
+
* @param height Rectangle height.
|
|
15040
|
+
* @param color Fill color.
|
|
15041
|
+
*
|
|
15042
|
+
* @private helper of the Minecraft avatar visuals
|
|
15043
|
+
*/
|
|
15044
|
+
function fillTextureRect(texture, x, y, width, height, color) {
|
|
15045
|
+
for (let rowIndex = y; rowIndex < y + height; rowIndex++) {
|
|
15046
|
+
for (let columnIndex = x; columnIndex < x + width; columnIndex++) {
|
|
15047
|
+
texture[rowIndex][columnIndex] = color;
|
|
15048
|
+
}
|
|
15049
|
+
}
|
|
15050
|
+
}
|
|
15051
|
+
|
|
15001
15052
|
/* eslint-disable no-magic-numbers */
|
|
15002
15053
|
/**
|
|
15003
15054
|
* Minecraft-style 3D avatar visual.
|
|
@@ -15022,8 +15073,8 @@
|
|
|
15022
15073
|
const bodyX = size * 0.33;
|
|
15023
15074
|
const bodyY = headY + headSize * 0.96;
|
|
15024
15075
|
const hasHeadband = random() < 0.5;
|
|
15025
|
-
const
|
|
15026
|
-
const
|
|
15076
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft-face'), palette, hasHeadband);
|
|
15077
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft-shirt'), palette);
|
|
15027
15078
|
drawAvatarFrame(context, size, palette);
|
|
15028
15079
|
const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
|
|
15029
15080
|
spotlight.addColorStop(0, `${palette.highlight}66`);
|
|
@@ -15043,7 +15094,7 @@
|
|
|
15043
15094
|
width: bodyWidth,
|
|
15044
15095
|
height: bodyHeight,
|
|
15045
15096
|
depth: bodyDepth,
|
|
15046
|
-
frontTexture:
|
|
15097
|
+
frontTexture: torsoTextures.front,
|
|
15047
15098
|
topColor: `${palette.highlight}cc`,
|
|
15048
15099
|
sideColor: `${palette.secondary}dd`,
|
|
15049
15100
|
outlineColor: `${palette.shadow}aa`,
|
|
@@ -15054,7 +15105,7 @@
|
|
|
15054
15105
|
width: headSize,
|
|
15055
15106
|
height: headSize,
|
|
15056
15107
|
depth,
|
|
15057
|
-
frontTexture:
|
|
15108
|
+
frontTexture: headTextures.front,
|
|
15058
15109
|
topColor: `${palette.highlight}ee`,
|
|
15059
15110
|
sideColor: `${palette.secondary}ee`,
|
|
15060
15111
|
outlineColor: `${palette.shadow}cc`,
|
|
@@ -15119,72 +15170,505 @@
|
|
|
15119
15170
|
context.closePath();
|
|
15120
15171
|
context.stroke();
|
|
15121
15172
|
}
|
|
15173
|
+
|
|
15174
|
+
/* eslint-disable no-magic-numbers */
|
|
15122
15175
|
/**
|
|
15123
|
-
*
|
|
15176
|
+
* Fixed scene camera distance used for the proper-3D projection.
|
|
15124
15177
|
*
|
|
15125
|
-
* @
|
|
15178
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15179
|
+
*/
|
|
15180
|
+
const CAMERA_DISTANCE_RATIO = 1.4;
|
|
15181
|
+
/**
|
|
15182
|
+
* Shared light direction used to shade projected cuboid faces.
|
|
15183
|
+
*
|
|
15184
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15185
|
+
*/
|
|
15186
|
+
const LIGHT_DIRECTION = normalizeVector3({
|
|
15187
|
+
x: 0.4,
|
|
15188
|
+
y: -0.65,
|
|
15189
|
+
z: 0.92,
|
|
15190
|
+
});
|
|
15191
|
+
/**
|
|
15192
|
+
* Minecraft 3D 2 avatar visual.
|
|
15193
|
+
*
|
|
15194
|
+
* @private built-in avatar visual
|
|
15195
|
+
*/
|
|
15196
|
+
const minecraft2AvatarVisual = {
|
|
15197
|
+
id: 'minecraft2',
|
|
15198
|
+
title: 'Minecraft 3D 2',
|
|
15199
|
+
description: 'Proper 3D Minecraft-style portrait with textured cuboids and pointer-driven head turns.',
|
|
15200
|
+
isAnimated: true,
|
|
15201
|
+
supportsPointerTracking: true,
|
|
15202
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
15203
|
+
const spotlightY = size * 0.22;
|
|
15204
|
+
const headRandom = createRandom('minecraft2-head');
|
|
15205
|
+
const hasHeadband = headRandom() < 0.5;
|
|
15206
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft2-head-textures'), palette, hasHeadband);
|
|
15207
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft2-body-textures'), palette);
|
|
15208
|
+
const bob = Math.sin(timeMs / 880) * size * 0.014;
|
|
15209
|
+
const bodyYaw = -0.24 + Math.sin(timeMs / 2300) * 0.06 + interaction.bodyOffsetX * 0.16;
|
|
15210
|
+
const bodyPitch = -0.12 + Math.cos(timeMs / 2800) * 0.02 - interaction.bodyOffsetY * 0.06;
|
|
15211
|
+
const headYaw = -0.18 + Math.sin(timeMs / 1900 + 0.6) * 0.05 + interaction.gazeX * 0.62;
|
|
15212
|
+
const headPitch = -0.12 + Math.cos(timeMs / 2400 + 1.1) * 0.03 - interaction.gazeY * 0.38;
|
|
15213
|
+
const sceneCenterX = size * 0.5;
|
|
15214
|
+
const sceneCenterY = size * 0.57;
|
|
15215
|
+
const bodyWidth = size * 0.225;
|
|
15216
|
+
const bodyHeight = size * 0.245;
|
|
15217
|
+
const bodyDepth = size * 0.145;
|
|
15218
|
+
const headSize = size * 0.24;
|
|
15219
|
+
const headLift = size * 0.205;
|
|
15220
|
+
const headForwardShift = interaction.intensity * size * 0.018;
|
|
15221
|
+
const sceneCuboids = [
|
|
15222
|
+
{
|
|
15223
|
+
center: {
|
|
15224
|
+
x: interaction.bodyOffsetX * size * 0.026,
|
|
15225
|
+
y: size * 0.05 + interaction.bodyOffsetY * size * 0.018 + bob,
|
|
15226
|
+
z: 0,
|
|
15227
|
+
},
|
|
15228
|
+
width: bodyWidth,
|
|
15229
|
+
height: bodyHeight,
|
|
15230
|
+
depth: bodyDepth,
|
|
15231
|
+
rotationX: bodyPitch,
|
|
15232
|
+
rotationY: bodyYaw,
|
|
15233
|
+
textures: torsoTextures,
|
|
15234
|
+
outlineColor: `${palette.shadow}cc`,
|
|
15235
|
+
},
|
|
15236
|
+
{
|
|
15237
|
+
center: {
|
|
15238
|
+
x: interaction.bodyOffsetX * size * 0.018 + interaction.gazeX * size * 0.016,
|
|
15239
|
+
y: -headLift + bob * 1.15,
|
|
15240
|
+
z: headForwardShift,
|
|
15241
|
+
},
|
|
15242
|
+
width: headSize,
|
|
15243
|
+
height: headSize,
|
|
15244
|
+
depth: headSize,
|
|
15245
|
+
rotationX: headPitch,
|
|
15246
|
+
rotationY: headYaw,
|
|
15247
|
+
textures: headTextures,
|
|
15248
|
+
outlineColor: `${palette.shadow}dd`,
|
|
15249
|
+
},
|
|
15250
|
+
];
|
|
15251
|
+
const visibleFaces = sceneCuboids
|
|
15252
|
+
.flatMap((cuboid) => resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY))
|
|
15253
|
+
.sort((firstFace, secondFace) => firstFace.averageDepth - secondFace.averageDepth);
|
|
15254
|
+
drawAvatarFrame(context, size, palette);
|
|
15255
|
+
drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs);
|
|
15256
|
+
drawMinecraftShadow(context, size, palette, interaction, timeMs);
|
|
15257
|
+
for (const visibleFace of visibleFaces) {
|
|
15258
|
+
drawTexturedProjectedFace(context, visibleFace);
|
|
15259
|
+
}
|
|
15260
|
+
},
|
|
15261
|
+
};
|
|
15262
|
+
/**
|
|
15263
|
+
* Draws the shared background atmosphere behind the Minecraft 3D 2 portrait.
|
|
15264
|
+
*
|
|
15265
|
+
* @param context Canvas 2D context.
|
|
15266
|
+
* @param size Canvas size in CSS pixels.
|
|
15126
15267
|
* @param palette Derived avatar palette.
|
|
15127
|
-
* @param
|
|
15128
|
-
* @
|
|
15268
|
+
* @param sceneCenterX Horizontal scene center.
|
|
15269
|
+
* @param spotlightY Vertical spotlight anchor.
|
|
15270
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
15271
|
+
* @param timeMs Current animation time in milliseconds.
|
|
15129
15272
|
*
|
|
15130
|
-
* @private helper of `
|
|
15273
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15131
15274
|
*/
|
|
15132
|
-
function
|
|
15133
|
-
const
|
|
15134
|
-
|
|
15135
|
-
|
|
15136
|
-
|
|
15137
|
-
|
|
15138
|
-
|
|
15275
|
+
function drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs) {
|
|
15276
|
+
const spotlightGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.08, spotlightY + interaction.gazeY * size * 0.05, size * 0.03, sceneCenterX, spotlightY, size * 0.52);
|
|
15277
|
+
spotlightGradient.addColorStop(0, `${palette.highlight}66`);
|
|
15278
|
+
spotlightGradient.addColorStop(0.42, `${palette.accent}1d`);
|
|
15279
|
+
spotlightGradient.addColorStop(1, `${palette.highlight}00`);
|
|
15280
|
+
context.fillStyle = spotlightGradient;
|
|
15281
|
+
context.fillRect(0, 0, size, size);
|
|
15282
|
+
const rimGradient = context.createLinearGradient(0, size * 0.14, 0, size * 0.92);
|
|
15283
|
+
rimGradient.addColorStop(0, `${palette.highlight}12`);
|
|
15284
|
+
rimGradient.addColorStop(0.55, `${palette.secondary}0a`);
|
|
15285
|
+
rimGradient.addColorStop(1, `${palette.shadow}00`);
|
|
15286
|
+
context.fillStyle = rimGradient;
|
|
15287
|
+
context.fillRect(0, 0, size, size);
|
|
15288
|
+
context.save();
|
|
15289
|
+
context.globalAlpha = 0.08 + interaction.intensity * 0.04;
|
|
15290
|
+
context.fillStyle = palette.highlight;
|
|
15291
|
+
context.beginPath();
|
|
15292
|
+
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);
|
|
15293
|
+
context.fill();
|
|
15294
|
+
context.restore();
|
|
15295
|
+
}
|
|
15296
|
+
/**
|
|
15297
|
+
* Draws the soft floor shadow used to anchor the cuboids in the frame.
|
|
15298
|
+
*
|
|
15299
|
+
* @param context Canvas 2D context.
|
|
15300
|
+
* @param size Canvas size in CSS pixels.
|
|
15301
|
+
* @param palette Derived avatar palette.
|
|
15302
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
15303
|
+
* @param timeMs Current animation time in milliseconds.
|
|
15304
|
+
*
|
|
15305
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15306
|
+
*/
|
|
15307
|
+
function drawMinecraftShadow(context, size, palette, interaction, timeMs) {
|
|
15308
|
+
context.save();
|
|
15309
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
15310
|
+
context.filter = `blur(${size * 0.02}px)`;
|
|
15311
|
+
context.beginPath();
|
|
15312
|
+
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);
|
|
15313
|
+
context.fill();
|
|
15314
|
+
context.restore();
|
|
15315
|
+
}
|
|
15316
|
+
/**
|
|
15317
|
+
* Resolves all visible projected faces for one scene cuboid.
|
|
15318
|
+
*
|
|
15319
|
+
* @param cuboid Scene cuboid definition.
|
|
15320
|
+
* @param size Canvas size in CSS pixels.
|
|
15321
|
+
* @param sceneCenterX Horizontal scene center.
|
|
15322
|
+
* @param sceneCenterY Vertical scene center.
|
|
15323
|
+
* @returns Visible faces sorted later by depth.
|
|
15324
|
+
*
|
|
15325
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15326
|
+
*/
|
|
15327
|
+
function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
|
|
15328
|
+
const halfWidth = cuboid.width / 2;
|
|
15329
|
+
const halfHeight = cuboid.height / 2;
|
|
15330
|
+
const halfDepth = cuboid.depth / 2;
|
|
15331
|
+
const faceDefinitions = [
|
|
15332
|
+
{
|
|
15333
|
+
texture: cuboid.textures.front,
|
|
15334
|
+
corners: [
|
|
15335
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
15336
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
15337
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
15338
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
15339
|
+
],
|
|
15340
|
+
},
|
|
15341
|
+
{
|
|
15342
|
+
texture: cuboid.textures.back,
|
|
15343
|
+
corners: [
|
|
15344
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15345
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15346
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
15347
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
15348
|
+
],
|
|
15349
|
+
},
|
|
15350
|
+
{
|
|
15351
|
+
texture: cuboid.textures.right,
|
|
15352
|
+
corners: [
|
|
15353
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
15354
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15355
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
15356
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
15357
|
+
],
|
|
15358
|
+
},
|
|
15359
|
+
{
|
|
15360
|
+
texture: cuboid.textures.left,
|
|
15361
|
+
corners: [
|
|
15362
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15363
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
15364
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
15365
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
15366
|
+
],
|
|
15367
|
+
},
|
|
15368
|
+
{
|
|
15369
|
+
texture: cuboid.textures.top,
|
|
15370
|
+
corners: [
|
|
15371
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15372
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
15373
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
15374
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
15375
|
+
],
|
|
15376
|
+
},
|
|
15377
|
+
{
|
|
15378
|
+
texture: cuboid.textures.bottom,
|
|
15379
|
+
corners: [
|
|
15380
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
15381
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
15382
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
15383
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
15384
|
+
],
|
|
15385
|
+
},
|
|
15386
|
+
];
|
|
15387
|
+
const visibleFaces = faceDefinitions
|
|
15388
|
+
.map((faceDefinition) => {
|
|
15389
|
+
const transformedCorners = faceDefinition.corners.map((corner) => transformScenePoint(corner, cuboid.center, cuboid.rotationX, cuboid.rotationY));
|
|
15390
|
+
const faceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
|
|
15391
|
+
if (faceNormal.z <= 0.02) {
|
|
15392
|
+
return null;
|
|
15139
15393
|
}
|
|
15394
|
+
const projectedCorners = transformedCorners.map((corner) => projectScenePoint(corner, size, sceneCenterX, sceneCenterY));
|
|
15395
|
+
return {
|
|
15396
|
+
corners: projectedCorners,
|
|
15397
|
+
texture: faceDefinition.texture,
|
|
15398
|
+
averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
|
|
15399
|
+
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION), -1, 1),
|
|
15400
|
+
outlineColor: cuboid.outlineColor,
|
|
15401
|
+
};
|
|
15402
|
+
});
|
|
15403
|
+
return visibleFaces.filter((visibleFace) => visibleFace !== null);
|
|
15404
|
+
}
|
|
15405
|
+
/**
|
|
15406
|
+
* Draws one projected textured face by tessellating its texture cells into quads.
|
|
15407
|
+
*
|
|
15408
|
+
* @param context Canvas 2D context.
|
|
15409
|
+
* @param face Visible projected face.
|
|
15410
|
+
*
|
|
15411
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15412
|
+
*/
|
|
15413
|
+
function drawTexturedProjectedFace(context, face) {
|
|
15414
|
+
var _a;
|
|
15415
|
+
const rows = face.texture.length;
|
|
15416
|
+
const columns = ((_a = face.texture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
15417
|
+
if (rows === 0 || columns === 0) {
|
|
15418
|
+
return;
|
|
15140
15419
|
}
|
|
15141
|
-
|
|
15142
|
-
|
|
15143
|
-
|
|
15144
|
-
|
|
15145
|
-
|
|
15146
|
-
|
|
15147
|
-
|
|
15420
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
15421
|
+
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
|
|
15422
|
+
const startX = columnIndex / columns;
|
|
15423
|
+
const endX = (columnIndex + 1) / columns;
|
|
15424
|
+
const startY = rowIndex / rows;
|
|
15425
|
+
const endY = (rowIndex + 1) / rows;
|
|
15426
|
+
drawProjectedQuad(context, [
|
|
15427
|
+
interpolateProjectedQuad(face.corners, startX, startY),
|
|
15428
|
+
interpolateProjectedQuad(face.corners, endX, startY),
|
|
15429
|
+
interpolateProjectedQuad(face.corners, endX, endY),
|
|
15430
|
+
interpolateProjectedQuad(face.corners, startX, endY),
|
|
15431
|
+
], face.texture[rowIndex][columnIndex]);
|
|
15148
15432
|
}
|
|
15149
15433
|
}
|
|
15150
|
-
|
|
15151
|
-
|
|
15152
|
-
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
|
|
15156
|
-
|
|
15157
|
-
|
|
15158
|
-
|
|
15159
|
-
|
|
15160
|
-
|
|
15434
|
+
if (face.lightIntensity > 0) {
|
|
15435
|
+
drawProjectedQuad(context, face.corners, `rgba(255, 255, 255, ${0.15 * face.lightIntensity})`);
|
|
15436
|
+
}
|
|
15437
|
+
else if (face.lightIntensity < 0) {
|
|
15438
|
+
drawProjectedQuad(context, face.corners, `rgba(0, 0, 0, ${0.22 * Math.abs(face.lightIntensity)})`);
|
|
15439
|
+
}
|
|
15440
|
+
context.save();
|
|
15441
|
+
context.beginPath();
|
|
15442
|
+
context.moveTo(face.corners[0].x, face.corners[0].y);
|
|
15443
|
+
for (let cornerIndex = 1; cornerIndex < face.corners.length; cornerIndex++) {
|
|
15444
|
+
context.lineTo(face.corners[cornerIndex].x, face.corners[cornerIndex].y);
|
|
15445
|
+
}
|
|
15446
|
+
context.closePath();
|
|
15447
|
+
context.strokeStyle = face.outlineColor;
|
|
15448
|
+
context.lineWidth = Math.max(1.1, getProjectedQuadPerimeter(face.corners) * 0.0045);
|
|
15449
|
+
context.lineJoin = 'round';
|
|
15450
|
+
context.stroke();
|
|
15451
|
+
context.restore();
|
|
15161
15452
|
}
|
|
15162
15453
|
/**
|
|
15163
|
-
*
|
|
15454
|
+
* Draws one filled projected quad.
|
|
15164
15455
|
*
|
|
15165
|
-
* @param
|
|
15166
|
-
* @param
|
|
15167
|
-
* @
|
|
15456
|
+
* @param context Canvas 2D context.
|
|
15457
|
+
* @param corners Quad corners in clockwise order.
|
|
15458
|
+
* @param fillStyle CSS fill style.
|
|
15168
15459
|
*
|
|
15169
|
-
* @private helper of `
|
|
15460
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15170
15461
|
*/
|
|
15171
|
-
function
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15462
|
+
function drawProjectedQuad(context, corners, fillStyle) {
|
|
15463
|
+
context.beginPath();
|
|
15464
|
+
context.moveTo(corners[0].x, corners[0].y);
|
|
15465
|
+
context.lineTo(corners[1].x, corners[1].y);
|
|
15466
|
+
context.lineTo(corners[2].x, corners[2].y);
|
|
15467
|
+
context.lineTo(corners[3].x, corners[3].y);
|
|
15468
|
+
context.closePath();
|
|
15469
|
+
context.fillStyle = fillStyle;
|
|
15470
|
+
context.fill();
|
|
15471
|
+
}
|
|
15472
|
+
/**
|
|
15473
|
+
* Interpolates one point inside a projected quad across both quad axes.
|
|
15474
|
+
*
|
|
15475
|
+
* @param corners Quad corners in clockwise order.
|
|
15476
|
+
* @param horizontalRatio Horizontal ratio in the range `[0, 1]`.
|
|
15477
|
+
* @param verticalRatio Vertical ratio in the range `[0, 1]`.
|
|
15478
|
+
* @returns Interpolated projected point.
|
|
15479
|
+
*
|
|
15480
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15481
|
+
*/
|
|
15482
|
+
function interpolateProjectedQuad(corners, horizontalRatio, verticalRatio) {
|
|
15483
|
+
const topPoint = interpolateProjectedPoint(corners[0], corners[1], horizontalRatio);
|
|
15484
|
+
const bottomPoint = interpolateProjectedPoint(corners[3], corners[2], horizontalRatio);
|
|
15485
|
+
return interpolateProjectedPoint(topPoint, bottomPoint, verticalRatio);
|
|
15486
|
+
}
|
|
15487
|
+
/**
|
|
15488
|
+
* Interpolates between two projected points.
|
|
15489
|
+
*
|
|
15490
|
+
* @param startPoint Start point.
|
|
15491
|
+
* @param endPoint End point.
|
|
15492
|
+
* @param ratio Interpolation ratio in the range `[0, 1]`.
|
|
15493
|
+
* @returns Interpolated projected point.
|
|
15494
|
+
*
|
|
15495
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15496
|
+
*/
|
|
15497
|
+
function interpolateProjectedPoint(startPoint, endPoint, ratio) {
|
|
15498
|
+
return {
|
|
15499
|
+
x: startPoint.x + (endPoint.x - startPoint.x) * ratio,
|
|
15500
|
+
y: startPoint.y + (endPoint.y - startPoint.y) * ratio,
|
|
15501
|
+
z: startPoint.z + (endPoint.z - startPoint.z) * ratio,
|
|
15502
|
+
};
|
|
15503
|
+
}
|
|
15504
|
+
/**
|
|
15505
|
+
* Projects one rotated scene point into canvas coordinates.
|
|
15506
|
+
*
|
|
15507
|
+
* @param point Scene point.
|
|
15508
|
+
* @param size Canvas size in CSS pixels.
|
|
15509
|
+
* @param sceneCenterX Horizontal scene center.
|
|
15510
|
+
* @param sceneCenterY Vertical scene center.
|
|
15511
|
+
* @returns Projected point.
|
|
15512
|
+
*
|
|
15513
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15514
|
+
*/
|
|
15515
|
+
function projectScenePoint(point, size, sceneCenterX, sceneCenterY) {
|
|
15516
|
+
const cameraDistance = size * CAMERA_DISTANCE_RATIO;
|
|
15517
|
+
const perspectiveScale = cameraDistance / Math.max(cameraDistance - point.z, cameraDistance * 0.35);
|
|
15518
|
+
return {
|
|
15519
|
+
x: sceneCenterX + point.x * perspectiveScale,
|
|
15520
|
+
y: sceneCenterY + point.y * perspectiveScale,
|
|
15521
|
+
z: point.z,
|
|
15522
|
+
};
|
|
15523
|
+
}
|
|
15524
|
+
/**
|
|
15525
|
+
* Applies the local cuboid rotations and translation to one scene point.
|
|
15526
|
+
*
|
|
15527
|
+
* @param localPoint Point in cuboid-local space.
|
|
15528
|
+
* @param center Cuboid center in scene space.
|
|
15529
|
+
* @param rotationX Cuboid pitch in radians.
|
|
15530
|
+
* @param rotationY Cuboid yaw in radians.
|
|
15531
|
+
* @returns Transformed scene-space point.
|
|
15532
|
+
*
|
|
15533
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15534
|
+
*/
|
|
15535
|
+
function transformScenePoint(localPoint, center, rotationX, rotationY) {
|
|
15536
|
+
const yawedPoint = rotatePointAroundY(localPoint, rotationY);
|
|
15537
|
+
const pitchedPoint = rotatePointAroundX(yawedPoint, rotationX);
|
|
15538
|
+
return {
|
|
15539
|
+
x: center.x + pitchedPoint.x,
|
|
15540
|
+
y: center.y + pitchedPoint.y,
|
|
15541
|
+
z: center.z + pitchedPoint.z,
|
|
15542
|
+
};
|
|
15543
|
+
}
|
|
15544
|
+
/**
|
|
15545
|
+
* Rotates one point around the local Y axis.
|
|
15546
|
+
*
|
|
15547
|
+
* @param point Source point.
|
|
15548
|
+
* @param angle Rotation angle in radians.
|
|
15549
|
+
* @returns Rotated point.
|
|
15550
|
+
*
|
|
15551
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15552
|
+
*/
|
|
15553
|
+
function rotatePointAroundY(point, angle) {
|
|
15554
|
+
const cosine = Math.cos(angle);
|
|
15555
|
+
const sine = Math.sin(angle);
|
|
15556
|
+
return {
|
|
15557
|
+
x: point.x * cosine + point.z * sine,
|
|
15558
|
+
y: point.y,
|
|
15559
|
+
z: -point.x * sine + point.z * cosine,
|
|
15560
|
+
};
|
|
15561
|
+
}
|
|
15562
|
+
/**
|
|
15563
|
+
* Rotates one point around the local X axis.
|
|
15564
|
+
*
|
|
15565
|
+
* @param point Source point.
|
|
15566
|
+
* @param angle Rotation angle in radians.
|
|
15567
|
+
* @returns Rotated point.
|
|
15568
|
+
*
|
|
15569
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15570
|
+
*/
|
|
15571
|
+
function rotatePointAroundX(point, angle) {
|
|
15572
|
+
const cosine = Math.cos(angle);
|
|
15573
|
+
const sine = Math.sin(angle);
|
|
15574
|
+
return {
|
|
15575
|
+
x: point.x,
|
|
15576
|
+
y: point.y * cosine - point.z * sine,
|
|
15577
|
+
z: point.y * sine + point.z * cosine,
|
|
15578
|
+
};
|
|
15579
|
+
}
|
|
15580
|
+
/**
|
|
15581
|
+
* Subtracts one 3D point from another.
|
|
15582
|
+
*
|
|
15583
|
+
* @param leftPoint Left point.
|
|
15584
|
+
* @param rightPoint Right point.
|
|
15585
|
+
* @returns Difference vector.
|
|
15586
|
+
*
|
|
15587
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15588
|
+
*/
|
|
15589
|
+
function subtractPoint3D(leftPoint, rightPoint) {
|
|
15590
|
+
return {
|
|
15591
|
+
x: leftPoint.x - rightPoint.x,
|
|
15592
|
+
y: leftPoint.y - rightPoint.y,
|
|
15593
|
+
z: leftPoint.z - rightPoint.z,
|
|
15594
|
+
};
|
|
15595
|
+
}
|
|
15596
|
+
/**
|
|
15597
|
+
* Computes the 3D cross product of two vectors.
|
|
15598
|
+
*
|
|
15599
|
+
* @param leftVector Left vector.
|
|
15600
|
+
* @param rightVector Right vector.
|
|
15601
|
+
* @returns Cross product.
|
|
15602
|
+
*
|
|
15603
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15604
|
+
*/
|
|
15605
|
+
function crossProduct3D(leftVector, rightVector) {
|
|
15606
|
+
return {
|
|
15607
|
+
x: leftVector.y * rightVector.z - leftVector.z * rightVector.y,
|
|
15608
|
+
y: leftVector.z * rightVector.x - leftVector.x * rightVector.z,
|
|
15609
|
+
z: leftVector.x * rightVector.y - leftVector.y * rightVector.x,
|
|
15610
|
+
};
|
|
15611
|
+
}
|
|
15612
|
+
/**
|
|
15613
|
+
* Computes the 3D dot product of two vectors.
|
|
15614
|
+
*
|
|
15615
|
+
* @param leftVector Left vector.
|
|
15616
|
+
* @param rightVector Right vector.
|
|
15617
|
+
* @returns Dot product.
|
|
15618
|
+
*
|
|
15619
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15620
|
+
*/
|
|
15621
|
+
function dotProduct3D(leftVector, rightVector) {
|
|
15622
|
+
return leftVector.x * rightVector.x + leftVector.y * rightVector.y + leftVector.z * rightVector.z;
|
|
15623
|
+
}
|
|
15624
|
+
/**
|
|
15625
|
+
* Normalizes one 3D vector while keeping zero vectors stable.
|
|
15626
|
+
*
|
|
15627
|
+
* @param vector Source vector.
|
|
15628
|
+
* @returns Normalized vector.
|
|
15629
|
+
*
|
|
15630
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15631
|
+
*/
|
|
15632
|
+
function normalizeVector3(vector) {
|
|
15633
|
+
const length = Math.hypot(vector.x, vector.y, vector.z);
|
|
15634
|
+
if (length === 0) {
|
|
15635
|
+
return vector;
|
|
15178
15636
|
}
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
|
|
15637
|
+
return {
|
|
15638
|
+
x: vector.x / length,
|
|
15639
|
+
y: vector.y / length,
|
|
15640
|
+
z: vector.z / length,
|
|
15641
|
+
};
|
|
15642
|
+
}
|
|
15643
|
+
/**
|
|
15644
|
+
* Clamps one number into the provided range.
|
|
15645
|
+
*
|
|
15646
|
+
* @param value Input value.
|
|
15647
|
+
* @param minimumValue Inclusive lower bound.
|
|
15648
|
+
* @param maximumValue Inclusive upper bound.
|
|
15649
|
+
* @returns Clamped value.
|
|
15650
|
+
*
|
|
15651
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15652
|
+
*/
|
|
15653
|
+
function clampNumber$1(value, minimumValue, maximumValue) {
|
|
15654
|
+
return Math.min(maximumValue, Math.max(minimumValue, value));
|
|
15655
|
+
}
|
|
15656
|
+
/**
|
|
15657
|
+
* Measures the perimeter of one projected quad.
|
|
15658
|
+
*
|
|
15659
|
+
* @param corners Quad corners.
|
|
15660
|
+
* @returns Perimeter length.
|
|
15661
|
+
*
|
|
15662
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
15663
|
+
*/
|
|
15664
|
+
function getProjectedQuadPerimeter(corners) {
|
|
15665
|
+
let perimeter = 0;
|
|
15666
|
+
for (let cornerIndex = 0; cornerIndex < corners.length; cornerIndex++) {
|
|
15667
|
+
const currentCorner = corners[cornerIndex];
|
|
15668
|
+
const nextCorner = corners[(cornerIndex + 1) % corners.length];
|
|
15669
|
+
perimeter += Math.hypot(nextCorner.x - currentCorner.x, nextCorner.y - currentCorner.y);
|
|
15182
15670
|
}
|
|
15183
|
-
|
|
15184
|
-
texture[4][6] = palette.accent;
|
|
15185
|
-
texture[5][2] = palette.highlight;
|
|
15186
|
-
texture[5][5] = palette.highlight;
|
|
15187
|
-
return texture;
|
|
15671
|
+
return perimeter;
|
|
15188
15672
|
}
|
|
15189
15673
|
|
|
15190
15674
|
/* eslint-disable no-magic-numbers */
|
|
@@ -16789,6 +17273,7 @@
|
|
|
16789
17273
|
octopus3AvatarVisual,
|
|
16790
17274
|
asciiOctopusAvatarVisual,
|
|
16791
17275
|
minecraftAvatarVisual,
|
|
17276
|
+
minecraft2AvatarVisual,
|
|
16792
17277
|
fractalAvatarVisual,
|
|
16793
17278
|
orbAvatarVisual,
|
|
16794
17279
|
];
|
|
@@ -18091,7 +18576,11 @@
|
|
|
18091
18576
|
// Create new system message with persona at the beginning
|
|
18092
18577
|
// Format: "You are {agentName}\n{personaContent}"
|
|
18093
18578
|
// The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
|
|
18094
|
-
const personaSection =
|
|
18579
|
+
const personaSection = spacetrim.spaceTrim((block) => `
|
|
18580
|
+
# PERSONA
|
|
18581
|
+
You are ${agentName}
|
|
18582
|
+
${block(mergedPersonaContent)}
|
|
18583
|
+
`);
|
|
18095
18584
|
const newSystemMessage = cleanedMessage ? `${personaSection}\n\n${cleanedMessage}` : personaSection;
|
|
18096
18585
|
return {
|
|
18097
18586
|
...requirements,
|
|
@@ -18993,7 +19482,10 @@
|
|
|
18993
19482
|
*/
|
|
18994
19483
|
function buildTeamToolDescription(entry) {
|
|
18995
19484
|
const detailLines = collectTeamEntryDetails(entry).map(({ label, content }) => `${label}: ${content}`);
|
|
18996
|
-
return
|
|
19485
|
+
return spacetrim.spaceTrim((block) => `
|
|
19486
|
+
Consult teammate ${entry.teammate.label}
|
|
19487
|
+
${block(detailLines.join('\n'))}
|
|
19488
|
+
`);
|
|
18997
19489
|
}
|
|
18998
19490
|
/**
|
|
18999
19491
|
* Collects structured teammate details that should stay visible to the model.
|
|
@@ -24327,7 +24819,10 @@
|
|
|
24327
24819
|
if (hiddenCount > 0) {
|
|
24328
24820
|
summaryRows.push(`...and ${hiddenCount} more.`);
|
|
24329
24821
|
}
|
|
24330
|
-
return
|
|
24822
|
+
return spacetrim.spaceTrim((block) => `
|
|
24823
|
+
Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
|
|
24824
|
+
${block(summaryRows.join('\n'))}
|
|
24825
|
+
`);
|
|
24331
24826
|
}
|
|
24332
24827
|
/**
|
|
24333
24828
|
* Formats one timeout row for assistant-visible timeout listings.
|
|
@@ -27698,6 +28193,791 @@
|
|
|
27698
28193
|
// <- [🐱🚀] Buttons into genesis book
|
|
27699
28194
|
// <- TODO: [🐱🚀] generateBookBoilerplate and deprecate `DEFAULT_BOOK`
|
|
27700
28195
|
|
|
28196
|
+
/**
|
|
28197
|
+
* Warning message used for unfinished commitments.
|
|
28198
|
+
*/
|
|
28199
|
+
const UNFINISHED_COMMITMENT_MESSAGE = 'This commitment is unfinished and not ready to use. Be careful when using it.';
|
|
28200
|
+
/**
|
|
28201
|
+
* Low-level warning message used for low-level commitments.
|
|
28202
|
+
*/
|
|
28203
|
+
const LOW_LEVEL_COMMITMENT_MESSAGE = 'This commitment is low-level and not used by most of the users. Be careful when using it.';
|
|
28204
|
+
/**
|
|
28205
|
+
* Short badge text used for deprecated commitments.
|
|
28206
|
+
*/
|
|
28207
|
+
const DEPRECATED_COMMITMENT_BADGE_LABEL = 'Deprecated';
|
|
28208
|
+
/**
|
|
28209
|
+
* Short badge text used for unfinished and low-level commitments.
|
|
28210
|
+
*/
|
|
28211
|
+
const LOW_LEVEL_COMMITMENT_BADGE_LABEL = 'Low-level';
|
|
28212
|
+
/**
|
|
28213
|
+
* Longer label used for deprecated commitments.
|
|
28214
|
+
*/
|
|
28215
|
+
const DEPRECATED_COMMITMENT_DETAIL_LABEL = 'Deprecated commitment';
|
|
28216
|
+
/**
|
|
28217
|
+
* Longer label used for unfinished and low-level commitments.
|
|
28218
|
+
*/
|
|
28219
|
+
const LOW_LEVEL_COMMITMENT_DETAIL_LABEL = 'Low-level commitment';
|
|
28220
|
+
/**
|
|
28221
|
+
* Prefix used when formatting replacement guidance.
|
|
28222
|
+
*/
|
|
28223
|
+
const PREFERRED_REPLACEMENT_LABEL = 'Preferred replacement';
|
|
28224
|
+
/**
|
|
28225
|
+
* Formats preferred replacement guidance for deprecated commitments.
|
|
28226
|
+
*
|
|
28227
|
+
* @param replacedBy - Preferred replacement commitment keywords.
|
|
28228
|
+
* @returns Optional replacement guidance sentence with leading space.
|
|
28229
|
+
*
|
|
28230
|
+
* @private internal utility of commitment catalog notices
|
|
28231
|
+
*/
|
|
28232
|
+
function formatCommitmentReplacementText(replacedBy) {
|
|
28233
|
+
if (!replacedBy || replacedBy.length === 0) {
|
|
28234
|
+
return '';
|
|
28235
|
+
}
|
|
28236
|
+
return ` ${PREFERRED_REPLACEMENT_LABEL}: ${replacedBy.map((type) => `\`${type}\``).join(', ')}.`;
|
|
28237
|
+
}
|
|
28238
|
+
/**
|
|
28239
|
+
* Resolves the notice metadata for deprecated, unfinished, or low-level commitments.
|
|
28240
|
+
*
|
|
28241
|
+
* @param definition - Commitment definition to inspect.
|
|
28242
|
+
* @returns Notice metadata when the commitment should be surfaced with caution.
|
|
28243
|
+
*
|
|
28244
|
+
* @private internal utility of commitment catalog notices
|
|
28245
|
+
*/
|
|
28246
|
+
function getCommitmentNoticeMetadata(definition) {
|
|
28247
|
+
if (definition.isUnfinished) {
|
|
28248
|
+
return {
|
|
28249
|
+
kind: 'unfinished',
|
|
28250
|
+
badgeLabel: LOW_LEVEL_COMMITMENT_BADGE_LABEL,
|
|
28251
|
+
detailLabel: LOW_LEVEL_COMMITMENT_DETAIL_LABEL,
|
|
28252
|
+
message: UNFINISHED_COMMITMENT_MESSAGE,
|
|
28253
|
+
};
|
|
28254
|
+
}
|
|
28255
|
+
if (definition.isLowLevel) {
|
|
28256
|
+
return {
|
|
28257
|
+
kind: 'lowLevel',
|
|
28258
|
+
badgeLabel: LOW_LEVEL_COMMITMENT_BADGE_LABEL,
|
|
28259
|
+
detailLabel: LOW_LEVEL_COMMITMENT_DETAIL_LABEL,
|
|
28260
|
+
message: LOW_LEVEL_COMMITMENT_MESSAGE,
|
|
28261
|
+
};
|
|
28262
|
+
}
|
|
28263
|
+
if (definition.deprecation) {
|
|
28264
|
+
return {
|
|
28265
|
+
kind: 'deprecated',
|
|
28266
|
+
badgeLabel: DEPRECATED_COMMITMENT_BADGE_LABEL,
|
|
28267
|
+
detailLabel: DEPRECATED_COMMITMENT_DETAIL_LABEL,
|
|
28268
|
+
message: definition.deprecation.message,
|
|
28269
|
+
};
|
|
28270
|
+
}
|
|
28271
|
+
return null;
|
|
28272
|
+
}
|
|
28273
|
+
|
|
28274
|
+
/**
|
|
28275
|
+
* Common anti-patterns with practical fixes.
|
|
28276
|
+
*
|
|
28277
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28278
|
+
*/
|
|
28279
|
+
const bookLanguageCommonPitfalls = [
|
|
28280
|
+
{
|
|
28281
|
+
title: 'Too broad agent scope',
|
|
28282
|
+
dont: 'One agent tries to be a lawyer, developer, marketer, and researcher at once.',
|
|
28283
|
+
doInstead: 'Split into focused agents and orchestrate with TEAM or IMPORT.',
|
|
28284
|
+
},
|
|
28285
|
+
{
|
|
28286
|
+
title: 'Unverifiable claims',
|
|
28287
|
+
dont: 'The agent answers internet-dependent questions without tools or without citing sources.',
|
|
28288
|
+
doInstead: 'Add `USE SEARCH ENGINE` / `USE BROWSER` and a citation-oriented `RULE`.',
|
|
28289
|
+
},
|
|
28290
|
+
{
|
|
28291
|
+
title: 'Missing guardrails',
|
|
28292
|
+
dont: 'Only persona is defined, with no behavioral constraints.',
|
|
28293
|
+
doInstead: 'Add concrete `RULE` commitments for safety, scope, and tone.',
|
|
28294
|
+
},
|
|
28295
|
+
{
|
|
28296
|
+
title: 'Overloaded inheritance',
|
|
28297
|
+
dont: 'Using deep `FROM` chains without documenting why each parent is needed.',
|
|
28298
|
+
doInstead: 'Keep inheritance shallow and use focused IMPORT/TEAM composition for reuse.',
|
|
28299
|
+
},
|
|
28300
|
+
{
|
|
28301
|
+
title: 'Unsafe memory usage',
|
|
28302
|
+
dont: 'Storing every detail in memory without boundaries.',
|
|
28303
|
+
doInstead: 'Pair `MEMORY` with explicit rules about what is allowed to persist.',
|
|
28304
|
+
},
|
|
28305
|
+
];
|
|
28306
|
+
|
|
28307
|
+
/**
|
|
28308
|
+
* End-to-end examples used by the standalone Book language documentation.
|
|
28309
|
+
*
|
|
28310
|
+
* These are intentionally compact but complete, so they can be copy-pasted and
|
|
28311
|
+
* used as practical starting points.
|
|
28312
|
+
*
|
|
28313
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28314
|
+
*/
|
|
28315
|
+
const bookLanguageDocumentationExamples = [
|
|
28316
|
+
{
|
|
28317
|
+
id: 'minimal-hello-world-agent',
|
|
28318
|
+
title: 'Minimal hello-world agent',
|
|
28319
|
+
goal: 'Create the smallest useful agent with identity and greeting.',
|
|
28320
|
+
source: spacetrim.spaceTrim(`
|
|
28321
|
+
Hello World Agent
|
|
28322
|
+
|
|
28323
|
+
GOAL Be a concise and friendly assistant.
|
|
28324
|
+
INITIAL MESSAGE Hello! I am ready to help.
|
|
28325
|
+
CLOSED
|
|
28326
|
+
`),
|
|
28327
|
+
walkthrough: [
|
|
28328
|
+
'The first line (`Hello World Agent`) is the agent name.',
|
|
28329
|
+
'`GOAL` defines the effective role and profile text.',
|
|
28330
|
+
'`INITIAL MESSAGE` sets a deterministic first message for a new chat.',
|
|
28331
|
+
'`CLOSED` prevents conversational self-modification.',
|
|
28332
|
+
],
|
|
28333
|
+
},
|
|
28334
|
+
{
|
|
28335
|
+
id: 'tool-using-browser-search-agent',
|
|
28336
|
+
title: 'Tool-using agent (Browser + Search engine)',
|
|
28337
|
+
goal: 'Enable internet research with clear sourcing behavior.',
|
|
28338
|
+
source: spacetrim.spaceTrim(`
|
|
28339
|
+
Web Research Assistant
|
|
28340
|
+
|
|
28341
|
+
GOAL Research topics using fresh and verifiable information.
|
|
28342
|
+
USE SEARCH ENGINE Prefer official sources and recent publications.
|
|
28343
|
+
USE BROWSER
|
|
28344
|
+
RULE Verify important claims across multiple sources when possible.
|
|
28345
|
+
RULE Include source links in your final answer.
|
|
28346
|
+
INITIAL MESSAGE Ask me what topic you want to research and how deep the report should be.
|
|
28347
|
+
`),
|
|
28348
|
+
walkthrough: [
|
|
28349
|
+
'`USE SEARCH ENGINE` provides web search tooling and optional search instructions.',
|
|
28350
|
+
'`USE BROWSER` enables URL fetching and interactive browsing tools.',
|
|
28351
|
+
'`RULE` commitments make reliability behavior explicit and repeatable.',
|
|
28352
|
+
'This pattern is ideal for current-events and fact-checking agents.',
|
|
28353
|
+
],
|
|
28354
|
+
},
|
|
28355
|
+
{
|
|
28356
|
+
id: 'rule-and-knowledge-agent',
|
|
28357
|
+
title: 'Agent with RULE and KNOWLEDGE',
|
|
28358
|
+
goal: 'Ground responses in explicit constraints and curated sources.',
|
|
28359
|
+
source: spacetrim.spaceTrim(`
|
|
28360
|
+
Support Policy Assistant
|
|
28361
|
+
|
|
28362
|
+
GOAL Answer questions about support policy.
|
|
28363
|
+
KNOWLEDGE Refunds are available within 30 days with proof of purchase.
|
|
28364
|
+
KNOWLEDGE https://example.com/support-policy
|
|
28365
|
+
RULE If a policy item is missing in available knowledge, say it explicitly.
|
|
28366
|
+
RULE Never invent legal or policy statements.
|
|
28367
|
+
INITIAL MESSAGE I can explain refund and support rules from provided knowledge.
|
|
28368
|
+
`),
|
|
28369
|
+
walkthrough: [
|
|
28370
|
+
'`KNOWLEDGE` may be inline text or an external URL/document.',
|
|
28371
|
+
'`RULE` commitments define non-negotiable behavior constraints.',
|
|
28372
|
+
'Combining both creates predictable, grounded policy responses.',
|
|
28373
|
+
'Use this pattern for compliance, support, and internal procedures.',
|
|
28374
|
+
],
|
|
28375
|
+
},
|
|
28376
|
+
{
|
|
28377
|
+
id: 'memory-agent-with-long-term-memory',
|
|
28378
|
+
title: 'MEMORY agent with long-term memory',
|
|
28379
|
+
goal: 'Persist user preferences across conversations.',
|
|
28380
|
+
source: spacetrim.spaceTrim(`
|
|
28381
|
+
Customer Success Memory Agent
|
|
28382
|
+
|
|
28383
|
+
GOAL Support SaaS customers while remembering relevant setup and preference context.
|
|
28384
|
+
MEMORY Remember product setup, user goals, and communication preferences.
|
|
28385
|
+
RULE Store only user-approved preferences and project context.
|
|
28386
|
+
RULE Never store secrets or sensitive data unless explicitly requested and allowed.
|
|
28387
|
+
INITIAL MESSAGE I can remember your setup and preferences for future sessions.
|
|
28388
|
+
`),
|
|
28389
|
+
walkthrough: [
|
|
28390
|
+
'`MEMORY` adds runtime memory tools and memory-specific system guidance.',
|
|
28391
|
+
'`RULE` commitments narrow what should be remembered to reduce privacy risks.',
|
|
28392
|
+
'In Agents Server, memory is runtime-backed and user-scoped.',
|
|
28393
|
+
'Use this for assistants that must preserve context over time.',
|
|
28394
|
+
],
|
|
28395
|
+
},
|
|
28396
|
+
{
|
|
28397
|
+
id: 'use-project-and-wallet-integration-agent',
|
|
28398
|
+
title: 'USE PROJECT and WALLET external integration',
|
|
28399
|
+
goal: 'Work with GitHub repositories and wallet-backed credentials.',
|
|
28400
|
+
source: spacetrim.spaceTrim(`
|
|
28401
|
+
Repository Maintainer
|
|
28402
|
+
|
|
28403
|
+
GOAL Maintain a GitHub repository and prepare safe pull requests.
|
|
28404
|
+
USE PROJECT https://github.com/acme/website
|
|
28405
|
+
WALLET Store credentials for repository operations.
|
|
28406
|
+
RULE Before editing files, explain the planned change and impacted paths.
|
|
28407
|
+
RULE Never reveal raw credentials in chat output.
|
|
28408
|
+
INITIAL MESSAGE I can inspect the repository and help you prepare PR-ready changes.
|
|
28409
|
+
`),
|
|
28410
|
+
walkthrough: [
|
|
28411
|
+
'`USE PROJECT` enables repository tools for listing, reading, editing files, and creating PRs.',
|
|
28412
|
+
'Credentials are resolved from wallet records at runtime in Agents Server.',
|
|
28413
|
+
'`WALLET` is kept here as a compatibility marker, but current Book 2.0 parsing treats it as deprecated/ignored.',
|
|
28414
|
+
'In current runtime behavior, wallet-backed integrations are driven by commitments such as `USE PROJECT` and `USE EMAIL`.',
|
|
28415
|
+
],
|
|
28416
|
+
},
|
|
28417
|
+
{
|
|
28418
|
+
id: 'use-calendar-integration-agent',
|
|
28419
|
+
title: 'USE CALENDAR integration',
|
|
28420
|
+
goal: 'Coordinate meetings and schedules through a connected Google Calendar.',
|
|
28421
|
+
source: spacetrim.spaceTrim(`
|
|
28422
|
+
Calendar Assistant
|
|
28423
|
+
|
|
28424
|
+
GOAL Schedule meetings and keep the calendar conflict-free.
|
|
28425
|
+
USE CALENDAR https://calendar.google.com/calendar/u/0/r
|
|
28426
|
+
SCOPES https://www.googleapis.com/auth/calendar
|
|
28427
|
+
RULE Confirm destructive actions before deleting an event.
|
|
28428
|
+
INITIAL MESSAGE Tell me the meeting details and I will schedule it in your calendar.
|
|
28429
|
+
`),
|
|
28430
|
+
walkthrough: [
|
|
28431
|
+
'`USE CALENDAR` enables calendar tools for listing, reading, creating, updating, and deleting events.',
|
|
28432
|
+
'The first calendar URL identifies which calendar integration should be used.',
|
|
28433
|
+
'`SCOPES` can explicitly request required Google Calendar OAuth permissions.',
|
|
28434
|
+
'Credentials are resolved from wallet-backed Google Calendar OAuth records at runtime in Agents Server.',
|
|
28435
|
+
],
|
|
28436
|
+
},
|
|
28437
|
+
{
|
|
28438
|
+
id: 'agents-team-example',
|
|
28439
|
+
title: 'Agents TEAM (with in-book teammates)',
|
|
28440
|
+
goal: 'Delegate sub-tasks to specialized teammates.',
|
|
28441
|
+
source: spacetrim.spaceTrim(`
|
|
28442
|
+
Team Manager
|
|
28443
|
+
|
|
28444
|
+
GOAL Coordinate specialists and deliver one consolidated answer.
|
|
28445
|
+
TEAM Ask {Legal Reviewer} for legal constraints and {Implementation Reviewer} for technical feasibility.
|
|
28446
|
+
RULE Always summarize teammate outputs into one action plan.
|
|
28447
|
+
|
|
28448
|
+
---
|
|
28449
|
+
|
|
28450
|
+
Legal Reviewer
|
|
28451
|
+
|
|
28452
|
+
FROM VOID
|
|
28453
|
+
GOAL Review legal and compliance risk.
|
|
28454
|
+
RULE Flag legal/compliance risk and uncertainty clearly.
|
|
28455
|
+
CLOSED
|
|
28456
|
+
|
|
28457
|
+
---
|
|
28458
|
+
|
|
28459
|
+
Implementation Reviewer
|
|
28460
|
+
|
|
28461
|
+
FROM VOID
|
|
28462
|
+
GOAL Review implementation effort and delivery risk.
|
|
28463
|
+
RULE Estimate complexity and identify blockers.
|
|
28464
|
+
CLOSED
|
|
28465
|
+
`),
|
|
28466
|
+
walkthrough: [
|
|
28467
|
+
'The main agent delegates via `TEAM` commitment.',
|
|
28468
|
+
'References in `{...}` are resolved against embedded agents inside the same book (split by `---`).',
|
|
28469
|
+
'Each teammate can be isolated with `FROM VOID` for deterministic specialization.',
|
|
28470
|
+
'This pattern works well for multi-role review and decision support.',
|
|
28471
|
+
],
|
|
28472
|
+
},
|
|
28473
|
+
];
|
|
28474
|
+
|
|
28475
|
+
/**
|
|
28476
|
+
* Canonical commitment keyword for the open/closed family.
|
|
28477
|
+
*
|
|
28478
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28479
|
+
*/
|
|
28480
|
+
const OPEN_COMMITMENT_TYPE = 'OPEN';
|
|
28481
|
+
/**
|
|
28482
|
+
* Canonical commitment keyword for the open/closed family.
|
|
28483
|
+
*/
|
|
28484
|
+
const CLOSED_COMMITMENT_TYPE = 'CLOSED';
|
|
28485
|
+
/**
|
|
28486
|
+
* Removes the top-level heading from one commitment documentation block.
|
|
28487
|
+
*
|
|
28488
|
+
* @param markdown - Original markdown source.
|
|
28489
|
+
* @returns Markdown without the first `#` heading.
|
|
28490
|
+
*
|
|
28491
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28492
|
+
*/
|
|
28493
|
+
function removeLeadingTopLevelHeading(markdown) {
|
|
28494
|
+
return markdown.replace(/^\s*#\s+[^\n]+\n*/u, '').trim();
|
|
28495
|
+
}
|
|
28496
|
+
/**
|
|
28497
|
+
* Renders one subsection for the combined open/closed documentation family.
|
|
28498
|
+
*
|
|
28499
|
+
* @param title - Heading label for the subsection.
|
|
28500
|
+
* @param documentation - Raw commitment documentation markdown.
|
|
28501
|
+
* @returns Markdown subsection with a `####` heading.
|
|
28502
|
+
*
|
|
28503
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28504
|
+
*/
|
|
28505
|
+
function renderDocumentationSection(title, documentation) {
|
|
28506
|
+
return `#### ${title}\n\n${removeLeadingTopLevelHeading(documentation)}`;
|
|
28507
|
+
}
|
|
28508
|
+
/**
|
|
28509
|
+
* Renders the documentation body for one grouped commitment entry.
|
|
28510
|
+
*
|
|
28511
|
+
* `OPEN` and `CLOSED` are intentionally rendered together so the documentation
|
|
28512
|
+
* surfaces present them as one conceptual switch instead of two isolated pages.
|
|
28513
|
+
*
|
|
28514
|
+
* @param group - Grouped commitment metadata.
|
|
28515
|
+
* @returns Markdown body for the docs page/catalog entry.
|
|
28516
|
+
*
|
|
28517
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28518
|
+
*/
|
|
28519
|
+
function renderGroupedCommitmentDocumentationMarkdown(group) {
|
|
28520
|
+
const commitmentTypes = new Set([group.primary.type, ...group.aliases]);
|
|
28521
|
+
if (commitmentTypes.has(OPEN_COMMITMENT_TYPE) && commitmentTypes.has(CLOSED_COMMITMENT_TYPE)) {
|
|
28522
|
+
const openCommitmentDefinition = getCommitmentDefinition(OPEN_COMMITMENT_TYPE);
|
|
28523
|
+
const closedCommitmentDefinition = getCommitmentDefinition(CLOSED_COMMITMENT_TYPE);
|
|
28524
|
+
if (openCommitmentDefinition && closedCommitmentDefinition) {
|
|
28525
|
+
return spacetrim.spaceTrim((block) => `
|
|
28526
|
+
${block(renderDocumentationSection(OPEN_COMMITMENT_TYPE, openCommitmentDefinition.documentation))}
|
|
28527
|
+
|
|
28528
|
+
${block(renderDocumentationSection(CLOSED_COMMITMENT_TYPE, closedCommitmentDefinition.documentation))}
|
|
28529
|
+
`);
|
|
28530
|
+
}
|
|
28531
|
+
}
|
|
28532
|
+
return removeLeadingTopLevelHeading(group.primary.documentation);
|
|
28533
|
+
}
|
|
28534
|
+
|
|
28535
|
+
/**
|
|
28536
|
+
* Commitment types that primarily model composition of multiple agents.
|
|
28537
|
+
*
|
|
28538
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28539
|
+
*/
|
|
28540
|
+
const COMPOSITION_COMMITMENT_TYPES = new Set(['FROM', 'IMPORT', 'IMPORTS', 'TEAM']);
|
|
28541
|
+
/**
|
|
28542
|
+
* Commitment types that expose tools/runtime capabilities.
|
|
28543
|
+
*
|
|
28544
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28545
|
+
*/
|
|
28546
|
+
const TOOLING_COMMITMENT_TYPES = new Set([
|
|
28547
|
+
'USE BROWSER',
|
|
28548
|
+
'USE DEEPSEARCH',
|
|
28549
|
+
'USE SEARCH ENGINE',
|
|
28550
|
+
'USE SEARCH',
|
|
28551
|
+
'USE SPAWN',
|
|
28552
|
+
'USE EMAIL',
|
|
28553
|
+
'USE POPUP',
|
|
28554
|
+
'USE TIME',
|
|
28555
|
+
'USE USER LOCATION',
|
|
28556
|
+
'USE PROJECT',
|
|
28557
|
+
'USE CALENDAR',
|
|
28558
|
+
'USE IMAGE GENERATOR',
|
|
28559
|
+
'USE MCP',
|
|
28560
|
+
'USE PRIVACY',
|
|
28561
|
+
'MEMORY',
|
|
28562
|
+
'MEMORIES',
|
|
28563
|
+
]);
|
|
28564
|
+
/**
|
|
28565
|
+
* Commitment types that primarily define agent profile metadata.
|
|
28566
|
+
*
|
|
28567
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28568
|
+
*/
|
|
28569
|
+
const PROFILE_COMMITMENT_TYPES = new Set([
|
|
28570
|
+
'GOAL',
|
|
28571
|
+
'GOALS',
|
|
28572
|
+
'PERSONA',
|
|
28573
|
+
'PERSONAE',
|
|
28574
|
+
'META',
|
|
28575
|
+
'META AVATAR',
|
|
28576
|
+
'META IMAGE',
|
|
28577
|
+
'META LINK',
|
|
28578
|
+
'META DOMAIN',
|
|
28579
|
+
'META DESCRIPTION',
|
|
28580
|
+
'META DISCLAIMER',
|
|
28581
|
+
'META INPUT PLACEHOLDER',
|
|
28582
|
+
'META COLOR',
|
|
28583
|
+
'META FONT',
|
|
28584
|
+
'META VOICE',
|
|
28585
|
+
'INITIAL MESSAGE',
|
|
28586
|
+
'MODEL',
|
|
28587
|
+
'MODELS',
|
|
28588
|
+
]);
|
|
28589
|
+
/**
|
|
28590
|
+
* Commitment types that primarily define behavioral constraints or prompt shaping.
|
|
28591
|
+
*
|
|
28592
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28593
|
+
*/
|
|
28594
|
+
const BEHAVIOR_COMMITMENT_TYPES = new Set([
|
|
28595
|
+
'RULE',
|
|
28596
|
+
'RULES',
|
|
28597
|
+
'KNOWLEDGE',
|
|
28598
|
+
'GOAL',
|
|
28599
|
+
'GOALS',
|
|
28600
|
+
'STYLE',
|
|
28601
|
+
'STYLES',
|
|
28602
|
+
'LANGUAGE',
|
|
28603
|
+
'LANGUAGES',
|
|
28604
|
+
'FORMAT',
|
|
28605
|
+
'FORMATS',
|
|
28606
|
+
'TEMPLATE',
|
|
28607
|
+
'TEMPLATES',
|
|
28608
|
+
'WRITING SAMPLE',
|
|
28609
|
+
'WRITING RULES',
|
|
28610
|
+
'SAMPLE',
|
|
28611
|
+
'EXAMPLE',
|
|
28612
|
+
'SCENARIO',
|
|
28613
|
+
'SCENARIOS',
|
|
28614
|
+
'MESSAGE',
|
|
28615
|
+
'MESSAGES',
|
|
28616
|
+
'MESSAGE SUFFIX',
|
|
28617
|
+
'USER MESSAGE',
|
|
28618
|
+
'AGENT MESSAGE',
|
|
28619
|
+
'INTERNAL MESSAGE',
|
|
28620
|
+
'OPEN',
|
|
28621
|
+
'CLOSED',
|
|
28622
|
+
]);
|
|
28623
|
+
/**
|
|
28624
|
+
* Creates one standalone markdown guide for Book language (Book 2.0 / agent language).
|
|
28625
|
+
*
|
|
28626
|
+
* The output intentionally combines:
|
|
28627
|
+
* - static conceptual building blocks maintained in this repository
|
|
28628
|
+
* - dynamically generated commitment catalog from runtime commitment definitions
|
|
28629
|
+
* so docs stay up-to-date by design.
|
|
28630
|
+
*
|
|
28631
|
+
* @returns Full standalone markdown document.
|
|
28632
|
+
*
|
|
28633
|
+
* @public exported from `@promptbook/core`
|
|
28634
|
+
*/
|
|
28635
|
+
function createStandaloneBookLanguageMarkdown() {
|
|
28636
|
+
const groupedCommitments = getGroupedCommitmentDefinitions();
|
|
28637
|
+
const generatedAtIso = new Date().toISOString();
|
|
28638
|
+
const placeholderCommitmentCount = groupedCommitments.filter(({ primary }) => primary instanceof NotYetImplementedCommitmentDefinition).length;
|
|
28639
|
+
const implementedCommitmentCount = groupedCommitments.length - placeholderCommitmentCount;
|
|
28640
|
+
const allCommitmentKeywords = groupedCommitments.flatMap(({ primary, aliases }) => [primary.type, ...aliases]);
|
|
28641
|
+
const toolingCommitments = groupedCommitments.filter(({ primary }) => TOOLING_COMMITMENT_TYPES.has(primary.type));
|
|
28642
|
+
const profileCommitments = groupedCommitments.filter(({ primary }) => PROFILE_COMMITMENT_TYPES.has(primary.type));
|
|
28643
|
+
const compositionCommitments = groupedCommitments.filter(({ primary }) => COMPOSITION_COMMITMENT_TYPES.has(primary.type));
|
|
28644
|
+
const behaviorCommitments = groupedCommitments.filter(({ primary }) => BEHAVIOR_COMMITMENT_TYPES.has(primary.type));
|
|
28645
|
+
return spacetrim.spaceTrim(
|
|
28646
|
+
// [✨]
|
|
28647
|
+
(block) => `
|
|
28648
|
+
# Book Language blueprint
|
|
28649
|
+
|
|
28650
|
+
> Canonical standalone guide for Promptbook Book Agent language.
|
|
28651
|
+
> Generated from repository https://github.com/webgptorg/promptbook
|
|
28652
|
+
|
|
28653
|
+
- Book language version: \`${BOOK_LANGUAGE_VERSION}\`
|
|
28654
|
+
- Generated at: \`${generatedAtIso}\`
|
|
28655
|
+
- Commitment groups: \`${groupedCommitments.length}\`
|
|
28656
|
+
- Implemented commitments: \`${implementedCommitmentCount}\`
|
|
28657
|
+
- Placeholder commitments: \`${placeholderCommitmentCount}\`
|
|
28658
|
+
|
|
28659
|
+
## <a id="table-of-contents"></a>Table of Contents
|
|
28660
|
+
|
|
28661
|
+
- [What Book language is](#what-book-language-is)
|
|
28662
|
+
- [Execution and compilation model](#execution-and-compilation-model)
|
|
28663
|
+
- [Mental model of an agent](#mental-model-of-an-agent)
|
|
28664
|
+
- [How to structure good agents](#how-to-structure-good-agents)
|
|
28665
|
+
- [Primitives and constructs reference](#primitives-and-constructs-reference)
|
|
28666
|
+
- [Commitment catalog (all commitments)](#commitment-catalog-all-commitments)
|
|
28667
|
+
- [End-to-end examples](#end-to-end-examples)
|
|
28668
|
+
- [Do nots and common pitfalls](#do-nots-and-common-pitfalls)
|
|
28669
|
+
- [Build an agent from scratch (offline tutorial)](#build-an-agent-from-scratch-offline-tutorial)
|
|
28670
|
+
|
|
28671
|
+
## <a id="what-book-language-is"></a>What Book language is
|
|
28672
|
+
|
|
28673
|
+
Book language is a domain-specific language for defining **AI agents** as plain-text source.
|
|
28674
|
+
It solves these problems:
|
|
28675
|
+
|
|
28676
|
+
- **One editable source of truth** for agent behavior, tools, memory, and profile metadata.
|
|
28677
|
+
- **Composable agent architecture** through commitments like \`FROM\`, \`IMPORT\`, and \`TEAM\`.
|
|
28678
|
+
- **Deterministic runtime preparation** where source is parsed and compiled into model requirements.
|
|
28679
|
+
- **Portable agent definitions** that can be copied, versioned, and reviewed as text.
|
|
28680
|
+
|
|
28681
|
+
In this repository, "Book language" means **Book 2.0 agent language**.
|
|
28682
|
+
|
|
28683
|
+
## <a id="execution-and-compilation-model"></a>Execution and compilation model
|
|
28684
|
+
|
|
28685
|
+
Promptbook and Agents Server use two core passes:
|
|
28686
|
+
|
|
28687
|
+
1. **Fast parse pass** (\`parseAgentSource\`):
|
|
28688
|
+
It synchronously extracts agent profile/basic info (name, last goal/profile text, meta, capabilities, samples, references).
|
|
28689
|
+
2. **Compilation pass** (\`createAgentModelRequirements\`):
|
|
28690
|
+
It applies commitments in sequence and builds executable model requirements (system message, tools, memory/tool metadata, imports, etc.).
|
|
28691
|
+
|
|
28692
|
+
In Agents Server, the runtime flow typically includes:
|
|
28693
|
+
|
|
28694
|
+
1. Resolve scoped references (including in-book references like \`{Some Agent}\`).
|
|
28695
|
+
2. Resolve inheritance/import chains into effective source.
|
|
28696
|
+
3. Compile effective source into model requirements.
|
|
28697
|
+
4. Execute chat turns with resolved tools and runtime adapters.
|
|
28698
|
+
|
|
28699
|
+
## <a id="mental-model-of-an-agent"></a>Mental model of an agent
|
|
28700
|
+
|
|
28701
|
+
Think of one agent source as four layers:
|
|
28702
|
+
|
|
28703
|
+
1. **Identity/Profile layer**:
|
|
28704
|
+
Agent name (first non-commitment line), the last \`GOAL\` (preferred) or deprecated \`PERSONA\`, and \`META*\` commitments.
|
|
28705
|
+
2. **Behavior layer**:
|
|
28706
|
+
\`RULE\`, \`KNOWLEDGE\`, \`WRITING SAMPLE\`, \`WRITING RULES\`, deprecated \`STYLE\`, \`FORMAT\`, \`TEMPLATE\`, \`LANGUAGE\`, \`GOAL\`, and related commitments.
|
|
28707
|
+
3. **Capability layer**:
|
|
28708
|
+
\`USE*\`, \`MEMORY\`, and other tooling commitments exposing runtime abilities.
|
|
28709
|
+
4. **Composition layer**:
|
|
28710
|
+
\`FROM\` inheritance, \`IMPORT\` reuse, and \`TEAM\` delegation.
|
|
28711
|
+
|
|
28712
|
+
Agent composition commitments in current runtime:
|
|
28713
|
+
|
|
28714
|
+
- Profile-centric commitments detected: ${profileCommitments
|
|
28715
|
+
.map(({ primary }) => `\`${primary.type}\``)
|
|
28716
|
+
.join(', ')}
|
|
28717
|
+
- Behavior-centric commitments detected: ${behaviorCommitments
|
|
28718
|
+
.map(({ primary }) => `\`${primary.type}\``)
|
|
28719
|
+
.join(', ')}
|
|
28720
|
+
- Tool/runtime commitments detected: ${toolingCommitments
|
|
28721
|
+
.map(({ primary }) => `\`${primary.type}\``)
|
|
28722
|
+
.join(', ')}
|
|
28723
|
+
- Composition commitments detected: ${compositionCommitments
|
|
28724
|
+
.map(({ primary }) => `\`${primary.type}\``)
|
|
28725
|
+
.join(', ')}
|
|
28726
|
+
|
|
28727
|
+
### META commitments and agent profile
|
|
28728
|
+
|
|
28729
|
+
\`META*\` commitments control profile data shown in UI (for example avatar visual, image, description, disclaimers, domain, input placeholder).
|
|
28730
|
+
They generally shape presentation/metadata rather than tool behavior.
|
|
28731
|
+
|
|
28732
|
+
### FROM inheritance
|
|
28733
|
+
|
|
28734
|
+
\`FROM\` points to a parent agent source. During inheritance resolution:
|
|
28735
|
+
|
|
28736
|
+
- Parent corpus is merged into effective source.
|
|
28737
|
+
- \`FROM {Void}\` / \`FROM VOID\` means explicit "no parent".
|
|
28738
|
+
- Missing references are surfaced as notes in resolved source.
|
|
28739
|
+
|
|
28740
|
+
### TEAM and IMPORT
|
|
28741
|
+
|
|
28742
|
+
- \`TEAM\` registers teammate agents as callable tools.
|
|
28743
|
+
- \`IMPORT\` injects imported agent/file content into current agent context.
|
|
28744
|
+
- In Agents Server, compact references like \`{Legal Reviewer}\` can resolve to embedded in-book agents.
|
|
28745
|
+
|
|
28746
|
+
### USE commitments
|
|
28747
|
+
|
|
28748
|
+
\`USE*\` commitments enable capabilities (search, browser, project integration, email, image generation, etc.).
|
|
28749
|
+
They expose runtime tools and system-message guidance used during execution.
|
|
28750
|
+
|
|
28751
|
+
## <a id="how-to-structure-good-agents"></a>How to structure good agents
|
|
28752
|
+
|
|
28753
|
+
Recommended patterns and tradeoffs:
|
|
28754
|
+
|
|
28755
|
+
1. **Single clear role first**:
|
|
28756
|
+
Start with one narrow \`GOAL\`; use \`PERSONA\` only for backward-compatible legacy books.
|
|
28757
|
+
Tradeoff: less initial flexibility, much higher reliability.
|
|
28758
|
+
2. **Guardrails early**:
|
|
28759
|
+
Add concrete \`RULE\` commitments before adding many tools.
|
|
28760
|
+
Tradeoff: more upfront design, fewer runtime surprises.
|
|
28761
|
+
3. **Grounding over improvisation**:
|
|
28762
|
+
Prefer \`KNOWLEDGE\` + explicit citation rule for high-stakes answers.
|
|
28763
|
+
Tradeoff: extra maintenance for sources, better factual control.
|
|
28764
|
+
4. **Composition over monoliths**:
|
|
28765
|
+
Use \`TEAM\`/\`IMPORT\` for specialized responsibilities.
|
|
28766
|
+
Tradeoff: orchestration overhead, stronger modularity and reuse.
|
|
28767
|
+
5. **Controlled memory**:
|
|
28768
|
+
If using \`MEMORY\`, define what must and must not be remembered.
|
|
28769
|
+
Tradeoff: stricter policy design, better privacy and signal quality.
|
|
28770
|
+
|
|
28771
|
+
## <a id="primitives-and-constructs-reference"></a>Primitives and constructs reference
|
|
28772
|
+
|
|
28773
|
+
### Core syntax primitives
|
|
28774
|
+
|
|
28775
|
+
1. **Agent title**:
|
|
28776
|
+
First non-empty line that is not a commitment keyword.
|
|
28777
|
+
2. **Commitment block**:
|
|
28778
|
+
Starts with a commitment keyword and continues until the next commitment block or separator.
|
|
28779
|
+
3. **Horizontal separator**:
|
|
28780
|
+
Lines like \`---\` split sections; in Agents Server they can delimit embedded in-book agents.
|
|
28781
|
+
4. **Code fences**:
|
|
28782
|
+
Preserved inside commitment content; useful for examples/instructions.
|
|
28783
|
+
5. **Parameters**:
|
|
28784
|
+
Both \`@parameter\` and \`{parameter}\` notations are supported and parsed.
|
|
28785
|
+
|
|
28786
|
+
### Reference tokens and pseudo-agents
|
|
28787
|
+
|
|
28788
|
+
- Compact references like \`{Agent Name}\` are resolved by Agents Server reference resolver.
|
|
28789
|
+
- Pseudo-agent forms (for example \`{User}\`, \`{Void}\`) are supported in relevant commitments.
|
|
28790
|
+
- \`{User}\` is intended for \`TEAM\`; \`{Void}\` is useful for explicit no-parent inheritance.
|
|
28791
|
+
|
|
28792
|
+
### Commitment keywords currently recognized
|
|
28793
|
+
|
|
28794
|
+
${block(getSafeCodeBlock(allCommitmentKeywords.join(', '), 'text'))}
|
|
28795
|
+
|
|
28796
|
+
## <a id="commitment-catalog-all-commitments"></a>Commitment catalog (all commitments)
|
|
28797
|
+
|
|
28798
|
+
This section is generated from commitment definitions in \`src/commitments\`.
|
|
28799
|
+
For each commitment group you get:
|
|
28800
|
+
|
|
28801
|
+
- semantics summary (description/icon/status)
|
|
28802
|
+
- parsing schema (\`createTypeRegex\` and \`createRegex\`)
|
|
28803
|
+
- canonical documentation block
|
|
28804
|
+
|
|
28805
|
+
${block(groupedCommitments.map(renderCommitmentCatalogSection).join('\n\n'))}
|
|
28806
|
+
|
|
28807
|
+
## <a id="end-to-end-examples"></a>End-to-end examples
|
|
28808
|
+
|
|
28809
|
+
${block(bookLanguageDocumentationExamples.map(renderExampleSection).join('\n\n'))}
|
|
28810
|
+
|
|
28811
|
+
## <a id="do-nots-and-common-pitfalls"></a>Do nots and common pitfalls
|
|
28812
|
+
|
|
28813
|
+
${block(bookLanguageCommonPitfalls
|
|
28814
|
+
.map((pitfall, index) => spacetrim.spaceTrim(`
|
|
28815
|
+
${index + 1}. **${pitfall.title}**
|
|
28816
|
+
- Don't: ${pitfall.dont}
|
|
28817
|
+
- Do instead: ${pitfall.doInstead}
|
|
28818
|
+
`))
|
|
28819
|
+
.join('\n'))}
|
|
28820
|
+
|
|
28821
|
+
## <a id="build-an-agent-from-scratch-offline-tutorial"></a>Build an agent from scratch (offline tutorial)
|
|
28822
|
+
|
|
28823
|
+
This tutorial is sufficient without internet access.
|
|
28824
|
+
|
|
28825
|
+
1. **Define role and goal**
|
|
28826
|
+
Create a short name line and one clear \`GOAL\`.
|
|
28827
|
+
2. **Add behavioral constraints**
|
|
28828
|
+
Add 3-6 specific \`RULE\` commitments covering scope, tone, and safety boundaries.
|
|
28829
|
+
3. **Add grounding**
|
|
28830
|
+
Add \`KNOWLEDGE\` commitments (inline text or local/importable sources).
|
|
28831
|
+
4. **Add capabilities**
|
|
28832
|
+
Add only necessary \`USE*\` and/or \`MEMORY\` commitments.
|
|
28833
|
+
5. **Set profile metadata**
|
|
28834
|
+
Add \`META DESCRIPTION\`, \`META AVATAR\` or \`META IMAGE\`, \`META INPUT PLACEHOLDER\`, and disclaimers if needed.
|
|
28835
|
+
6. **Add first interaction**
|
|
28836
|
+
Add \`INITIAL MESSAGE\` and optionally sample \`USER MESSAGE\` / \`AGENT MESSAGE\` pairs.
|
|
28837
|
+
7. **Close for deterministic behavior (optional)**
|
|
28838
|
+
Add \`CLOSED\` when you want stable non-self-modifying behavior.
|
|
28839
|
+
|
|
28840
|
+
Copy-paste template:
|
|
28841
|
+
|
|
28842
|
+
${block(getSafeCodeBlock(spacetrim.spaceTrim(`
|
|
28843
|
+
Project Assistant
|
|
28844
|
+
|
|
28845
|
+
GOAL Help the user turn project ideas into concrete deliverables with focused planning support.
|
|
28846
|
+
|
|
28847
|
+
RULE Ask clarifying questions when requirements are ambiguous.
|
|
28848
|
+
RULE Provide concise, structured outputs with actionable steps.
|
|
28849
|
+
RULE If information is missing, state assumptions explicitly.
|
|
28850
|
+
RULE Do not invent facts.
|
|
28851
|
+
|
|
28852
|
+
KNOWLEDGE Team works in two-week sprints and tracks tasks in Kanban.
|
|
28853
|
+
KNOWLEDGE Preferred output format: summary, plan, risks, next action.
|
|
28854
|
+
|
|
28855
|
+
META DESCRIPTION Practical project-planning assistant.
|
|
28856
|
+
META INPUT PLACEHOLDER Describe your project goal or blocker...
|
|
28857
|
+
|
|
28858
|
+
INITIAL MESSAGE Share your project goal and current blocker, and I will propose a concrete next-step plan.
|
|
28859
|
+
CLOSED
|
|
28860
|
+
`), 'book'))}
|
|
28861
|
+
|
|
28862
|
+
Validation checklist:
|
|
28863
|
+
|
|
28864
|
+
- Does each commitment have a clear purpose?
|
|
28865
|
+
- Are there explicit constraints against hallucination and unsafe behavior?
|
|
28866
|
+
- Are tools only enabled when genuinely needed?
|
|
28867
|
+
- Is memory usage bounded by clear rules?
|
|
28868
|
+
- Is composition (\`FROM\`/\`TEAM\`/\`IMPORT\`) justified and understandable?
|
|
28869
|
+
|
|
28870
|
+
---
|
|
28871
|
+
|
|
28872
|
+
Generated from:
|
|
28873
|
+
|
|
28874
|
+
- Commitments registry and runtime docs in \`src/commitments\`
|
|
28875
|
+
- Parser/compiler behavior in \`src/book-2.0/agent-source\`
|
|
28876
|
+
- Agents Server reference/inheritance resolution in \`apps/agents-server/src/utils\`
|
|
28877
|
+
- Standalone docs source blocks in \`apps/agents-server/src/utils/bookLanguageDocumentation\`
|
|
28878
|
+
`);
|
|
28879
|
+
}
|
|
28880
|
+
/**
|
|
28881
|
+
* Renders one commitment section in the generated catalog.
|
|
28882
|
+
*
|
|
28883
|
+
* @param groupedCommitment - Grouped commitment definition with aliases.
|
|
28884
|
+
* @returns Markdown section for a single commitment.
|
|
28885
|
+
*
|
|
28886
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28887
|
+
*/
|
|
28888
|
+
function renderCommitmentCatalogSection(groupedCommitment) {
|
|
28889
|
+
var _a;
|
|
28890
|
+
const { primary, aliases } = groupedCommitment;
|
|
28891
|
+
const notice = getCommitmentNoticeMetadata(primary);
|
|
28892
|
+
const status = primary instanceof NotYetImplementedCommitmentDefinition
|
|
28893
|
+
? 'Placeholder (not fully implemented)'
|
|
28894
|
+
: notice
|
|
28895
|
+
? `Implemented (${notice.detailLabel})`
|
|
28896
|
+
: 'Implemented';
|
|
28897
|
+
const aliasText = aliases.length === 0 ? 'None' : aliases.map((alias) => `\`${alias}\``).join(', ');
|
|
28898
|
+
const noticeText = notice
|
|
28899
|
+
? notice.kind === 'deprecated'
|
|
28900
|
+
? `- **Deprecation:** ${notice.message}${formatCommitmentReplacementText((_a = primary.deprecation) === null || _a === void 0 ? void 0 : _a.replacedBy)}`
|
|
28901
|
+
: `- **Low-level commitment:** ${notice.message}`
|
|
28902
|
+
: '';
|
|
28903
|
+
const documentationMarkdown = renderGroupedCommitmentDocumentationMarkdown(groupedCommitment);
|
|
28904
|
+
return spacetrim.spaceTrim((block) => `
|
|
28905
|
+
### <a id="commitment-${toStableAnchorId(primary.type)}"></a>${primary.icon} ${primary.type}
|
|
28906
|
+
|
|
28907
|
+
- **Status:** ${status}
|
|
28908
|
+
- **Aliases:** ${aliasText}
|
|
28909
|
+
- **Semantics:** ${primary.description}
|
|
28910
|
+
- **Type schema (\`createTypeRegex\`):** \`${stringifyRegex(primary.createTypeRegex())}\`
|
|
28911
|
+
- **Block schema (\`createRegex\`):** \`${stringifyRegex(primary.createRegex())}\`
|
|
28912
|
+
${noticeText}
|
|
28913
|
+
|
|
28914
|
+
${block(documentationMarkdown)}
|
|
28915
|
+
`);
|
|
28916
|
+
}
|
|
28917
|
+
/**
|
|
28918
|
+
* Renders one end-to-end example section.
|
|
28919
|
+
*
|
|
28920
|
+
* @param example - Example definition.
|
|
28921
|
+
* @returns Markdown section for one example.
|
|
28922
|
+
*
|
|
28923
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28924
|
+
*/
|
|
28925
|
+
function renderExampleSection(example) {
|
|
28926
|
+
return spacetrim.spaceTrim((block) => `
|
|
28927
|
+
### <a id="example-${toStableAnchorId(example.id)}"></a>${example.title}
|
|
28928
|
+
|
|
28929
|
+
**Goal:** ${example.goal}
|
|
28930
|
+
|
|
28931
|
+
**Full source**
|
|
28932
|
+
|
|
28933
|
+
${block(getSafeCodeBlock(example.source, 'book'))}
|
|
28934
|
+
|
|
28935
|
+
**Walkthrough**
|
|
28936
|
+
|
|
28937
|
+
${block(example.walkthrough.map((step, index) => `${index + 1}. ${step}`).join('\n'))}
|
|
28938
|
+
`);
|
|
28939
|
+
}
|
|
28940
|
+
/**
|
|
28941
|
+
* Converts a heading label into a stable markdown anchor id.
|
|
28942
|
+
*
|
|
28943
|
+
* @param value - Raw heading/identifier text.
|
|
28944
|
+
* @returns Stable lowercase anchor id.
|
|
28945
|
+
*
|
|
28946
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28947
|
+
*/
|
|
28948
|
+
function toStableAnchorId(value) {
|
|
28949
|
+
return value
|
|
28950
|
+
.trim()
|
|
28951
|
+
.toLowerCase()
|
|
28952
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
28953
|
+
.replace(/^-+|-+$/g, '');
|
|
28954
|
+
}
|
|
28955
|
+
/**
|
|
28956
|
+
* Converts a regular expression into a concise literal-like string.
|
|
28957
|
+
*
|
|
28958
|
+
* @param regex - Regex instance.
|
|
28959
|
+
* @returns Printable regex pattern and flags.
|
|
28960
|
+
*
|
|
28961
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28962
|
+
*/
|
|
28963
|
+
function stringifyRegex(regex) {
|
|
28964
|
+
return `/${regex.source}/${regex.flags}`;
|
|
28965
|
+
}
|
|
28966
|
+
/**
|
|
28967
|
+
* Creates a safe markdown fenced code block even when content contains backticks.
|
|
28968
|
+
*
|
|
28969
|
+
* @param content - Raw code content.
|
|
28970
|
+
* @param language - Optional info-string language label.
|
|
28971
|
+
* @returns Fenced code block.
|
|
28972
|
+
*
|
|
28973
|
+
* @private internal utility of `createStandaloneBookLanguageMarkdown`
|
|
28974
|
+
*/
|
|
28975
|
+
function getSafeCodeBlock(content, language = 'markdown') {
|
|
28976
|
+
const maxBacktickCount = Math.max(0, ...(content.match(/`+/g) || []).map((match) => match.length));
|
|
28977
|
+
const fence = '`'.repeat(Math.max(3, maxBacktickCount + 1));
|
|
28978
|
+
return `${fence}${language}\n${content}\n${fence}`;
|
|
28979
|
+
}
|
|
28980
|
+
|
|
27701
28981
|
/**
|
|
27702
28982
|
* Generates an image for the agent to use as profile image
|
|
27703
28983
|
*
|
|
@@ -29705,8 +30985,10 @@
|
|
|
29705
30985
|
*/
|
|
29706
30986
|
const MatcherFormfactorDefinition = {
|
|
29707
30987
|
name: 'EXPERIMENTAL_MATCHER',
|
|
29708
|
-
description: `
|
|
29709
|
-
|
|
30988
|
+
description: spacetrim.spaceTrim(`
|
|
30989
|
+
An evaluation system that determines whether content meets specific criteria or patterns.
|
|
30990
|
+
Used for content validation, quality assessment, and intelligent filtering tasks. Currently in experimental phase.
|
|
30991
|
+
`),
|
|
29710
30992
|
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/177`,
|
|
29711
30993
|
pipelineInterface: {
|
|
29712
30994
|
inputParameters: [
|
|
@@ -29763,9 +31045,11 @@
|
|
|
29763
31045
|
*/
|
|
29764
31046
|
const TranslatorFormfactorDefinition = {
|
|
29765
31047
|
name: 'TRANSLATOR',
|
|
29766
|
-
description: `
|
|
29767
|
-
|
|
29768
|
-
|
|
31048
|
+
description: spacetrim.spaceTrim(`
|
|
31049
|
+
A text transformation system that converts input content into different forms,
|
|
31050
|
+
including language translations, paraphrasing, style conversions, and tone adjustments.
|
|
31051
|
+
This form factor takes one input and produces one transformed output.
|
|
31052
|
+
`),
|
|
29769
31053
|
documentationUrl: `https://github.com/webgptorg/promptbook/discussions/175`,
|
|
29770
31054
|
pipelineInterface: {
|
|
29771
31055
|
inputParameters: [
|
|
@@ -31125,12 +32409,21 @@
|
|
|
31125
32409
|
// <- TODO: [🧠] Make this dynamic, async, prepare-phase HLAs
|
|
31126
32410
|
],
|
|
31127
32411
|
});
|
|
31128
|
-
// TODO: Use spaceTrim in multiline strings
|
|
31129
32412
|
$pipelineJson.tasks.push({
|
|
31130
32413
|
taskType: 'PROMPT_TASK',
|
|
31131
32414
|
name: 'create-an-answer',
|
|
31132
32415
|
title: 'Create an answer',
|
|
31133
|
-
content:
|
|
32416
|
+
content: spacetrim.spaceTrim(`
|
|
32417
|
+
Write a response to the user message:
|
|
32418
|
+
|
|
32419
|
+
**Question from user**
|
|
32420
|
+
|
|
32421
|
+
> {userMessage}
|
|
32422
|
+
|
|
32423
|
+
**Previous conversation**
|
|
32424
|
+
|
|
32425
|
+
> {previousConversationSummary}
|
|
32426
|
+
`),
|
|
31134
32427
|
resultingParameterName: 'chatbotResponse',
|
|
31135
32428
|
personaName,
|
|
31136
32429
|
dependentParameterNames: [
|
|
@@ -31142,7 +32435,26 @@
|
|
|
31142
32435
|
taskType: 'PROMPT_TASK',
|
|
31143
32436
|
name: 'summarize-the-conversation',
|
|
31144
32437
|
title: 'Summarize the conversation',
|
|
31145
|
-
content:
|
|
32438
|
+
content: spacetrim.spaceTrim(`
|
|
32439
|
+
Summarize the conversation in a few words:
|
|
32440
|
+
|
|
32441
|
+
## Rules
|
|
32442
|
+
|
|
32443
|
+
- Summarise the text of the conversation in a few words
|
|
32444
|
+
- Convert the text to its basic idea
|
|
32445
|
+
- Imagine you are writing the headline or subject line of an email
|
|
32446
|
+
- Respond with a few words of summary only
|
|
32447
|
+
|
|
32448
|
+
## Conversation
|
|
32449
|
+
|
|
32450
|
+
**User:**
|
|
32451
|
+
|
|
32452
|
+
> {userMessage}
|
|
32453
|
+
|
|
32454
|
+
**You:**
|
|
32455
|
+
|
|
32456
|
+
> {chatbotResponse}
|
|
32457
|
+
`),
|
|
31146
32458
|
resultingParameterName: 'conversationSummary',
|
|
31147
32459
|
personaName,
|
|
31148
32460
|
expectations: {
|
|
@@ -33546,11 +34858,11 @@
|
|
|
33546
34858
|
if (attachments.length === 0) {
|
|
33547
34859
|
return '';
|
|
33548
34860
|
}
|
|
33549
|
-
return
|
|
33550
|
-
CHAT_ATTACHMENTS_HEADING
|
|
33551
|
-
|
|
33552
|
-
CHAT_ATTACHMENTS_INSTRUCTION
|
|
33553
|
-
|
|
34861
|
+
return spacetrim.spaceTrim((block) => `
|
|
34862
|
+
${CHAT_ATTACHMENTS_HEADING}
|
|
34863
|
+
${block(attachments.map((attachment) => formatChatAttachmentLine(attachment)).join('\n'))}
|
|
34864
|
+
${CHAT_ATTACHMENTS_INSTRUCTION}
|
|
34865
|
+
`);
|
|
33554
34866
|
}
|
|
33555
34867
|
|
|
33556
34868
|
/**
|
|
@@ -33791,24 +35103,24 @@
|
|
|
33791
35103
|
: ''}`
|
|
33792
35104
|
: null;
|
|
33793
35105
|
const warningsLine = contentResolution.warnings.length > 0 ? `Warnings: ${contentResolution.warnings.join(' | ')}` : null;
|
|
33794
|
-
|
|
35106
|
+
const metadataLines = [decodingLine, warningsLine].filter((line) => Boolean(line)).join('\n');
|
|
35107
|
+
const resolvedContent = contentResolution.content;
|
|
35108
|
+
if (!resolvedContent) {
|
|
33795
35109
|
const reason = contentResolution.reason || 'content unavailable';
|
|
33796
|
-
return
|
|
33797
|
-
.
|
|
33798
|
-
|
|
35110
|
+
return spacetrim.spaceTrim((block) => `
|
|
35111
|
+
- ${attachmentLabel}: ${reason}. URL: ${contentResolution.attachment.url}
|
|
35112
|
+
${block(metadataLines)}
|
|
35113
|
+
`);
|
|
33799
35114
|
}
|
|
33800
35115
|
const truncatedLabel = contentResolution.isTruncated ? ' [truncated]' : '';
|
|
33801
|
-
return
|
|
33802
|
-
|
|
33803
|
-
|
|
33804
|
-
|
|
33805
|
-
|
|
33806
|
-
|
|
33807
|
-
|
|
33808
|
-
|
|
33809
|
-
]
|
|
33810
|
-
.filter(Boolean)
|
|
33811
|
-
.join('\n');
|
|
35116
|
+
return spacetrim.spaceTrim((block) => `
|
|
35117
|
+
File: ${attachmentLabel}${truncatedLabel}
|
|
35118
|
+
URL: ${contentResolution.attachment.url}
|
|
35119
|
+
${block(metadataLines)}
|
|
35120
|
+
\`\`\`text
|
|
35121
|
+
${block(resolvedContent)}
|
|
35122
|
+
\`\`\`
|
|
35123
|
+
`);
|
|
33812
35124
|
}
|
|
33813
35125
|
/**
|
|
33814
35126
|
* Formats inline attachment-content context section for the model.
|
|
@@ -33822,11 +35134,14 @@
|
|
|
33822
35134
|
if (resolvedContents.length === 0) {
|
|
33823
35135
|
return '';
|
|
33824
35136
|
}
|
|
33825
|
-
return
|
|
33826
|
-
CHAT_ATTACHMENT_CONTENT_HEADING
|
|
33827
|
-
CHAT_ATTACHMENT_CONTENT_INSTRUCTION
|
|
33828
|
-
|
|
33829
|
-
|
|
35137
|
+
return spacetrim.spaceTrim((block) => `
|
|
35138
|
+
${CHAT_ATTACHMENT_CONTENT_HEADING}
|
|
35139
|
+
${CHAT_ATTACHMENT_CONTENT_INSTRUCTION}
|
|
35140
|
+
|
|
35141
|
+
${block(resolvedContents
|
|
35142
|
+
.map((resolvedContent) => formatResolvedChatAttachmentContent(resolvedContent))
|
|
35143
|
+
.join('\n\n'))}
|
|
35144
|
+
`);
|
|
33830
35145
|
}
|
|
33831
35146
|
|
|
33832
35147
|
/**
|
|
@@ -34985,9 +36300,11 @@
|
|
|
34985
36300
|
* Creates the retry-history error message shared by all OpenAI-compatible model variants.
|
|
34986
36301
|
*/
|
|
34987
36302
|
createAttemptHistoryError(finalErrorMessage) {
|
|
34988
|
-
return new PipelineExecutionError(
|
|
34989
|
-
|
|
34990
|
-
|
|
36303
|
+
return new PipelineExecutionError(spacetrim.spaceTrim((block) => `
|
|
36304
|
+
All attempts failed. Attempt history:
|
|
36305
|
+
${block(formatUnsupportedParameterAttemptHistory(this.attemptStack))}
|
|
36306
|
+
Final error: ${finalErrorMessage}
|
|
36307
|
+
`));
|
|
34991
36308
|
}
|
|
34992
36309
|
}
|
|
34993
36310
|
|
|
@@ -37581,7 +38898,7 @@
|
|
|
37581
38898
|
});
|
|
37582
38899
|
}
|
|
37583
38900
|
let vectorStoreId = cachedVectorStoreId;
|
|
37584
|
-
if (
|
|
38901
|
+
if (!vectorStoreId && knowledgeSources && knowledgeSources.length > 0) {
|
|
37585
38902
|
const vectorStoreResult = await this.createVectorStoreWithKnowledgeSources({
|
|
37586
38903
|
client: await this.getClient(),
|
|
37587
38904
|
name,
|
|
@@ -37590,19 +38907,13 @@
|
|
|
37590
38907
|
});
|
|
37591
38908
|
vectorStoreId = vectorStoreResult.vectorStoreId;
|
|
37592
38909
|
}
|
|
37593
|
-
else if (
|
|
38910
|
+
else if (vectorStoreId && this.options.isVerbose) {
|
|
37594
38911
|
console.info('[🤰]', 'Using cached vector store for AgentKit agent', {
|
|
37595
38912
|
name,
|
|
37596
38913
|
vectorStoreId,
|
|
37597
38914
|
});
|
|
37598
38915
|
}
|
|
37599
|
-
|
|
37600
|
-
vectorStoreId = undefined;
|
|
37601
|
-
}
|
|
37602
|
-
const agentKitTools = this.buildAgentKitTools({
|
|
37603
|
-
tools,
|
|
37604
|
-
vectorStoreId,
|
|
37605
|
-
});
|
|
38916
|
+
const agentKitTools = this.buildAgentKitTools({ tools, vectorStoreId });
|
|
37606
38917
|
const openAiAgentKitAgent = new agents.Agent({
|
|
37607
38918
|
name,
|
|
37608
38919
|
model: this.agentKitModelName,
|
|
@@ -37621,7 +38932,7 @@
|
|
|
37621
38932
|
name,
|
|
37622
38933
|
model: this.agentKitModelName,
|
|
37623
38934
|
toolCount: agentKitTools.length,
|
|
37624
|
-
hasVectorStore:
|
|
38935
|
+
hasVectorStore: Boolean(vectorStoreId),
|
|
37625
38936
|
});
|
|
37626
38937
|
}
|
|
37627
38938
|
return preparedAgent;
|
|
@@ -38120,12 +39431,6 @@
|
|
|
38120
39431
|
get agentKitOptions() {
|
|
38121
39432
|
return this.options;
|
|
38122
39433
|
}
|
|
38123
|
-
/**
|
|
38124
|
-
* Returns true when hosted OpenAI vector-store search should back `knowledgeSources`.
|
|
38125
|
-
*/
|
|
38126
|
-
get isNativeKnowledgeSearchEnabled() {
|
|
38127
|
-
return this.agentKitOptions.isNativeKnowledgeSearchEnabled !== false;
|
|
38128
|
-
}
|
|
38129
39434
|
/**
|
|
38130
39435
|
* Discriminant for type guards.
|
|
38131
39436
|
*/
|
|
@@ -42649,7 +43954,7 @@
|
|
|
42649
43954
|
*/
|
|
42650
43955
|
async function prepareSdkTranspilerContext(book, options) {
|
|
42651
43956
|
const { agentName } = await parseAgentSource(book);
|
|
42652
|
-
const
|
|
43957
|
+
const modelRequirements = await createAgentModelRequirements(book, undefined, undefined, undefined, {
|
|
42653
43958
|
agentReferenceResolver: options === null || options === void 0 ? void 0 : options.agentReferenceResolver,
|
|
42654
43959
|
inlineKnowledgeSourceUploader: options === null || options === void 0 ? void 0 : options.inlineKnowledgeSourceUploader,
|
|
42655
43960
|
teammateProfileResolver: options === null || options === void 0 ? void 0 : options.teammateProfileResolver,
|
|
@@ -42659,12 +43964,7 @@
|
|
|
42659
43964
|
const knowledgeContent = knowledgeCommitments.map((commitment) => commitment.content.trim());
|
|
42660
43965
|
const directKnowledge = knowledgeContent.filter((content) => !isKnowledgeSourceUrl(content));
|
|
42661
43966
|
const knowledgeSources = knowledgeContent.filter((content) => isKnowledgeSourceUrl(content));
|
|
42662
|
-
const isKnowledgeHandledWithRetrieval = directKnowledge.join('\n').length > SDK_TRANSPILER_KNOWLEDGE_THRESHOLD ||
|
|
42663
|
-
knowledgeSources.length > 0 ||
|
|
42664
|
-
knowledgeCommitments.length > 0;
|
|
42665
|
-
const modelRequirements = normalizeSdkTranspilerModelRequirements(rawModelRequirements, {
|
|
42666
|
-
isKnowledgeHandledWithRetrieval,
|
|
42667
|
-
});
|
|
43967
|
+
const isKnowledgeHandledWithRetrieval = directKnowledge.join('\n').length > SDK_TRANSPILER_KNOWLEDGE_THRESHOLD || knowledgeSources.length > 0;
|
|
42668
43968
|
const transpiledTeam = createTranspiledTeamExportForContext({
|
|
42669
43969
|
agentName,
|
|
42670
43970
|
agentSource: book,
|
|
@@ -42682,36 +43982,6 @@
|
|
|
42682
43982
|
transpiledTeam,
|
|
42683
43983
|
};
|
|
42684
43984
|
}
|
|
42685
|
-
/**
|
|
42686
|
-
* Removes the runtime-only knowledge-search tool from SDK harnesses that provide
|
|
42687
|
-
* their own generated retrieval scaffold.
|
|
42688
|
-
*
|
|
42689
|
-
* @param modelRequirements - Raw compiled model requirements.
|
|
42690
|
-
* @param options - Knowledge handling mode selected for the generated harness.
|
|
42691
|
-
* @returns Model requirements safe to embed into a standalone SDK export.
|
|
42692
|
-
*/
|
|
42693
|
-
function normalizeSdkTranspilerModelRequirements(modelRequirements, options) {
|
|
42694
|
-
var _a;
|
|
42695
|
-
if (!options.isKnowledgeHandledWithRetrieval) {
|
|
42696
|
-
return modelRequirements;
|
|
42697
|
-
}
|
|
42698
|
-
const tools = (_a = modelRequirements.tools) === null || _a === void 0 ? void 0 : _a.filter((tool) => tool.name !== KNOWLEDGE_SEARCH_TOOL_NAME);
|
|
42699
|
-
return {
|
|
42700
|
-
...modelRequirements,
|
|
42701
|
-
systemMessage: removeKnowledgeSearchSystemSection(modelRequirements.systemMessage),
|
|
42702
|
-
...(tools ? { tools } : {}),
|
|
42703
|
-
};
|
|
42704
|
-
}
|
|
42705
|
-
/**
|
|
42706
|
-
* Removes the generated `## Knowledge Search` instructions from SDK exports
|
|
42707
|
-
* that answer with the transpiler's native retrieval scaffold instead.
|
|
42708
|
-
*
|
|
42709
|
-
* @param systemMessage - Raw system message from compiled model requirements.
|
|
42710
|
-
* @returns System message without the runtime-only knowledge-search section.
|
|
42711
|
-
*/
|
|
42712
|
-
function removeKnowledgeSearchSystemSection(systemMessage) {
|
|
42713
|
-
return systemMessage.replace(/(?:^|\n\n)## Knowledge Search[\s\S]*?(?=\n\n##|$)/, '').trim();
|
|
42714
|
-
}
|
|
42715
43985
|
/**
|
|
42716
43986
|
* Detects whether one knowledge commitment points to a URL instead of inline text.
|
|
42717
43987
|
*
|
|
@@ -45455,7 +46725,6 @@
|
|
|
45455
46725
|
exports.GenericFormfactorDefinition = GenericFormfactorDefinition;
|
|
45456
46726
|
exports.HTTP_STATUS_CODES = HTTP_STATUS_CODES;
|
|
45457
46727
|
exports.ImageGeneratorFormfactorDefinition = ImageGeneratorFormfactorDefinition;
|
|
45458
|
-
exports.KNOWLEDGE_SEARCH_TOOL_NAME = KNOWLEDGE_SEARCH_TOOL_NAME;
|
|
45459
46728
|
exports.KnowledgeScrapeError = KnowledgeScrapeError;
|
|
45460
46729
|
exports.LIMITS = LIMITS;
|
|
45461
46730
|
exports.LimitReachedError = LimitReachedError;
|
|
@@ -45551,6 +46820,7 @@
|
|
|
45551
46820
|
exports.createPipelineCollectionFromUrl = createPipelineCollectionFromUrl;
|
|
45552
46821
|
exports.createPipelineExecutor = createPipelineExecutor;
|
|
45553
46822
|
exports.createPipelineSubcollection = createPipelineSubcollection;
|
|
46823
|
+
exports.createStandaloneBookLanguageMarkdown = createStandaloneBookLanguageMarkdown;
|
|
45554
46824
|
exports.embeddingVectorToString = embeddingVectorToString;
|
|
45555
46825
|
exports.executionReportJsonToString = executionReportJsonToString;
|
|
45556
46826
|
exports.extractParameterNamesFromTask = extractParameterNamesFromTask;
|