@promptbook/javascript 0.105.0-14 → 0.105.0-16
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 +506 -17
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -1
- package/esm/typings/src/book-2.0/agent-source/parseTeamCommitment.d.ts +28 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +2 -7
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +1 -6
- package/esm/typings/src/book-components/Chat/Chat/ClockIcon.d.ts +9 -0
- package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +10 -37
- package/esm/typings/src/book-components/Chat/utils/getToolCallChipletText.d.ts +2 -5
- package/esm/typings/src/book-components/Chat/utils/toolCallParsing.d.ts +64 -0
- package/esm/typings/src/book-components/icons/SettingsIcon.d.ts +11 -0
- package/esm/typings/src/commitments/TEAM/TEAM.d.ts +45 -0
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +1 -0
- package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +2 -0
- package/esm/typings/src/commitments/_base/formatOptionalInstructionBlock.d.ts +6 -0
- package/esm/typings/src/commitments/index.d.ts +2 -1
- package/esm/typings/src/constants.d.ts +125 -0
- package/esm/typings/src/execution/PromptResult.d.ts +2 -19
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -0
- package/esm/typings/src/types/ToolCall.d.ts +37 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +4 -2
- package/umd/index.umd.js +509 -19
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import 'path';
|
|
3
3
|
import { randomBytes } from 'crypto';
|
|
4
|
-
import 'crypto-js';
|
|
5
|
-
import 'crypto-js/enc-hex';
|
|
4
|
+
import { SHA256 } from 'crypto-js';
|
|
5
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
6
|
+
import moment from 'moment';
|
|
6
7
|
|
|
7
8
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
8
9
|
/**
|
|
@@ -18,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
18
19
|
* @generated
|
|
19
20
|
* @see https://github.com/webgptorg/promptbook
|
|
20
21
|
*/
|
|
21
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-16';
|
|
22
23
|
/**
|
|
23
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
24
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1924,6 +1925,19 @@ class PipelineExecutionError extends Error {
|
|
|
1924
1925
|
* TODO: [🧠][🌂] Add id to all errors
|
|
1925
1926
|
*/
|
|
1926
1927
|
|
|
1928
|
+
/**
|
|
1929
|
+
* Error thrown when a fetch request fails
|
|
1930
|
+
*
|
|
1931
|
+
* @public exported from `@promptbook/core`
|
|
1932
|
+
*/
|
|
1933
|
+
class PromptbookFetchError extends Error {
|
|
1934
|
+
constructor(message) {
|
|
1935
|
+
super(message);
|
|
1936
|
+
this.name = 'PromptbookFetchError';
|
|
1937
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1927
1941
|
/**
|
|
1928
1942
|
* Index of all javascript errors
|
|
1929
1943
|
*
|
|
@@ -2032,6 +2046,18 @@ function valueToString(value) {
|
|
|
2032
2046
|
}
|
|
2033
2047
|
}
|
|
2034
2048
|
|
|
2049
|
+
/**
|
|
2050
|
+
* Computes SHA-256 hash of the given object
|
|
2051
|
+
*
|
|
2052
|
+
* @public exported from `@promptbook/utils`
|
|
2053
|
+
*/
|
|
2054
|
+
function computeHash(value) {
|
|
2055
|
+
return SHA256(hexEncoder.parse(spaceTrim$2(valueToString(value)))).toString( /* hex */);
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* TODO: [🥬][🥬] Use this ACRY
|
|
2059
|
+
*/
|
|
2060
|
+
|
|
2035
2061
|
/**
|
|
2036
2062
|
* Makes first letter of a string uppercase
|
|
2037
2063
|
*
|
|
@@ -5325,6 +5351,432 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5325
5351
|
* [💞] Ignore a discrepancy between file name and entity name
|
|
5326
5352
|
*/
|
|
5327
5353
|
|
|
5354
|
+
const urlRegex = /https?:\/\/[^\s]+/gi;
|
|
5355
|
+
const trailingPunctuationRegex = /[),.;!?]+$/;
|
|
5356
|
+
const clauseSeparators = ['.', '?', '!', ';', ','];
|
|
5357
|
+
const conjunctionSeparators = [' and ', ' or '];
|
|
5358
|
+
/**
|
|
5359
|
+
* Parses TEAM commitment content into teammates with instructions.
|
|
5360
|
+
*
|
|
5361
|
+
* @private
|
|
5362
|
+
*/
|
|
5363
|
+
function parseTeamCommitmentContent(content, options = {}) {
|
|
5364
|
+
const { strict = false } = options;
|
|
5365
|
+
const lines = content
|
|
5366
|
+
.split('\n')
|
|
5367
|
+
.map((line) => line.trim())
|
|
5368
|
+
.filter(Boolean);
|
|
5369
|
+
const teammates = [];
|
|
5370
|
+
const seenUrls = new Set();
|
|
5371
|
+
for (const line of lines) {
|
|
5372
|
+
const matches = Array.from(line.matchAll(urlRegex));
|
|
5373
|
+
if (matches.length === 0) {
|
|
5374
|
+
if (strict) {
|
|
5375
|
+
throw new Error(`TEAM commitment expects at least one agent URL, got: "${line}"`);
|
|
5376
|
+
}
|
|
5377
|
+
continue;
|
|
5378
|
+
}
|
|
5379
|
+
for (const [matchIndex, match] of matches.entries()) {
|
|
5380
|
+
const rawUrl = match[0] || '';
|
|
5381
|
+
const cleanedUrl = rawUrl.replace(trailingPunctuationRegex, '');
|
|
5382
|
+
if (!isValidAgentUrl(cleanedUrl)) {
|
|
5383
|
+
if (strict) {
|
|
5384
|
+
throw new Error(`Invalid agent URL in TEAM commitment: "${cleanedUrl}"`);
|
|
5385
|
+
}
|
|
5386
|
+
continue;
|
|
5387
|
+
}
|
|
5388
|
+
if (seenUrls.has(cleanedUrl)) {
|
|
5389
|
+
continue;
|
|
5390
|
+
}
|
|
5391
|
+
seenUrls.add(cleanedUrl);
|
|
5392
|
+
const instructionContext = extractInstructionContext(line, matches, matchIndex);
|
|
5393
|
+
const instructions = normalizeInstructionText(instructionContext);
|
|
5394
|
+
const label = createTeammateLabel(cleanedUrl);
|
|
5395
|
+
teammates.push({
|
|
5396
|
+
url: cleanedUrl,
|
|
5397
|
+
label,
|
|
5398
|
+
instructions,
|
|
5399
|
+
});
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
return teammates;
|
|
5403
|
+
}
|
|
5404
|
+
function extractInstructionContext(line, matches, matchIndex) {
|
|
5405
|
+
var _a;
|
|
5406
|
+
const match = matches[matchIndex];
|
|
5407
|
+
if (!match || match.index === undefined) {
|
|
5408
|
+
return line.trim();
|
|
5409
|
+
}
|
|
5410
|
+
const rawUrl = match[0] || '';
|
|
5411
|
+
const matchStart = match.index;
|
|
5412
|
+
const matchEnd = matchStart + rawUrl.length;
|
|
5413
|
+
const previousMatch = matches[matchIndex - 1];
|
|
5414
|
+
const nextMatch = matches[matchIndex + 1];
|
|
5415
|
+
const previousEnd = previousMatch && previousMatch.index !== undefined ? previousMatch.index + (((_a = previousMatch[0]) === null || _a === void 0 ? void 0 : _a.length) || 0) : 0;
|
|
5416
|
+
const nextStart = nextMatch && nextMatch.index !== undefined ? nextMatch.index : line.length;
|
|
5417
|
+
const rawPrefix = line.slice(previousEnd, matchStart);
|
|
5418
|
+
const rawSuffix = line.slice(matchEnd, nextStart);
|
|
5419
|
+
const prefix = trimAfterLastDelimiter(rawPrefix);
|
|
5420
|
+
const suffix = trimBeforeLastDelimiter(rawSuffix);
|
|
5421
|
+
if (normalizeInstructionText(suffix)) {
|
|
5422
|
+
return suffix;
|
|
5423
|
+
}
|
|
5424
|
+
if (normalizeInstructionText(prefix)) {
|
|
5425
|
+
return prefix;
|
|
5426
|
+
}
|
|
5427
|
+
return `${prefix} ${suffix}`.trim();
|
|
5428
|
+
}
|
|
5429
|
+
function trimAfterLastDelimiter(text) {
|
|
5430
|
+
const match = findLastDelimiter(text);
|
|
5431
|
+
if (!match) {
|
|
5432
|
+
return text;
|
|
5433
|
+
}
|
|
5434
|
+
return text.slice(match.index + match.length);
|
|
5435
|
+
}
|
|
5436
|
+
function trimBeforeLastDelimiter(text) {
|
|
5437
|
+
const cleaned = text.replace(/^[,;:]\s*/g, '');
|
|
5438
|
+
const match = findLastDelimiter(cleaned);
|
|
5439
|
+
if (!match || match.index <= 0) {
|
|
5440
|
+
return cleaned;
|
|
5441
|
+
}
|
|
5442
|
+
return cleaned.slice(0, match.index);
|
|
5443
|
+
}
|
|
5444
|
+
function findLastDelimiter(text) {
|
|
5445
|
+
let bestIndex = -1;
|
|
5446
|
+
let bestLength = 0;
|
|
5447
|
+
for (const separator of clauseSeparators) {
|
|
5448
|
+
const index = text.lastIndexOf(separator);
|
|
5449
|
+
if (index > bestIndex) {
|
|
5450
|
+
bestIndex = index;
|
|
5451
|
+
bestLength = separator.length;
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5454
|
+
const lowerText = text.toLowerCase();
|
|
5455
|
+
for (const separator of conjunctionSeparators) {
|
|
5456
|
+
const index = lowerText.lastIndexOf(separator);
|
|
5457
|
+
if (index > bestIndex) {
|
|
5458
|
+
bestIndex = index;
|
|
5459
|
+
bestLength = separator.length;
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
if (bestIndex === -1) {
|
|
5463
|
+
return null;
|
|
5464
|
+
}
|
|
5465
|
+
return { index: bestIndex, length: bestLength };
|
|
5466
|
+
}
|
|
5467
|
+
function normalizeInstructionText(text) {
|
|
5468
|
+
if (!text) {
|
|
5469
|
+
return '';
|
|
5470
|
+
}
|
|
5471
|
+
const withoutUrls = text.replace(urlRegex, '');
|
|
5472
|
+
let normalized = normalizeWhitespaces(withoutUrls).trim();
|
|
5473
|
+
normalized = normalized.replace(/^[,;:]\s*/g, '');
|
|
5474
|
+
normalized = normalized.replace(/^(and|or|the|a|an)\s+/i, '');
|
|
5475
|
+
normalized = normalized.replace(/\s*[,;:]\s*$/g, '');
|
|
5476
|
+
normalized = normalized.replace(/\s+(and|or)\s*$/i, '');
|
|
5477
|
+
normalized = normalizeWhitespaces(normalized).trim();
|
|
5478
|
+
return normalized;
|
|
5479
|
+
}
|
|
5480
|
+
function createTeammateLabel(url) {
|
|
5481
|
+
try {
|
|
5482
|
+
const parsed = new URL(url);
|
|
5483
|
+
const pathParts = parsed.pathname.split('/').filter(Boolean);
|
|
5484
|
+
const lastPart = pathParts[pathParts.length - 1] || parsed.hostname;
|
|
5485
|
+
const decoded = decodeURIComponent(lastPart);
|
|
5486
|
+
const spaced = decoded.replace(/[-_]+/g, ' ').trim();
|
|
5487
|
+
if (!spaced) {
|
|
5488
|
+
return parsed.hostname;
|
|
5489
|
+
}
|
|
5490
|
+
return spaced
|
|
5491
|
+
.split(' ')
|
|
5492
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
5493
|
+
.join(' ');
|
|
5494
|
+
}
|
|
5495
|
+
catch (error) {
|
|
5496
|
+
return url;
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
/**
|
|
5500
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5501
|
+
*/
|
|
5502
|
+
|
|
5503
|
+
/**
|
|
5504
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5505
|
+
*
|
|
5506
|
+
* @public exported from `@promptbook/core`
|
|
5507
|
+
*/
|
|
5508
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5509
|
+
try {
|
|
5510
|
+
return await fetch(urlOrRequest, init);
|
|
5511
|
+
}
|
|
5512
|
+
catch (error) {
|
|
5513
|
+
assertsError(error);
|
|
5514
|
+
let url;
|
|
5515
|
+
if (typeof urlOrRequest === 'string') {
|
|
5516
|
+
url = urlOrRequest;
|
|
5517
|
+
}
|
|
5518
|
+
else if (urlOrRequest instanceof Request) {
|
|
5519
|
+
url = urlOrRequest.url;
|
|
5520
|
+
}
|
|
5521
|
+
throw new PromptbookFetchError(spaceTrim$2((block) => `
|
|
5522
|
+
Can not fetch "${url}"
|
|
5523
|
+
|
|
5524
|
+
Fetch error:
|
|
5525
|
+
${block(error.message)}
|
|
5526
|
+
|
|
5527
|
+
`));
|
|
5528
|
+
}
|
|
5529
|
+
};
|
|
5530
|
+
/**
|
|
5531
|
+
* TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
|
|
5532
|
+
*/
|
|
5533
|
+
|
|
5534
|
+
const TEAM_TOOL_PREFIX = 'team_chat_';
|
|
5535
|
+
const teamToolFunctions = {};
|
|
5536
|
+
const teamToolTitles = {};
|
|
5537
|
+
/**
|
|
5538
|
+
* TEAM commitment definition
|
|
5539
|
+
*
|
|
5540
|
+
* The `TEAM` commitment defines teammates that the agent can consult via tools.
|
|
5541
|
+
*
|
|
5542
|
+
* Example usage in agent source:
|
|
5543
|
+
*
|
|
5544
|
+
* ```book
|
|
5545
|
+
* TEAM https://agents.ptbk.ik/agents/joe-green
|
|
5546
|
+
* TEAM You can talk with http://localhost:4440/agents/GMw67JN8TXxN7y to discuss the legal aspects.
|
|
5547
|
+
* ```
|
|
5548
|
+
*
|
|
5549
|
+
* @private [??] Maybe export the commitments through some package
|
|
5550
|
+
*/
|
|
5551
|
+
class TeamCommitmentDefinition extends BaseCommitmentDefinition {
|
|
5552
|
+
constructor() {
|
|
5553
|
+
super('TEAM');
|
|
5554
|
+
}
|
|
5555
|
+
/**
|
|
5556
|
+
* Short one-line description of TEAM.
|
|
5557
|
+
*/
|
|
5558
|
+
get description() {
|
|
5559
|
+
return 'Enable the agent to consult teammate agents via dedicated tools.';
|
|
5560
|
+
}
|
|
5561
|
+
/**
|
|
5562
|
+
* Icon for this commitment.
|
|
5563
|
+
*/
|
|
5564
|
+
get icon() {
|
|
5565
|
+
return '??';
|
|
5566
|
+
}
|
|
5567
|
+
/**
|
|
5568
|
+
* Markdown documentation for TEAM commitment.
|
|
5569
|
+
*/
|
|
5570
|
+
get documentation() {
|
|
5571
|
+
return spaceTrim$1(`
|
|
5572
|
+
# TEAM
|
|
5573
|
+
|
|
5574
|
+
Registers teammate agents that the current agent can consult via tools.
|
|
5575
|
+
|
|
5576
|
+
## Examples
|
|
5577
|
+
|
|
5578
|
+
\`\`\`book
|
|
5579
|
+
Legal Assistant
|
|
5580
|
+
|
|
5581
|
+
PERSONA An expert software developer
|
|
5582
|
+
TEAM You can talk with http://localhost:4440/agents/GMw67JN8TXxN7y to discuss the legal aspects.
|
|
5583
|
+
\`\`\`
|
|
5584
|
+
`);
|
|
5585
|
+
}
|
|
5586
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
5587
|
+
var _a, _b;
|
|
5588
|
+
const trimmedContent = content.trim();
|
|
5589
|
+
if (!trimmedContent) {
|
|
5590
|
+
return requirements;
|
|
5591
|
+
}
|
|
5592
|
+
const teammates = parseTeamCommitmentContent(trimmedContent, { strict: true });
|
|
5593
|
+
if (teammates.length === 0) {
|
|
5594
|
+
return requirements;
|
|
5595
|
+
}
|
|
5596
|
+
const agentName = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.agentName) || 'Agent';
|
|
5597
|
+
const teamEntries = teammates.map((teammate) => ({
|
|
5598
|
+
toolName: createTeamToolName(teammate.url),
|
|
5599
|
+
teammate,
|
|
5600
|
+
agentName,
|
|
5601
|
+
}));
|
|
5602
|
+
for (const entry of teamEntries) {
|
|
5603
|
+
registerTeamTool(entry);
|
|
5604
|
+
}
|
|
5605
|
+
const existingTools = requirements.tools || [];
|
|
5606
|
+
const updatedTools = [...existingTools];
|
|
5607
|
+
for (const entry of teamEntries) {
|
|
5608
|
+
if (updatedTools.some((tool) => tool.name === entry.toolName)) {
|
|
5609
|
+
continue;
|
|
5610
|
+
}
|
|
5611
|
+
const instructionSuffix = entry.teammate.instructions
|
|
5612
|
+
? `Use when: ${entry.teammate.instructions}`
|
|
5613
|
+
: 'Use when their expertise is needed.';
|
|
5614
|
+
updatedTools.push({
|
|
5615
|
+
name: entry.toolName,
|
|
5616
|
+
description: spaceTrim$1(`
|
|
5617
|
+
Consult teammate ${entry.teammate.label} (${entry.teammate.url}).
|
|
5618
|
+
${instructionSuffix}
|
|
5619
|
+
`),
|
|
5620
|
+
parameters: {
|
|
5621
|
+
type: 'object',
|
|
5622
|
+
properties: {
|
|
5623
|
+
message: {
|
|
5624
|
+
type: 'string',
|
|
5625
|
+
description: 'Question or request to send to the teammate.',
|
|
5626
|
+
},
|
|
5627
|
+
context: {
|
|
5628
|
+
type: 'string',
|
|
5629
|
+
description: 'Optional background context for the teammate.',
|
|
5630
|
+
},
|
|
5631
|
+
},
|
|
5632
|
+
required: ['message'],
|
|
5633
|
+
},
|
|
5634
|
+
});
|
|
5635
|
+
}
|
|
5636
|
+
const existingTeammates = ((_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.teammates) || [];
|
|
5637
|
+
const updatedTeammates = [...existingTeammates];
|
|
5638
|
+
for (const entry of teamEntries) {
|
|
5639
|
+
if (updatedTeammates.some((existing) => existing.url === entry.teammate.url)) {
|
|
5640
|
+
continue;
|
|
5641
|
+
}
|
|
5642
|
+
updatedTeammates.push({
|
|
5643
|
+
url: entry.teammate.url,
|
|
5644
|
+
label: entry.teammate.label,
|
|
5645
|
+
instructions: entry.teammate.instructions || undefined,
|
|
5646
|
+
toolName: entry.toolName,
|
|
5647
|
+
});
|
|
5648
|
+
}
|
|
5649
|
+
const teamSystemMessage = spaceTrim$1((block) => `
|
|
5650
|
+
Teammates:
|
|
5651
|
+
${block(teamEntries
|
|
5652
|
+
.map((entry) => {
|
|
5653
|
+
const whenToConsult = entry.teammate.instructions || 'Use when their expertise is needed.';
|
|
5654
|
+
return spaceTrim$1(() => `
|
|
5655
|
+
- ${entry.teammate.label} (${entry.teammate.url})
|
|
5656
|
+
- Tool: "${entry.toolName}"
|
|
5657
|
+
- When to consult: ${whenToConsult}
|
|
5658
|
+
`);
|
|
5659
|
+
})
|
|
5660
|
+
.join('\n'))}
|
|
5661
|
+
`);
|
|
5662
|
+
return this.appendToSystemMessage({
|
|
5663
|
+
...requirements,
|
|
5664
|
+
tools: updatedTools,
|
|
5665
|
+
metadata: {
|
|
5666
|
+
...requirements.metadata,
|
|
5667
|
+
teammates: updatedTeammates,
|
|
5668
|
+
},
|
|
5669
|
+
}, teamSystemMessage);
|
|
5670
|
+
}
|
|
5671
|
+
/**
|
|
5672
|
+
* Gets human-readable titles for tool functions provided by this commitment.
|
|
5673
|
+
*/
|
|
5674
|
+
getToolTitles() {
|
|
5675
|
+
return { ...teamToolTitles };
|
|
5676
|
+
}
|
|
5677
|
+
/**
|
|
5678
|
+
* Gets tool function implementations for teammate tools.
|
|
5679
|
+
*/
|
|
5680
|
+
getToolFunctions() {
|
|
5681
|
+
return { ...teamToolFunctions };
|
|
5682
|
+
}
|
|
5683
|
+
}
|
|
5684
|
+
function createTeamToolName(url) {
|
|
5685
|
+
const hash = computeHash(url).substring(0, 10);
|
|
5686
|
+
return `${TEAM_TOOL_PREFIX}${hash}`;
|
|
5687
|
+
}
|
|
5688
|
+
function registerTeamTool(entry) {
|
|
5689
|
+
teamToolFunctions[entry.toolName] = createTeamToolFunction(entry);
|
|
5690
|
+
teamToolTitles[entry.toolName] = `Consult ${entry.teammate.label}`;
|
|
5691
|
+
}
|
|
5692
|
+
function createTeamToolFunction(entry) {
|
|
5693
|
+
return async (args) => {
|
|
5694
|
+
const message = args.message || args.question || '';
|
|
5695
|
+
if (!message) {
|
|
5696
|
+
const result = {
|
|
5697
|
+
error: 'Message is required to contact teammate.',
|
|
5698
|
+
teammate: {
|
|
5699
|
+
url: entry.teammate.url,
|
|
5700
|
+
label: entry.teammate.label,
|
|
5701
|
+
instructions: entry.teammate.instructions,
|
|
5702
|
+
toolName: entry.toolName,
|
|
5703
|
+
},
|
|
5704
|
+
};
|
|
5705
|
+
return JSON.stringify(result);
|
|
5706
|
+
}
|
|
5707
|
+
const request = args.context ? `${message}\n\nContext:\n${args.context}` : message;
|
|
5708
|
+
let response = '';
|
|
5709
|
+
let error = null;
|
|
5710
|
+
try {
|
|
5711
|
+
response = await fetchTeammateResponse(entry.teammate.url, request);
|
|
5712
|
+
}
|
|
5713
|
+
catch (err) {
|
|
5714
|
+
error = err instanceof Error ? err.message : String(err);
|
|
5715
|
+
}
|
|
5716
|
+
const teammateReply = response || (error ? `Unable to reach teammate. Error: ${error}` : 'No response received.');
|
|
5717
|
+
const result = {
|
|
5718
|
+
teammate: {
|
|
5719
|
+
url: entry.teammate.url,
|
|
5720
|
+
label: entry.teammate.label,
|
|
5721
|
+
instructions: entry.teammate.instructions,
|
|
5722
|
+
toolName: entry.toolName,
|
|
5723
|
+
},
|
|
5724
|
+
request,
|
|
5725
|
+
response: teammateReply,
|
|
5726
|
+
error,
|
|
5727
|
+
conversation: [
|
|
5728
|
+
{
|
|
5729
|
+
sender: 'AGENT',
|
|
5730
|
+
name: entry.agentName,
|
|
5731
|
+
content: request,
|
|
5732
|
+
},
|
|
5733
|
+
{
|
|
5734
|
+
sender: 'TEAMMATE',
|
|
5735
|
+
name: entry.teammate.label,
|
|
5736
|
+
content: teammateReply,
|
|
5737
|
+
},
|
|
5738
|
+
],
|
|
5739
|
+
};
|
|
5740
|
+
return JSON.stringify(result);
|
|
5741
|
+
};
|
|
5742
|
+
}
|
|
5743
|
+
async function fetchTeammateResponse(agentUrl, message) {
|
|
5744
|
+
const url = `${agentUrl.replace(/\/$/, '')}/api/chat`;
|
|
5745
|
+
const response = await promptbookFetch(url, {
|
|
5746
|
+
method: 'POST',
|
|
5747
|
+
headers: {
|
|
5748
|
+
'Content-Type': 'application/json',
|
|
5749
|
+
},
|
|
5750
|
+
body: JSON.stringify({ message }),
|
|
5751
|
+
});
|
|
5752
|
+
if (!response.ok) {
|
|
5753
|
+
throw new Error(`Teammate request failed: ${response.status} ${response.statusText}`);
|
|
5754
|
+
}
|
|
5755
|
+
const rawText = await response.text();
|
|
5756
|
+
return stripToolCallLines(rawText).trim();
|
|
5757
|
+
}
|
|
5758
|
+
function stripToolCallLines(text) {
|
|
5759
|
+
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
|
5760
|
+
return lines
|
|
5761
|
+
.filter((line) => {
|
|
5762
|
+
const trimmed = line.trim();
|
|
5763
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {
|
|
5764
|
+
return true;
|
|
5765
|
+
}
|
|
5766
|
+
try {
|
|
5767
|
+
const parsed = JSON.parse(trimmed);
|
|
5768
|
+
return !('toolCalls' in parsed);
|
|
5769
|
+
}
|
|
5770
|
+
catch (_a) {
|
|
5771
|
+
return true;
|
|
5772
|
+
}
|
|
5773
|
+
})
|
|
5774
|
+
.join('\n');
|
|
5775
|
+
}
|
|
5776
|
+
/**
|
|
5777
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5778
|
+
*/
|
|
5779
|
+
|
|
5328
5780
|
/**
|
|
5329
5781
|
* USE commitment definition
|
|
5330
5782
|
*
|
|
@@ -5838,6 +6290,25 @@ class SerpSearchEngine {
|
|
|
5838
6290
|
}
|
|
5839
6291
|
}
|
|
5840
6292
|
|
|
6293
|
+
/**
|
|
6294
|
+
* @@@
|
|
6295
|
+
*
|
|
6296
|
+
* @private utility for commitments
|
|
6297
|
+
*/
|
|
6298
|
+
function formatOptionalInstructionBlock(label, content) {
|
|
6299
|
+
const trimmedContent = spaceTrim$1(content);
|
|
6300
|
+
if (!trimmedContent) {
|
|
6301
|
+
return '';
|
|
6302
|
+
}
|
|
6303
|
+
return spaceTrim$1((block) => `
|
|
6304
|
+
- ${label}:
|
|
6305
|
+
${block(trimmedContent
|
|
6306
|
+
.split('\n')
|
|
6307
|
+
.map((line) => `- ${line}`)
|
|
6308
|
+
.join('\n'))}
|
|
6309
|
+
`);
|
|
6310
|
+
}
|
|
6311
|
+
|
|
5841
6312
|
/**
|
|
5842
6313
|
* USE SEARCH ENGINE commitment definition
|
|
5843
6314
|
*
|
|
@@ -5859,6 +6330,9 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5859
6330
|
constructor() {
|
|
5860
6331
|
super('USE SEARCH ENGINE', ['USE SEARCH']);
|
|
5861
6332
|
}
|
|
6333
|
+
get requiresContent() {
|
|
6334
|
+
return false;
|
|
6335
|
+
}
|
|
5862
6336
|
/**
|
|
5863
6337
|
* Short one-line description of USE SEARCH ENGINE.
|
|
5864
6338
|
*/
|
|
@@ -5907,6 +6381,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5907
6381
|
`);
|
|
5908
6382
|
}
|
|
5909
6383
|
applyToAgentModelRequirements(requirements, content) {
|
|
6384
|
+
const extraInstructions = formatOptionalInstructionBlock('Search instructions', content);
|
|
5910
6385
|
// Get existing tools array or create new one
|
|
5911
6386
|
const existingTools = requirements.tools || [];
|
|
5912
6387
|
// Add 'web_search' to tools if not already present
|
|
@@ -5965,13 +6440,14 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
5965
6440
|
...requirements.metadata,
|
|
5966
6441
|
useSearchEngine: content || true,
|
|
5967
6442
|
},
|
|
5968
|
-
}, spaceTrim$1(`
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
6443
|
+
}, spaceTrim$1((block) => `
|
|
6444
|
+
Tool:
|
|
6445
|
+
- You have access to the web search engine via the tool "web_search".
|
|
6446
|
+
- Use it to find up-to-date information or facts that you don't know.
|
|
6447
|
+
- When you need to know some information from the internet, use the tool provided to you.
|
|
6448
|
+
- Do not make up information when you can search for it.
|
|
6449
|
+
- Do not tell the user you cannot search for information, YOU CAN.
|
|
6450
|
+
${block(extraInstructions)}
|
|
5975
6451
|
`));
|
|
5976
6452
|
}
|
|
5977
6453
|
/**
|
|
@@ -6023,6 +6499,7 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6023
6499
|
*
|
|
6024
6500
|
* ```book
|
|
6025
6501
|
* USE TIME
|
|
6502
|
+
* USE TIME Prefer the user's local timezone.
|
|
6026
6503
|
* ```
|
|
6027
6504
|
*
|
|
6028
6505
|
* @private [🪔] Maybe export the commitments through some package
|
|
@@ -6031,6 +6508,9 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6031
6508
|
constructor() {
|
|
6032
6509
|
super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
|
|
6033
6510
|
}
|
|
6511
|
+
get requiresContent() {
|
|
6512
|
+
return false;
|
|
6513
|
+
}
|
|
6034
6514
|
/**
|
|
6035
6515
|
* Short one-line description of USE TIME.
|
|
6036
6516
|
*/
|
|
@@ -6057,6 +6537,7 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6057
6537
|
- This tool won't receive any input.
|
|
6058
6538
|
- It outputs the current date and time as an ISO 8601 string.
|
|
6059
6539
|
- Allows the agent to answer questions about the current time or date.
|
|
6540
|
+
- The content following \`USE TIME\` is an arbitrary text that the agent should know (e.g. timezone preference).
|
|
6060
6541
|
|
|
6061
6542
|
## Examples
|
|
6062
6543
|
|
|
@@ -6066,9 +6547,17 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6066
6547
|
PERSONA You are a helpful assistant who knows the current time.
|
|
6067
6548
|
USE TIME
|
|
6068
6549
|
\`\`\`
|
|
6550
|
+
|
|
6551
|
+
\`\`\`book
|
|
6552
|
+
Travel Assistant
|
|
6553
|
+
|
|
6554
|
+
PERSONA You help travelers with planning.
|
|
6555
|
+
USE TIME Prefer the user's local timezone.
|
|
6556
|
+
\`\`\`
|
|
6069
6557
|
`);
|
|
6070
6558
|
}
|
|
6071
6559
|
applyToAgentModelRequirements(requirements, content) {
|
|
6560
|
+
const extraInstructions = formatOptionalInstructionBlock('Time instructions', content);
|
|
6072
6561
|
// Get existing tools array or create new one
|
|
6073
6562
|
const existingTools = requirements.tools || [];
|
|
6074
6563
|
// Add 'get_current_time' to tools if not already present
|
|
@@ -6099,13 +6588,12 @@ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
6099
6588
|
metadata: {
|
|
6100
6589
|
...requirements.metadata,
|
|
6101
6590
|
},
|
|
6102
|
-
}, spaceTrim$1(`
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
`));
|
|
6591
|
+
}, spaceTrim$1((block) => `
|
|
6592
|
+
Time and date context:
|
|
6593
|
+
- It is ${moment().format('MMMM YYYY')} now.
|
|
6594
|
+
- If you need more precise current time information, use the tool "get_current_time".
|
|
6595
|
+
${block(extraInstructions)}
|
|
6596
|
+
`));
|
|
6109
6597
|
}
|
|
6110
6598
|
/**
|
|
6111
6599
|
* Gets human-readable titles for tool functions provided by this commitment.
|
|
@@ -6283,6 +6771,7 @@ const COMMITMENT_REGISTRY = [
|
|
|
6283
6771
|
new DictionaryCommitmentDefinition(),
|
|
6284
6772
|
new OpenCommitmentDefinition(),
|
|
6285
6773
|
new ClosedCommitmentDefinition(),
|
|
6774
|
+
new TeamCommitmentDefinition(),
|
|
6286
6775
|
new UseBrowserCommitmentDefinition(),
|
|
6287
6776
|
new UseSearchEngineCommitmentDefinition(),
|
|
6288
6777
|
new UseTimeCommitmentDefinition(),
|