@promptbook/core 0.103.0-52 → 0.103.0-54
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 +588 -73
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +8 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +12 -0
- package/esm/typings/src/book-components/icons/MicIcon.d.ts +8 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +17 -0
- package/esm/typings/src/commitments/ACTION/ACTION.d.ts +4 -0
- package/esm/typings/src/commitments/DELETE/DELETE.d.ts +4 -0
- package/esm/typings/src/commitments/FORMAT/FORMAT.d.ts +4 -0
- package/esm/typings/src/commitments/GOAL/GOAL.d.ts +4 -0
- package/esm/typings/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
- package/esm/typings/src/commitments/MEMORY/MEMORY.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/AgentMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/MESSAGE.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/UserMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/commitments/META/META.d.ts +4 -0
- package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +4 -0
- package/esm/typings/src/commitments/META_IMAGE/META_IMAGE.d.ts +4 -0
- package/esm/typings/src/commitments/META_LINK/META_LINK.d.ts +4 -0
- package/esm/typings/src/commitments/MODEL/MODEL.d.ts +4 -0
- package/esm/typings/src/commitments/NOTE/NOTE.d.ts +4 -0
- package/esm/typings/src/commitments/PERSONA/PERSONA.d.ts +4 -0
- package/esm/typings/src/commitments/RULE/RULE.d.ts +4 -0
- package/esm/typings/src/commitments/SAMPLE/SAMPLE.d.ts +4 -0
- package/esm/typings/src/commitments/SCENARIO/SCENARIO.d.ts +4 -0
- package/esm/typings/src/commitments/STYLE/STYLE.d.ts +4 -0
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +5 -0
- package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +5 -0
- package/esm/typings/src/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +4 -0
- package/esm/typings/src/commitments/index.d.ts +20 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +9 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +10 -1
- package/esm/typings/src/utils/normalization/normalizeMessageText.d.ts +9 -0
- package/esm/typings/src/utils/normalization/normalizeMessageText.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +589 -72
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,12 +27,23 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-54';
|
|
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
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Core Promptbook server configuration.
|
|
38
|
+
*
|
|
39
|
+
* This server is also used for auto-federation in the Agents Server.
|
|
40
|
+
*/
|
|
41
|
+
const CORE_SERVER = {
|
|
42
|
+
title: 'Promptbook Core',
|
|
43
|
+
description: `Core Promptbook server used for auto-federation`,
|
|
44
|
+
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
45
|
+
urls: ['https://core.ptbk.io/'],
|
|
46
|
+
};
|
|
36
47
|
/**
|
|
37
48
|
* Available remote servers for the Promptbook
|
|
38
49
|
*
|
|
@@ -54,6 +65,7 @@ const REMOTE_SERVER_URLS = [
|
|
|
54
65
|
owner: 'AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)',
|
|
55
66
|
urls: ['https://s6.ptbk.io/'],
|
|
56
67
|
},
|
|
68
|
+
CORE_SERVER,
|
|
57
69
|
/*
|
|
58
70
|
Note: Working on older version of Promptbook and not supported anymore
|
|
59
71
|
{
|
|
@@ -66,7 +78,14 @@ const REMOTE_SERVER_URLS = [
|
|
|
66
78
|
*/
|
|
67
79
|
];
|
|
68
80
|
/**
|
|
69
|
-
*
|
|
81
|
+
* Remote servers that are auto-federated by the Agents Server.
|
|
82
|
+
*
|
|
83
|
+
* These servers are always added in addition to the `FEDERATED_SERVERS` metadata.
|
|
84
|
+
*
|
|
85
|
+
* @public exported from `@promptbook/core`
|
|
86
|
+
*/
|
|
87
|
+
const AUTO_FEDERATED_AGENT_SERVER_URLS = CORE_SERVER.urls;
|
|
88
|
+
/**
|
|
70
89
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
71
90
|
*/
|
|
72
91
|
|
|
@@ -7567,6 +7586,12 @@ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7567
7586
|
get description() {
|
|
7568
7587
|
return 'Define agent capabilities and actions it can perform.';
|
|
7569
7588
|
}
|
|
7589
|
+
/**
|
|
7590
|
+
* Icon for this commitment.
|
|
7591
|
+
*/
|
|
7592
|
+
get icon() {
|
|
7593
|
+
return '⚡';
|
|
7594
|
+
}
|
|
7570
7595
|
/**
|
|
7571
7596
|
* Markdown documentation for ACTION commitment.
|
|
7572
7597
|
*/
|
|
@@ -7646,6 +7671,12 @@ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7646
7671
|
get description() {
|
|
7647
7672
|
return 'Remove or **disregard** certain information, context, or previous commitments.';
|
|
7648
7673
|
}
|
|
7674
|
+
/**
|
|
7675
|
+
* Icon for this commitment.
|
|
7676
|
+
*/
|
|
7677
|
+
get icon() {
|
|
7678
|
+
return '🗑️';
|
|
7679
|
+
}
|
|
7649
7680
|
/**
|
|
7650
7681
|
* Markdown documentation for DELETE commitment.
|
|
7651
7682
|
*/
|
|
@@ -7762,6 +7793,12 @@ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7762
7793
|
get description() {
|
|
7763
7794
|
return 'Specify output structure or formatting requirements.';
|
|
7764
7795
|
}
|
|
7796
|
+
/**
|
|
7797
|
+
* Icon for this commitment.
|
|
7798
|
+
*/
|
|
7799
|
+
get icon() {
|
|
7800
|
+
return '📜';
|
|
7801
|
+
}
|
|
7765
7802
|
/**
|
|
7766
7803
|
* Markdown documentation for FORMAT commitment.
|
|
7767
7804
|
*/
|
|
@@ -7837,6 +7874,12 @@ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7837
7874
|
get description() {
|
|
7838
7875
|
return 'Define main **goals** the AI assistant should achieve, with later goals having higher priority.';
|
|
7839
7876
|
}
|
|
7877
|
+
/**
|
|
7878
|
+
* Icon for this commitment.
|
|
7879
|
+
*/
|
|
7880
|
+
get icon() {
|
|
7881
|
+
return '🎯';
|
|
7882
|
+
}
|
|
7840
7883
|
/**
|
|
7841
7884
|
* Markdown documentation for GOAL commitment.
|
|
7842
7885
|
*/
|
|
@@ -7933,6 +7976,12 @@ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
7933
7976
|
get description() {
|
|
7934
7977
|
return 'Add domain **knowledge** via direct text or external sources (RAG).';
|
|
7935
7978
|
}
|
|
7979
|
+
/**
|
|
7980
|
+
* Icon for this commitment.
|
|
7981
|
+
*/
|
|
7982
|
+
get icon() {
|
|
7983
|
+
return '🧠';
|
|
7984
|
+
}
|
|
7936
7985
|
/**
|
|
7937
7986
|
* Markdown documentation for KNOWLEDGE commitment.
|
|
7938
7987
|
*/
|
|
@@ -8034,6 +8083,12 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8034
8083
|
get description() {
|
|
8035
8084
|
return 'Remember past interactions and user **preferences** for personalized responses.';
|
|
8036
8085
|
}
|
|
8086
|
+
/**
|
|
8087
|
+
* Icon for this commitment.
|
|
8088
|
+
*/
|
|
8089
|
+
get icon() {
|
|
8090
|
+
return '🧠';
|
|
8091
|
+
}
|
|
8037
8092
|
/**
|
|
8038
8093
|
* Markdown documentation for MEMORY commitment.
|
|
8039
8094
|
*/
|
|
@@ -8108,6 +8163,83 @@ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8108
8163
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
8109
8164
|
*/
|
|
8110
8165
|
|
|
8166
|
+
/**
|
|
8167
|
+
* AGENT MESSAGE commitment definition
|
|
8168
|
+
*
|
|
8169
|
+
* The AGENT MESSAGE commitment defines a message from the agent in the conversation history.
|
|
8170
|
+
* It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
|
|
8171
|
+
*
|
|
8172
|
+
* Example usage in agent source:
|
|
8173
|
+
*
|
|
8174
|
+
* ```book
|
|
8175
|
+
* AGENT MESSAGE What seems to be the issue?
|
|
8176
|
+
* ```
|
|
8177
|
+
*
|
|
8178
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
8179
|
+
*/
|
|
8180
|
+
class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
8181
|
+
constructor() {
|
|
8182
|
+
super('AGENT MESSAGE');
|
|
8183
|
+
}
|
|
8184
|
+
/**
|
|
8185
|
+
* Short one-line description of AGENT MESSAGE.
|
|
8186
|
+
*/
|
|
8187
|
+
get description() {
|
|
8188
|
+
return 'Defines a **message from the agent** in the conversation history.';
|
|
8189
|
+
}
|
|
8190
|
+
/**
|
|
8191
|
+
* Icon for this commitment.
|
|
8192
|
+
*/
|
|
8193
|
+
get icon() {
|
|
8194
|
+
return '🤖';
|
|
8195
|
+
}
|
|
8196
|
+
/**
|
|
8197
|
+
* Markdown documentation for AGENT MESSAGE commitment.
|
|
8198
|
+
*/
|
|
8199
|
+
get documentation() {
|
|
8200
|
+
return spaceTrim$2(`
|
|
8201
|
+
# ${this.type}
|
|
8202
|
+
|
|
8203
|
+
Defines a message from the agent in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
|
|
8204
|
+
|
|
8205
|
+
## Key aspects
|
|
8206
|
+
|
|
8207
|
+
- Represents a message sent by the agent.
|
|
8208
|
+
- Used for setting up conversation context.
|
|
8209
|
+
- Can be used in conjunction with USER MESSAGE.
|
|
8210
|
+
|
|
8211
|
+
## Examples
|
|
8212
|
+
|
|
8213
|
+
\`\`\`book
|
|
8214
|
+
Conversation History
|
|
8215
|
+
|
|
8216
|
+
USER MESSAGE Hello, I have a problem.
|
|
8217
|
+
AGENT MESSAGE What seems to be the issue?
|
|
8218
|
+
USER MESSAGE My computer is not starting.
|
|
8219
|
+
\`\`\`
|
|
8220
|
+
`);
|
|
8221
|
+
}
|
|
8222
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
8223
|
+
// AGENT MESSAGE is for UI display purposes / conversation history construction
|
|
8224
|
+
// and typically doesn't need to be added to the system prompt or model requirements directly.
|
|
8225
|
+
// It is extracted separately for the chat interface.
|
|
8226
|
+
var _a;
|
|
8227
|
+
const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
|
|
8228
|
+
if (pendingUserMessage) {
|
|
8229
|
+
const newSample = { question: pendingUserMessage, answer: content };
|
|
8230
|
+
const newSamples = [...(requirements.samples || []), newSample];
|
|
8231
|
+
const newMetadata = { ...requirements.metadata };
|
|
8232
|
+
delete newMetadata.pendingUserMessage;
|
|
8233
|
+
return {
|
|
8234
|
+
...requirements,
|
|
8235
|
+
samples: newSamples,
|
|
8236
|
+
metadata: newMetadata,
|
|
8237
|
+
};
|
|
8238
|
+
}
|
|
8239
|
+
return requirements;
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8242
|
+
|
|
8111
8243
|
/**
|
|
8112
8244
|
* INITIAL MESSAGE commitment definition
|
|
8113
8245
|
*
|
|
@@ -8132,6 +8264,12 @@ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8132
8264
|
get description() {
|
|
8133
8265
|
return 'Defines the **initial message** shown to the user when the chat starts.';
|
|
8134
8266
|
}
|
|
8267
|
+
/**
|
|
8268
|
+
* Icon for this commitment.
|
|
8269
|
+
*/
|
|
8270
|
+
get icon() {
|
|
8271
|
+
return '👋';
|
|
8272
|
+
}
|
|
8135
8273
|
/**
|
|
8136
8274
|
* Markdown documentation for INITIAL MESSAGE commitment.
|
|
8137
8275
|
*/
|
|
@@ -8190,6 +8328,12 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8190
8328
|
get description() {
|
|
8191
8329
|
return 'Include actual **messages** the AI assistant has sent during conversation history.';
|
|
8192
8330
|
}
|
|
8331
|
+
/**
|
|
8332
|
+
* Icon for this commitment.
|
|
8333
|
+
*/
|
|
8334
|
+
get icon() {
|
|
8335
|
+
return '💬';
|
|
8336
|
+
}
|
|
8193
8337
|
/**
|
|
8194
8338
|
* Markdown documentation for MESSAGE commitment.
|
|
8195
8339
|
*/
|
|
@@ -8272,6 +8416,73 @@ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8272
8416
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
8273
8417
|
*/
|
|
8274
8418
|
|
|
8419
|
+
/**
|
|
8420
|
+
* USER MESSAGE commitment definition
|
|
8421
|
+
*
|
|
8422
|
+
* The USER MESSAGE commitment defines a message from the user in the conversation history.
|
|
8423
|
+
* It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
|
|
8424
|
+
*
|
|
8425
|
+
* Example usage in agent source:
|
|
8426
|
+
*
|
|
8427
|
+
* ```book
|
|
8428
|
+
* USER MESSAGE Hello, I have a problem.
|
|
8429
|
+
* ```
|
|
8430
|
+
*
|
|
8431
|
+
* @private [🪔] Maybe export the commitments through some package
|
|
8432
|
+
*/
|
|
8433
|
+
class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
8434
|
+
constructor() {
|
|
8435
|
+
super('USER MESSAGE');
|
|
8436
|
+
}
|
|
8437
|
+
/**
|
|
8438
|
+
* Short one-line description of USER MESSAGE.
|
|
8439
|
+
*/
|
|
8440
|
+
get description() {
|
|
8441
|
+
return 'Defines a **message from the user** in the conversation history.';
|
|
8442
|
+
}
|
|
8443
|
+
/**
|
|
8444
|
+
* Icon for this commitment.
|
|
8445
|
+
*/
|
|
8446
|
+
get icon() {
|
|
8447
|
+
return '🧑';
|
|
8448
|
+
}
|
|
8449
|
+
/**
|
|
8450
|
+
* Markdown documentation for USER MESSAGE commitment.
|
|
8451
|
+
*/
|
|
8452
|
+
get documentation() {
|
|
8453
|
+
return spaceTrim$2(`
|
|
8454
|
+
# ${this.type}
|
|
8455
|
+
|
|
8456
|
+
Defines a message from the user in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
|
|
8457
|
+
|
|
8458
|
+
## Key aspects
|
|
8459
|
+
|
|
8460
|
+
- Represents a message sent by the user.
|
|
8461
|
+
- Used for setting up conversation context.
|
|
8462
|
+
- Can be used in conjunction with AGENT MESSAGE.
|
|
8463
|
+
|
|
8464
|
+
## Examples
|
|
8465
|
+
|
|
8466
|
+
\`\`\`book
|
|
8467
|
+
Conversation History
|
|
8468
|
+
|
|
8469
|
+
USER MESSAGE Hello, I have a problem.
|
|
8470
|
+
AGENT MESSAGE What seems to be the issue?
|
|
8471
|
+
USER MESSAGE My computer is not starting.
|
|
8472
|
+
\`\`\`
|
|
8473
|
+
`);
|
|
8474
|
+
}
|
|
8475
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
8476
|
+
return {
|
|
8477
|
+
...requirements,
|
|
8478
|
+
metadata: {
|
|
8479
|
+
...requirements.metadata,
|
|
8480
|
+
pendingUserMessage: content,
|
|
8481
|
+
},
|
|
8482
|
+
};
|
|
8483
|
+
}
|
|
8484
|
+
}
|
|
8485
|
+
|
|
8275
8486
|
/**
|
|
8276
8487
|
* META commitment definition
|
|
8277
8488
|
*
|
|
@@ -8308,6 +8519,12 @@ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8308
8519
|
get description() {
|
|
8309
8520
|
return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
|
|
8310
8521
|
}
|
|
8522
|
+
/**
|
|
8523
|
+
* Icon for this commitment.
|
|
8524
|
+
*/
|
|
8525
|
+
get icon() {
|
|
8526
|
+
return 'ℹ️';
|
|
8527
|
+
}
|
|
8311
8528
|
/**
|
|
8312
8529
|
* Markdown documentation for META commitment.
|
|
8313
8530
|
*/
|
|
@@ -8435,6 +8652,12 @@ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8435
8652
|
get description() {
|
|
8436
8653
|
return "Set the agent's accent color.";
|
|
8437
8654
|
}
|
|
8655
|
+
/**
|
|
8656
|
+
* Icon for this commitment.
|
|
8657
|
+
*/
|
|
8658
|
+
get icon() {
|
|
8659
|
+
return '🎨';
|
|
8660
|
+
}
|
|
8438
8661
|
/**
|
|
8439
8662
|
* Markdown documentation for META COLOR commitment.
|
|
8440
8663
|
*/
|
|
@@ -8513,6 +8736,12 @@ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8513
8736
|
get description() {
|
|
8514
8737
|
return "Set the agent's profile image URL.";
|
|
8515
8738
|
}
|
|
8739
|
+
/**
|
|
8740
|
+
* Icon for this commitment.
|
|
8741
|
+
*/
|
|
8742
|
+
get icon() {
|
|
8743
|
+
return '🖼️';
|
|
8744
|
+
}
|
|
8516
8745
|
/**
|
|
8517
8746
|
* Markdown documentation for META IMAGE commitment.
|
|
8518
8747
|
*/
|
|
@@ -8603,6 +8832,12 @@ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8603
8832
|
get description() {
|
|
8604
8833
|
return 'Enforce AI model requirements including name and technical parameters.';
|
|
8605
8834
|
}
|
|
8835
|
+
/**
|
|
8836
|
+
* Icon for this commitment.
|
|
8837
|
+
*/
|
|
8838
|
+
get icon() {
|
|
8839
|
+
return '⚙️';
|
|
8840
|
+
}
|
|
8606
8841
|
/**
|
|
8607
8842
|
* Markdown documentation for MODEL commitment.
|
|
8608
8843
|
*/
|
|
@@ -8838,6 +9073,12 @@ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8838
9073
|
get description() {
|
|
8839
9074
|
return 'Add developer-facing notes without changing behavior or output.';
|
|
8840
9075
|
}
|
|
9076
|
+
/**
|
|
9077
|
+
* Icon for this commitment.
|
|
9078
|
+
*/
|
|
9079
|
+
get icon() {
|
|
9080
|
+
return '📝';
|
|
9081
|
+
}
|
|
8841
9082
|
/**
|
|
8842
9083
|
* Markdown documentation for NOTE commitment.
|
|
8843
9084
|
*/
|
|
@@ -8940,6 +9181,12 @@ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
8940
9181
|
get description() {
|
|
8941
9182
|
return 'Define who the agent is: background, expertise, and personality.';
|
|
8942
9183
|
}
|
|
9184
|
+
/**
|
|
9185
|
+
* Icon for this commitment.
|
|
9186
|
+
*/
|
|
9187
|
+
get icon() {
|
|
9188
|
+
return '👤';
|
|
9189
|
+
}
|
|
8943
9190
|
/**
|
|
8944
9191
|
* Markdown documentation for PERSONA commitment.
|
|
8945
9192
|
*/
|
|
@@ -9067,6 +9314,12 @@ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9067
9314
|
get description() {
|
|
9068
9315
|
return 'Add behavioral rules the agent must follow.';
|
|
9069
9316
|
}
|
|
9317
|
+
/**
|
|
9318
|
+
* Icon for this commitment.
|
|
9319
|
+
*/
|
|
9320
|
+
get icon() {
|
|
9321
|
+
return '⚖️';
|
|
9322
|
+
}
|
|
9070
9323
|
/**
|
|
9071
9324
|
* Markdown documentation for RULE/RULES commitment.
|
|
9072
9325
|
*/
|
|
@@ -9143,6 +9396,12 @@ class SampleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9143
9396
|
get description() {
|
|
9144
9397
|
return 'Provide example responses to guide behavior.';
|
|
9145
9398
|
}
|
|
9399
|
+
/**
|
|
9400
|
+
* Icon for this commitment.
|
|
9401
|
+
*/
|
|
9402
|
+
get icon() {
|
|
9403
|
+
return '🔍';
|
|
9404
|
+
}
|
|
9146
9405
|
/**
|
|
9147
9406
|
* Markdown documentation for SAMPLE/EXAMPLE commitment.
|
|
9148
9407
|
*/
|
|
@@ -9220,6 +9479,12 @@ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9220
9479
|
get description() {
|
|
9221
9480
|
return 'Define specific **situations** or contexts for AI responses, with later scenarios having higher priority.';
|
|
9222
9481
|
}
|
|
9482
|
+
/**
|
|
9483
|
+
* Icon for this commitment.
|
|
9484
|
+
*/
|
|
9485
|
+
get icon() {
|
|
9486
|
+
return '🎭';
|
|
9487
|
+
}
|
|
9223
9488
|
/**
|
|
9224
9489
|
* Markdown documentation for SCENARIO commitment.
|
|
9225
9490
|
*/
|
|
@@ -9336,6 +9601,12 @@ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9336
9601
|
get description() {
|
|
9337
9602
|
return 'Control the tone and writing style of responses.';
|
|
9338
9603
|
}
|
|
9604
|
+
/**
|
|
9605
|
+
* Icon for this commitment.
|
|
9606
|
+
*/
|
|
9607
|
+
get icon() {
|
|
9608
|
+
return '🖋️';
|
|
9609
|
+
}
|
|
9339
9610
|
/**
|
|
9340
9611
|
* Markdown documentation for STYLE commitment.
|
|
9341
9612
|
*/
|
|
@@ -9405,6 +9676,12 @@ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
9405
9676
|
get description() {
|
|
9406
9677
|
return 'Placeholder commitment that appends content verbatim to the system message.';
|
|
9407
9678
|
}
|
|
9679
|
+
/**
|
|
9680
|
+
* Icon for this commitment.
|
|
9681
|
+
*/
|
|
9682
|
+
get icon() {
|
|
9683
|
+
return '🚧';
|
|
9684
|
+
}
|
|
9408
9685
|
/**
|
|
9409
9686
|
* Markdown documentation available at runtime.
|
|
9410
9687
|
*/
|
|
@@ -9485,6 +9762,8 @@ const COMMITMENT_REGISTRY = [
|
|
|
9485
9762
|
new GoalCommitmentDefinition('GOAL'),
|
|
9486
9763
|
new GoalCommitmentDefinition('GOALS'),
|
|
9487
9764
|
new InitialMessageCommitmentDefinition(),
|
|
9765
|
+
new UserMessageCommitmentDefinition(),
|
|
9766
|
+
new AgentMessageCommitmentDefinition(),
|
|
9488
9767
|
new MessageCommitmentDefinition('MESSAGE'),
|
|
9489
9768
|
new MessageCommitmentDefinition('MESSAGES'),
|
|
9490
9769
|
new ScenarioCommitmentDefinition('SCENARIO'),
|
|
@@ -9539,6 +9818,45 @@ function getAllCommitmentTypes() {
|
|
|
9539
9818
|
function isCommitmentSupported(type) {
|
|
9540
9819
|
return COMMITMENT_REGISTRY.some((commitmentDefinition) => commitmentDefinition.type === type);
|
|
9541
9820
|
}
|
|
9821
|
+
/**
|
|
9822
|
+
* Gets all commitment definitions grouped by their aliases
|
|
9823
|
+
*
|
|
9824
|
+
* @returns Array of grouped commitment definitions
|
|
9825
|
+
*
|
|
9826
|
+
* @public exported from `@promptbook/core`
|
|
9827
|
+
*/
|
|
9828
|
+
function getGroupedCommitmentDefinitions() {
|
|
9829
|
+
const groupedCommitments = [];
|
|
9830
|
+
for (const commitment of COMMITMENT_REGISTRY) {
|
|
9831
|
+
const lastGroup = groupedCommitments[groupedCommitments.length - 1];
|
|
9832
|
+
// Check if we should group with the previous item
|
|
9833
|
+
let shouldGroup = false;
|
|
9834
|
+
if (lastGroup) {
|
|
9835
|
+
const lastPrimary = lastGroup.primary;
|
|
9836
|
+
// Case 1: Same class constructor (except NotYetImplemented)
|
|
9837
|
+
if (!(commitment instanceof NotYetImplementedCommitmentDefinition) &&
|
|
9838
|
+
commitment.constructor === lastPrimary.constructor) {
|
|
9839
|
+
shouldGroup = true;
|
|
9840
|
+
}
|
|
9841
|
+
// Case 2: NotYetImplemented with prefix matching (e.g. BEHAVIOUR -> BEHAVIOURS)
|
|
9842
|
+
else if (commitment instanceof NotYetImplementedCommitmentDefinition &&
|
|
9843
|
+
lastPrimary instanceof NotYetImplementedCommitmentDefinition &&
|
|
9844
|
+
commitment.type.startsWith(lastPrimary.type)) {
|
|
9845
|
+
shouldGroup = true;
|
|
9846
|
+
}
|
|
9847
|
+
}
|
|
9848
|
+
if (shouldGroup && lastGroup) {
|
|
9849
|
+
lastGroup.aliases.push(commitment.type);
|
|
9850
|
+
}
|
|
9851
|
+
else {
|
|
9852
|
+
groupedCommitments.push({
|
|
9853
|
+
primary: commitment,
|
|
9854
|
+
aliases: [],
|
|
9855
|
+
});
|
|
9856
|
+
}
|
|
9857
|
+
}
|
|
9858
|
+
return $deepFreeze(groupedCommitments);
|
|
9859
|
+
}
|
|
9542
9860
|
/**
|
|
9543
9861
|
* TODO: [🧠] Maybe create through standardized $register
|
|
9544
9862
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -10278,6 +10596,18 @@ function parseNumber(value) {
|
|
|
10278
10596
|
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
10279
10597
|
*/
|
|
10280
10598
|
|
|
10599
|
+
/**
|
|
10600
|
+
* Normalizes message text for comparison
|
|
10601
|
+
*
|
|
10602
|
+
* @param text The message text to normalize
|
|
10603
|
+
* @returns The normalized message text
|
|
10604
|
+
*
|
|
10605
|
+
* @public exported from `@promptbook/utils`
|
|
10606
|
+
*/
|
|
10607
|
+
function normalizeMessageText(text) {
|
|
10608
|
+
return spaceTrim$2(text);
|
|
10609
|
+
}
|
|
10610
|
+
|
|
10281
10611
|
/**
|
|
10282
10612
|
* Removes quotes from a string
|
|
10283
10613
|
*
|
|
@@ -10782,7 +11112,96 @@ class AgentCollectionInSupabase /* TODO: [🐱🚀] implements Agent */ {
|
|
|
10782
11112
|
* Deletes an agent from the collection
|
|
10783
11113
|
*/
|
|
10784
11114
|
async deleteAgent(agentName) {
|
|
10785
|
-
|
|
11115
|
+
const deleteResult = await this.supabaseClient
|
|
11116
|
+
.from(this.getTableName('Agent'))
|
|
11117
|
+
.delete()
|
|
11118
|
+
.eq('agentName', agentName);
|
|
11119
|
+
if (deleteResult.error) {
|
|
11120
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
11121
|
+
Error deleting agent "${agentName}" from Supabase:
|
|
11122
|
+
|
|
11123
|
+
${block(deleteResult.error.message)}
|
|
11124
|
+
`));
|
|
11125
|
+
}
|
|
11126
|
+
}
|
|
11127
|
+
/**
|
|
11128
|
+
* List history of an agent
|
|
11129
|
+
*/
|
|
11130
|
+
async listAgentHistory(agentName) {
|
|
11131
|
+
const result = await this.supabaseClient
|
|
11132
|
+
.from(this.getTableName('AgentHistory'))
|
|
11133
|
+
.select('id, createdAt, agentHash, promptbookEngineVersion')
|
|
11134
|
+
.eq('agentName', agentName)
|
|
11135
|
+
.order('createdAt', { ascending: false });
|
|
11136
|
+
if (result.error) {
|
|
11137
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
11138
|
+
Error listing history for agent "${agentName}" from Supabase:
|
|
11139
|
+
|
|
11140
|
+
${block(result.error.message)}
|
|
11141
|
+
`));
|
|
11142
|
+
}
|
|
11143
|
+
return result.data;
|
|
11144
|
+
}
|
|
11145
|
+
/**
|
|
11146
|
+
* List agents that are in history but not in the active agents list
|
|
11147
|
+
*/
|
|
11148
|
+
async listDeletedAgents() {
|
|
11149
|
+
const historyNamesResult = await this.supabaseClient.from(this.getTableName('AgentHistory')).select('agentName');
|
|
11150
|
+
const currentNamesResult = await this.supabaseClient.from(this.getTableName('Agent')).select('agentName');
|
|
11151
|
+
if (historyNamesResult.error) {
|
|
11152
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
11153
|
+
Error fetching agent history names from Supabase:
|
|
11154
|
+
|
|
11155
|
+
${block(historyNamesResult.error.message)}
|
|
11156
|
+
`));
|
|
11157
|
+
}
|
|
11158
|
+
if (currentNamesResult.error) {
|
|
11159
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
11160
|
+
Error fetching current agent names from Supabase:
|
|
11161
|
+
|
|
11162
|
+
${block(currentNamesResult.error.message)}
|
|
11163
|
+
`));
|
|
11164
|
+
}
|
|
11165
|
+
const currentNames = new Set(currentNamesResult.data.map((d) => d.agentName));
|
|
11166
|
+
const deletedNames = new Set();
|
|
11167
|
+
for (const { agentName } of historyNamesResult.data) {
|
|
11168
|
+
if (!currentNames.has(agentName)) {
|
|
11169
|
+
deletedNames.add(agentName);
|
|
11170
|
+
}
|
|
11171
|
+
}
|
|
11172
|
+
return Array.from(deletedNames);
|
|
11173
|
+
}
|
|
11174
|
+
/**
|
|
11175
|
+
* Restore an agent from history
|
|
11176
|
+
*/
|
|
11177
|
+
async restoreAgent(historyId) {
|
|
11178
|
+
const historyResult = await this.supabaseClient
|
|
11179
|
+
.from(this.getTableName('AgentHistory'))
|
|
11180
|
+
.select('*')
|
|
11181
|
+
.eq('id', historyId)
|
|
11182
|
+
.single();
|
|
11183
|
+
if (historyResult.error) {
|
|
11184
|
+
throw new DatabaseError(spaceTrim((block) => `
|
|
11185
|
+
Error fetching agent history item "${historyId}" from Supabase:
|
|
11186
|
+
|
|
11187
|
+
${block(historyResult.error.message)}
|
|
11188
|
+
`));
|
|
11189
|
+
}
|
|
11190
|
+
const { agentName, agentSource } = historyResult.data;
|
|
11191
|
+
// Check if agent exists
|
|
11192
|
+
const agentResult = await this.supabaseClient
|
|
11193
|
+
.from(this.getTableName('Agent'))
|
|
11194
|
+
.select('id')
|
|
11195
|
+
.eq('agentName', agentName)
|
|
11196
|
+
.single();
|
|
11197
|
+
if (agentResult.data) {
|
|
11198
|
+
// Update
|
|
11199
|
+
await this.updateAgentSource(agentName, agentSource);
|
|
11200
|
+
}
|
|
11201
|
+
else {
|
|
11202
|
+
// Insert (Restore from deleted)
|
|
11203
|
+
await this.createAgent(agentSource);
|
|
11204
|
+
}
|
|
10786
11205
|
}
|
|
10787
11206
|
/**
|
|
10788
11207
|
* Get the Supabase table name with prefix
|
|
@@ -17211,12 +17630,15 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
17211
17630
|
fileStreams.push(file);
|
|
17212
17631
|
}
|
|
17213
17632
|
else {
|
|
17633
|
+
/*
|
|
17634
|
+
TODO: [🐱🚀] Resolve problem with browser environment
|
|
17214
17635
|
// Assume it's a local file path
|
|
17215
17636
|
// Note: This will work in Node.js environment
|
|
17216
17637
|
// For browser environments, this would need different handling
|
|
17217
17638
|
const fs = await import('fs');
|
|
17218
17639
|
const fileStream = fs.createReadStream(source);
|
|
17219
17640
|
fileStreams.push(fileStream);
|
|
17641
|
+
*/
|
|
17220
17642
|
}
|
|
17221
17643
|
}
|
|
17222
17644
|
catch (error) {
|
|
@@ -17305,12 +17727,15 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
17305
17727
|
fileStreams.push(file);
|
|
17306
17728
|
}
|
|
17307
17729
|
else {
|
|
17730
|
+
/*
|
|
17731
|
+
TODO: [🐱🚀] Resolve problem with browser environment
|
|
17308
17732
|
// Assume it's a local file path
|
|
17309
17733
|
// Note: This will work in Node.js environment
|
|
17310
17734
|
// For browser environments, this would need different handling
|
|
17311
17735
|
const fs = await import('fs');
|
|
17312
17736
|
const fileStream = fs.createReadStream(source);
|
|
17313
17737
|
fileStreams.push(fileStream);
|
|
17738
|
+
*/
|
|
17314
17739
|
}
|
|
17315
17740
|
}
|
|
17316
17741
|
catch (error) {
|
|
@@ -17684,7 +18109,53 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
17684
18109
|
* Note: This method also implements the learning mechanism
|
|
17685
18110
|
*/
|
|
17686
18111
|
async callChatModelStream(prompt, onProgress) {
|
|
18112
|
+
// [1] Check if the user is asking the same thing as in the samples
|
|
18113
|
+
const modelRequirements = await this.getAgentModelRequirements();
|
|
18114
|
+
if (modelRequirements.samples) {
|
|
18115
|
+
const normalizedPrompt = normalizeMessageText(prompt.content);
|
|
18116
|
+
const sample = modelRequirements.samples.find((s) => normalizeMessageText(s.question) === normalizedPrompt);
|
|
18117
|
+
if (sample) {
|
|
18118
|
+
const now = new Date().toISOString();
|
|
18119
|
+
const result = {
|
|
18120
|
+
content: sample.answer,
|
|
18121
|
+
modelName: this.modelName,
|
|
18122
|
+
timing: {
|
|
18123
|
+
start: now,
|
|
18124
|
+
complete: now,
|
|
18125
|
+
},
|
|
18126
|
+
usage: {
|
|
18127
|
+
price: { value: 0, isUncertain: true },
|
|
18128
|
+
input: {
|
|
18129
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
18130
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
18131
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
18132
|
+
linesCount: { value: 0, isUncertain: true },
|
|
18133
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
18134
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
18135
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
18136
|
+
},
|
|
18137
|
+
output: {
|
|
18138
|
+
tokensCount: { value: 0, isUncertain: true },
|
|
18139
|
+
charactersCount: { value: 0, isUncertain: true },
|
|
18140
|
+
wordsCount: { value: 0, isUncertain: true },
|
|
18141
|
+
linesCount: { value: 0, isUncertain: true },
|
|
18142
|
+
sentencesCount: { value: 0, isUncertain: true },
|
|
18143
|
+
paragraphsCount: { value: 0, isUncertain: true },
|
|
18144
|
+
pagesCount: { value: 0, isUncertain: true },
|
|
18145
|
+
},
|
|
18146
|
+
},
|
|
18147
|
+
rawPromptContent: prompt.content,
|
|
18148
|
+
rawRequest: null,
|
|
18149
|
+
rawResponse: { sample },
|
|
18150
|
+
};
|
|
18151
|
+
onProgress(result);
|
|
18152
|
+
return result;
|
|
18153
|
+
}
|
|
18154
|
+
}
|
|
17687
18155
|
const result = await super.callChatModelStream(prompt, onProgress);
|
|
18156
|
+
if (result.rawResponse && 'sample' in result.rawResponse) {
|
|
18157
|
+
return result;
|
|
18158
|
+
}
|
|
17688
18159
|
// TODO: !!! Extract learning to separate method
|
|
17689
18160
|
// Learning: Append the conversation sample to the agent source
|
|
17690
18161
|
const learningExample = spaceTrim$1((block) => `
|
|
@@ -17770,6 +18241,70 @@ const _AgentRegistration = $llmToolsRegister.register(createAgentLlmExecutionToo
|
|
|
17770
18241
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
17771
18242
|
*/
|
|
17772
18243
|
|
|
18244
|
+
/**
|
|
18245
|
+
* Function `isValidPipelineString` will validate the if the string is a valid pipeline string
|
|
18246
|
+
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
18247
|
+
*
|
|
18248
|
+
* @param {string} pipelineString the candidate for a pipeline string
|
|
18249
|
+
* @returns {boolean} if the string is a valid pipeline string
|
|
18250
|
+
* @public exported from `@promptbook/core`
|
|
18251
|
+
*/
|
|
18252
|
+
function isValidPipelineString(pipelineString) {
|
|
18253
|
+
try {
|
|
18254
|
+
validatePipelineString(pipelineString);
|
|
18255
|
+
return true;
|
|
18256
|
+
}
|
|
18257
|
+
catch (error) {
|
|
18258
|
+
assertsError(error);
|
|
18259
|
+
return false;
|
|
18260
|
+
}
|
|
18261
|
+
}
|
|
18262
|
+
/**
|
|
18263
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
18264
|
+
*/
|
|
18265
|
+
|
|
18266
|
+
/**
|
|
18267
|
+
* Tag function for notating a pipeline with a book\`...\ notation as template literal
|
|
18268
|
+
*
|
|
18269
|
+
* Note: There are 3 similar functions:
|
|
18270
|
+
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
18271
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
18272
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
18273
|
+
*
|
|
18274
|
+
* @param strings The static string parts of the template literal
|
|
18275
|
+
* @param values The dynamic values embedded within the template literal used as data
|
|
18276
|
+
* @returns the pipeline string
|
|
18277
|
+
* @public exported from `@promptbook/core`
|
|
18278
|
+
*/
|
|
18279
|
+
function book(strings, ...values) {
|
|
18280
|
+
const bookString = prompt(strings, ...values);
|
|
18281
|
+
if (!isValidPipelineString(bookString)) {
|
|
18282
|
+
// TODO: Make the CustomError for this
|
|
18283
|
+
throw new Error(spaceTrim$1(`
|
|
18284
|
+
The string is not a valid pipeline string
|
|
18285
|
+
|
|
18286
|
+
book\`
|
|
18287
|
+
${bookString}
|
|
18288
|
+
\`
|
|
18289
|
+
`));
|
|
18290
|
+
}
|
|
18291
|
+
if (!isValidBook(bookString)) {
|
|
18292
|
+
// TODO: Make the CustomError for this
|
|
18293
|
+
throw new Error(spaceTrim$1(`
|
|
18294
|
+
The string is not a valid book
|
|
18295
|
+
|
|
18296
|
+
book\`
|
|
18297
|
+
${bookString}
|
|
18298
|
+
\`
|
|
18299
|
+
`));
|
|
18300
|
+
}
|
|
18301
|
+
return padBook(bookString);
|
|
18302
|
+
}
|
|
18303
|
+
/**
|
|
18304
|
+
* TODO: [🧠][🈴] Where is the best location for this file
|
|
18305
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18306
|
+
*/
|
|
18307
|
+
|
|
17773
18308
|
/**
|
|
17774
18309
|
* Represents one AI Agent
|
|
17775
18310
|
*
|
|
@@ -17791,11 +18326,12 @@ class RemoteAgent extends Agent {
|
|
|
17791
18326
|
const profile = await profileResponse.json();
|
|
17792
18327
|
// Note: We are creating dummy agent source because we don't have the source from the remote agent
|
|
17793
18328
|
// But we populate the metadata from the profile
|
|
17794
|
-
const agentSource = new BehaviorSubject(`
|
|
17795
|
-
|
|
18329
|
+
const agentSource = new BehaviorSubject(book `
|
|
18330
|
+
${profile.agentName}
|
|
17796
18331
|
|
|
17797
|
-
${profile.personaDescription}
|
|
18332
|
+
${profile.personaDescription}
|
|
17798
18333
|
`);
|
|
18334
|
+
// <- TODO: [🐱🚀] createBookFromProfile
|
|
17799
18335
|
// <- TODO: [🐱🚀] Support updating and self-updating
|
|
17800
18336
|
const remoteAgent = new RemoteAgent({
|
|
17801
18337
|
...options,
|
|
@@ -17820,10 +18356,12 @@ ${profile.personaDescription}
|
|
|
17820
18356
|
remoteAgent.initialMessage = profile.initialMessage;
|
|
17821
18357
|
remoteAgent.links = profile.links;
|
|
17822
18358
|
remoteAgent.meta = profile.meta;
|
|
18359
|
+
remoteAgent._isVoiceCallingEnabled = profile.isVoiceCallingEnabled === true; // [✨✷] Store voice calling status
|
|
17823
18360
|
return remoteAgent;
|
|
17824
18361
|
}
|
|
17825
18362
|
constructor(options) {
|
|
17826
18363
|
super(options);
|
|
18364
|
+
this._isVoiceCallingEnabled = false; // [✨✷] Track voice calling status
|
|
17827
18365
|
this.agentUrl = options.agentUrl;
|
|
17828
18366
|
}
|
|
17829
18367
|
get agentName() {
|
|
@@ -17839,8 +18377,49 @@ ${profile.personaDescription}
|
|
|
17839
18377
|
return this.callChatModelStream(prompt, () => { });
|
|
17840
18378
|
}
|
|
17841
18379
|
/**
|
|
17842
|
-
* Calls the agent on agents remote server with
|
|
18380
|
+
* Calls the agent on agents remote server with voice
|
|
18381
|
+
* [✨✷] Only available when voice calling is enabled on the server
|
|
18382
|
+
* Returns undefined if voice calling is disabled
|
|
17843
18383
|
*/
|
|
18384
|
+
get callVoiceChatModel() {
|
|
18385
|
+
if (!this._isVoiceCallingEnabled) {
|
|
18386
|
+
return undefined;
|
|
18387
|
+
}
|
|
18388
|
+
return async (audio, prompt) => {
|
|
18389
|
+
// Ensure we're working with a chat prompt
|
|
18390
|
+
if (prompt.modelRequirements.modelVariant !== 'CHAT') {
|
|
18391
|
+
throw new Error('Agents only supports chat prompts');
|
|
18392
|
+
}
|
|
18393
|
+
const chatPrompt = prompt;
|
|
18394
|
+
const formData = new FormData();
|
|
18395
|
+
formData.append('audio', audio, 'voice.webm');
|
|
18396
|
+
formData.append('message', prompt.content);
|
|
18397
|
+
if (chatPrompt.thread) {
|
|
18398
|
+
formData.append('thread', JSON.stringify(chatPrompt.thread));
|
|
18399
|
+
}
|
|
18400
|
+
const response = await fetch(`${this.agentUrl}/api/voice`, {
|
|
18401
|
+
method: 'POST',
|
|
18402
|
+
body: formData,
|
|
18403
|
+
});
|
|
18404
|
+
if (!response.ok) {
|
|
18405
|
+
throw new Error(`Voice chat failed: ${response.statusText}`);
|
|
18406
|
+
}
|
|
18407
|
+
const result = await response.json();
|
|
18408
|
+
// Convert base64 audio back to Blob
|
|
18409
|
+
const binaryString = atob(result.audio);
|
|
18410
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
18411
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
18412
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
18413
|
+
}
|
|
18414
|
+
const audioBlob = new Blob([bytes], { type: 'audio/mp3' });
|
|
18415
|
+
return {
|
|
18416
|
+
text: result.agentMessage || result.text,
|
|
18417
|
+
userMessage: result.userMessage,
|
|
18418
|
+
agentMessage: result.agentMessage || result.text,
|
|
18419
|
+
audio: audioBlob,
|
|
18420
|
+
};
|
|
18421
|
+
};
|
|
18422
|
+
}
|
|
17844
18423
|
async callChatModelStream(prompt, onProgress) {
|
|
17845
18424
|
// Ensure we're working with a chat prompt
|
|
17846
18425
|
if (prompt.modelRequirements.modelVariant !== 'CHAT') {
|
|
@@ -18377,70 +18956,6 @@ function migratePipeline(deprecatedPipeline) {
|
|
|
18377
18956
|
return migratedPipeline;
|
|
18378
18957
|
}
|
|
18379
18958
|
|
|
18380
|
-
/**
|
|
18381
|
-
* Function `isValidPipelineString` will validate the if the string is a valid pipeline string
|
|
18382
|
-
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
18383
|
-
*
|
|
18384
|
-
* @param {string} pipelineString the candidate for a pipeline string
|
|
18385
|
-
* @returns {boolean} if the string is a valid pipeline string
|
|
18386
|
-
* @public exported from `@promptbook/core`
|
|
18387
|
-
*/
|
|
18388
|
-
function isValidPipelineString(pipelineString) {
|
|
18389
|
-
try {
|
|
18390
|
-
validatePipelineString(pipelineString);
|
|
18391
|
-
return true;
|
|
18392
|
-
}
|
|
18393
|
-
catch (error) {
|
|
18394
|
-
assertsError(error);
|
|
18395
|
-
return false;
|
|
18396
|
-
}
|
|
18397
|
-
}
|
|
18398
|
-
/**
|
|
18399
|
-
* TODO: [🧠][🈴] Where is the best location for this file
|
|
18400
|
-
*/
|
|
18401
|
-
|
|
18402
|
-
/**
|
|
18403
|
-
* Tag function for notating a pipeline with a book\`...\ notation as template literal
|
|
18404
|
-
*
|
|
18405
|
-
* Note: There are 3 similar functions:
|
|
18406
|
-
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
18407
|
-
* 2) `promptTemplate` alias for `prompt`
|
|
18408
|
-
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
18409
|
-
*
|
|
18410
|
-
* @param strings The static string parts of the template literal
|
|
18411
|
-
* @param values The dynamic values embedded within the template literal used as data
|
|
18412
|
-
* @returns the pipeline string
|
|
18413
|
-
* @public exported from `@promptbook/core`
|
|
18414
|
-
*/
|
|
18415
|
-
function book(strings, ...values) {
|
|
18416
|
-
const bookString = prompt(strings, ...values);
|
|
18417
|
-
if (!isValidPipelineString(bookString)) {
|
|
18418
|
-
// TODO: Make the CustomError for this
|
|
18419
|
-
throw new Error(spaceTrim$1(`
|
|
18420
|
-
The string is not a valid pipeline string
|
|
18421
|
-
|
|
18422
|
-
book\`
|
|
18423
|
-
${bookString}
|
|
18424
|
-
\`
|
|
18425
|
-
`));
|
|
18426
|
-
}
|
|
18427
|
-
if (!isValidBook(bookString)) {
|
|
18428
|
-
// TODO: Make the CustomError for this
|
|
18429
|
-
throw new Error(spaceTrim$1(`
|
|
18430
|
-
The string is not a valid book
|
|
18431
|
-
|
|
18432
|
-
book\`
|
|
18433
|
-
${bookString}
|
|
18434
|
-
\`
|
|
18435
|
-
`));
|
|
18436
|
-
}
|
|
18437
|
-
return padBook(bookString);
|
|
18438
|
-
}
|
|
18439
|
-
/**
|
|
18440
|
-
* TODO: [🧠][🈴] Where is the best location for this file
|
|
18441
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
18442
|
-
*/
|
|
18443
|
-
|
|
18444
18959
|
/**
|
|
18445
18960
|
* Convert identification to Promptbook token
|
|
18446
18961
|
*
|
|
@@ -19203,7 +19718,7 @@ function $generateBookBoilerplate(options) {
|
|
|
19203
19718
|
const agentSource = validateBook(spaceTrim$1((block) => `
|
|
19204
19719
|
${agentName}
|
|
19205
19720
|
|
|
19206
|
-
META COLOR ${color ||
|
|
19721
|
+
META COLOR ${color || PROMPTBOOK_COLOR.toHex()}
|
|
19207
19722
|
PERSONA ${block(personaDescription)}
|
|
19208
19723
|
`));
|
|
19209
19724
|
return agentSource;
|
|
@@ -19212,5 +19727,5 @@ function $generateBookBoilerplate(options) {
|
|
|
19212
19727
|
* TODO: [🤶] Maybe export through `@promptbook/utils` or `@promptbook/random` package
|
|
19213
19728
|
*/
|
|
19214
19729
|
|
|
19215
|
-
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, RemoteAgent, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeAgentHash, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createDefaultAgentName, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, normalizeAgentName, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
19730
|
+
export { $bookTranspilersRegister, $generateBookBoilerplate, $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, API_REQUEST_TIMEOUT, AUTO_FEDERATED_AGENT_SERVER_URLS, AbstractFormatError, Agent, AgentCollectionInSupabase, AgentLlmExecutionTools, AuthenticationError, BIG_DATASET_TRESHOLD, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CLI_APP_ID, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CompletionFormfactorDefinition, CsvFormatError, CsvFormatParser, DEFAULT_AGENTS_DIRNAME, DEFAULT_BOOK, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_MAX_REQUESTS_PER_MINUTE, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_SERVER_URL, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_SIMULATED_DURATION_MS, DEFAULT_TASK_TITLE, DatabaseError, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FAILED_VALUE_PLACEHOLDER, FORMFACTOR_DEFINITIONS, FormattedBookInMarkdownTranspiler, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_ORDERS, MODEL_TRUST_LEVELS, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotAllowed, NotFoundError, NotYetImplementedCommitmentDefinition, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, OpenAiSdkTranspiler, PADDING_LINES, PENDING_VALUE_PLACEHOLDER, PLAYGROUND_APP_ID, PROMPTBOOK_CHAT_COLOR, PROMPTBOOK_COLOR, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, PROMPTBOOK_LOGO_URL, PROMPTBOOK_SYNTAX_COLORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, PromptbookFetchError, REMOTE_SERVER_URLS, RESERVED_PARAMETER_NAMES, RemoteAgent, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatParser, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UNCERTAIN_ZERO_VALUE, USER_CHAT_COLOR, UnexpectedError, WrappedError, ZERO_USAGE, ZERO_VALUE, _AgentMetadata, _AgentRegistration, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OllamaMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, aboutPromptbookInformation, addUsage, book, cacheLlmTools, compilePipeline, computeAgentHash, computeCosineSimilarity, countUsage, createAgentLlmExecutionTools, createAgentModelRequirements, createAgentModelRequirementsWithCommitments, createBasicAgentModelRequirements, createDefaultAgentName, createEmptyAgentModelRequirements, createLlmToolsFromConfiguration, createPipelineCollectionFromJson, createPipelineCollectionFromPromise, createPipelineCollectionFromUrl, createPipelineExecutor, createPipelineSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, filterModels, generatePlaceholderAgentProfileImageUrl, getAllCommitmentDefinitions, getAllCommitmentTypes, getCommitmentDefinition, getGroupedCommitmentDefinitions, getPipelineInterface, getSingleLlmExecutionTools, identificationToPromptbookToken, isCommitmentSupported, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidBook, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, migratePipeline, normalizeAgentName, padBook, parseAgentSource, parseParameters, parsePipeline, pipelineCollectionToJson, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prettifyPipelineString, promptbookFetch, promptbookTokenToIdentification, unpreparePipeline, usageToHuman, usageToWorktime, validateBook, validatePipeline, validatePipelineString };
|
|
19216
19731
|
//# sourceMappingURL=index.es.js.map
|