@promptbook/core 0.104.0-2 → 0.104.0-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ 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.104.0-2';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.104.0-3';
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
@@ -11044,17 +11044,64 @@ function parseAgentSourceWithCommitments(agentSource) {
11044
11044
  };
11045
11045
  }
11046
11046
  const lines = agentSource.split('\n');
11047
- const agentName = (((_a = lines[0]) === null || _a === void 0 ? void 0 : _a.trim()) || null);
11047
+ let agentName = null;
11048
+ let agentNameLineIndex = -1;
11049
+ // Find the agent name: first non-empty line that is not a commitment and not a horizontal line
11050
+ for (let i = 0; i < lines.length; i++) {
11051
+ const line = lines[i];
11052
+ if (line === undefined) {
11053
+ continue;
11054
+ }
11055
+ const trimmed = line.trim();
11056
+ if (!trimmed) {
11057
+ continue;
11058
+ }
11059
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
11060
+ if (isHorizontal) {
11061
+ continue;
11062
+ }
11063
+ let isCommitment = false;
11064
+ for (const definition of COMMITMENT_REGISTRY) {
11065
+ const typeRegex = definition.createTypeRegex();
11066
+ const match = typeRegex.exec(trimmed);
11067
+ if (match && ((_a = match.groups) === null || _a === void 0 ? void 0 : _a.type)) {
11068
+ isCommitment = true;
11069
+ break;
11070
+ }
11071
+ }
11072
+ if (!isCommitment) {
11073
+ agentName = trimmed;
11074
+ agentNameLineIndex = i;
11075
+ break;
11076
+ }
11077
+ }
11048
11078
  const commitments = [];
11049
11079
  const nonCommitmentLines = [];
11050
- // Always add the first line (agent name) to non-commitment lines
11051
- if (lines[0] !== undefined) {
11052
- nonCommitmentLines.push(lines[0]);
11080
+ // Add lines before agentName that are horizontal lines (they are non-commitment)
11081
+ for (let i = 0; i < agentNameLineIndex; i++) {
11082
+ const line = lines[i];
11083
+ if (line === undefined) {
11084
+ continue;
11085
+ }
11086
+ const trimmed = line.trim();
11087
+ if (!trimmed) {
11088
+ continue;
11089
+ }
11090
+ const isHorizontal = HORIZONTAL_LINE_PATTERN.test(line);
11091
+ if (isHorizontal) {
11092
+ nonCommitmentLines.push(line);
11093
+ }
11094
+ // Note: Commitments before agentName are not added to nonCommitmentLines
11095
+ }
11096
+ // Add the agent name line to non-commitment lines
11097
+ if (agentNameLineIndex >= 0) {
11098
+ nonCommitmentLines.push(lines[agentNameLineIndex]);
11053
11099
  }
11054
11100
  // Parse commitments with multiline support
11055
11101
  let currentCommitment = null;
11056
- // Process lines starting from the second line (skip agent name)
11057
- for (let i = 1; i < lines.length; i++) {
11102
+ // Process lines starting from after the agent name line
11103
+ const startIndex = agentNameLineIndex >= 0 ? agentNameLineIndex + 1 : 0;
11104
+ for (let i = startIndex; i < lines.length; i++) {
11058
11105
  const line = lines[i];
11059
11106
  if (line === undefined) {
11060
11107
  continue;
@@ -18067,7 +18114,7 @@ class OpenAiCompatibleExecutionTools {
18067
18114
  let threadMessages = [];
18068
18115
  if ('thread' in prompt && Array.isArray(prompt.thread)) {
18069
18116
  threadMessages = prompt.thread.map((msg) => ({
18070
- role: msg.role === 'assistant' ? 'assistant' : 'user',
18117
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
18071
18118
  content: msg.content,
18072
18119
  }));
18073
18120
  }