@promptbook/components 0.112.0-70 → 0.112.0-72
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 +1172 -380
- package/esm/index.es.js.map +1 -1
- package/esm/src/book-3.0/Book.d.ts +6 -0
- package/esm/src/book-components/Chat/utils/getToolCallChipletInfo.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +12 -2
- package/esm/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -0
- package/esm/src/cli/cli-commands/run/prepareRunCommandResources.d.ts +20 -0
- package/esm/src/cli/cli-commands/run/resolveRunInputParameters.d.ts +12 -0
- package/esm/src/cli/cli-commands/run/runCommandAction.d.ts +21 -0
- package/esm/src/cli/cli-commands/run/runPipelineExecution.d.ts +14 -0
- package/esm/src/cli/cli-commands/run.d.ts +1 -1
- package/esm/src/conversion/parsePipeline/applyPipelineHead.d.ts +8 -0
- package/esm/src/conversion/parsePipeline/createInitialPipelineJson.d.ts +8 -0
- package/esm/src/conversion/parsePipeline/createUniqueSectionNameResolver.d.ts +14 -0
- package/esm/src/conversion/parsePipeline/defineParameter.d.ts +8 -0
- package/esm/src/conversion/parsePipeline/extractPipelineDescription.d.ts +6 -0
- package/esm/src/conversion/parsePipeline/finalizeParsedPipeline.d.ts +8 -0
- package/esm/src/conversion/parsePipeline/getPipelineIdentification.d.ts +7 -0
- package/esm/src/conversion/parsePipeline/parsePreparedPipelineSections.d.ts +18 -0
- package/esm/src/conversion/parsePipeline/preparePipelineString.d.ts +8 -0
- package/esm/src/conversion/parsePipeline/processPipelineSection.d.ts +9 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +1172 -380
- package/umd/index.umd.js.map +1 -1
- package/umd/src/book-3.0/Book.d.ts +6 -0
- package/umd/src/book-components/Chat/utils/getToolCallChipletInfo.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agent/agentRunCliOptions.d.ts +12 -2
- package/umd/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -0
- package/umd/src/cli/cli-commands/run/prepareRunCommandResources.d.ts +20 -0
- package/umd/src/cli/cli-commands/run/resolveRunInputParameters.d.ts +12 -0
- package/umd/src/cli/cli-commands/run/runCommandAction.d.ts +21 -0
- package/umd/src/cli/cli-commands/run/runPipelineExecution.d.ts +14 -0
- package/umd/src/cli/cli-commands/run.d.ts +1 -1
- package/umd/src/conversion/parsePipeline/applyPipelineHead.d.ts +8 -0
- package/umd/src/conversion/parsePipeline/createInitialPipelineJson.d.ts +8 -0
- package/umd/src/conversion/parsePipeline/createUniqueSectionNameResolver.d.ts +14 -0
- package/umd/src/conversion/parsePipeline/defineParameter.d.ts +8 -0
- package/umd/src/conversion/parsePipeline/extractPipelineDescription.d.ts +6 -0
- package/umd/src/conversion/parsePipeline/finalizeParsedPipeline.d.ts +8 -0
- package/umd/src/conversion/parsePipeline/getPipelineIdentification.d.ts +7 -0
- package/umd/src/conversion/parsePipeline/parsePreparedPipelineSections.d.ts +18 -0
- package/umd/src/conversion/parsePipeline/preparePipelineString.d.ts +8 -0
- package/umd/src/conversion/parsePipeline/processPipelineSection.d.ts +9 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -40,7 +40,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
40
40
|
* @generated
|
|
41
41
|
* @see https://github.com/webgptorg/promptbook
|
|
42
42
|
*/
|
|
43
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
43
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-72';
|
|
44
44
|
/**
|
|
45
45
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
46
46
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4523,7 +4523,9 @@ const octopus3dAvatarVisual = {
|
|
|
4523
4523
|
};
|
|
4524
4524
|
const mantleRadiusX = size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.horizontalStretch;
|
|
4525
4525
|
const mantleRadiusY = size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.verticalStretch * 1.1;
|
|
4526
|
-
const mantleRadiusZ = size *
|
|
4526
|
+
const mantleRadiusZ = size *
|
|
4527
|
+
morphologyProfile.body.bodyRadiusRatio *
|
|
4528
|
+
(0.9 + (morphologyProfile.body.horizontalStretch - 1) * 0.3);
|
|
4527
4529
|
const underbodyRadiusX = mantleRadiusX * (0.9 + (morphologyProfile.tentacles.rootSpreadScale - 1) * 0.08);
|
|
4528
4530
|
const underbodyRadiusY = mantleRadiusY * (0.44 + morphologyProfile.body.lowerDropRatio * 3.1);
|
|
4529
4531
|
const underbodyRadiusZ = mantleRadiusZ * 0.78;
|
|
@@ -4609,7 +4611,11 @@ const octopus3dAvatarVisual = {
|
|
|
4609
4611
|
z: resolveEllipsoidSurfaceDepth(mantleRadiusX, mantleRadiusY, mantleRadiusZ, faceEyeSpacing, faceEyeYOffset),
|
|
4610
4612
|
}, faceEyeRadiusX, faceEyeRadiusY, mantleCenter, headPitch, headYaw, sceneCenterX, sceneCenterY, size, palette, timeMs, animationPhase + 0.7 + eyeRandom() * 0.6, interaction, morphologyProfile.face.eyeStyle);
|
|
4611
4613
|
drawProjectedMouth(context, [
|
|
4612
|
-
{
|
|
4614
|
+
{
|
|
4615
|
+
x: -mouthHalfWidth,
|
|
4616
|
+
y: mouthY,
|
|
4617
|
+
z: resolveEllipsoidSurfaceDepth(mantleRadiusX, mantleRadiusY, mantleRadiusZ, -mouthHalfWidth, mouthY),
|
|
4618
|
+
},
|
|
4613
4619
|
{
|
|
4614
4620
|
x: size * morphologyProfile.face.mouthCenterOffsetRatio,
|
|
4615
4621
|
y: mouthY +
|
|
@@ -4618,7 +4624,11 @@ const octopus3dAvatarVisual = {
|
|
|
4618
4624
|
interaction.gazeY * size * 0.01,
|
|
4619
4625
|
z: resolveEllipsoidSurfaceDepth(mantleRadiusX, mantleRadiusY, mantleRadiusZ, size * morphologyProfile.face.mouthCenterOffsetRatio, mouthY),
|
|
4620
4626
|
},
|
|
4621
|
-
{
|
|
4627
|
+
{
|
|
4628
|
+
x: mouthHalfWidth,
|
|
4629
|
+
y: mouthY,
|
|
4630
|
+
z: resolveEllipsoidSurfaceDepth(mantleRadiusX, mantleRadiusY, mantleRadiusZ, mouthHalfWidth, mouthY),
|
|
4631
|
+
},
|
|
4622
4632
|
], mantleCenter, headPitch, headYaw, sceneCenterX, sceneCenterY, palette, size);
|
|
4623
4633
|
},
|
|
4624
4634
|
};
|
|
@@ -4779,7 +4789,8 @@ function createOctopusTentacleStrokes(options) {
|
|
|
4779
4789
|
z: anchorPoint.z + Math.cos(orbitAngle) * depthReach * 0.3 + sway * size * 0.012,
|
|
4780
4790
|
};
|
|
4781
4791
|
const controlPointTwo = {
|
|
4782
|
-
x: anchorPoint.x +
|
|
4792
|
+
x: anchorPoint.x +
|
|
4793
|
+
Math.sin(orbitAngle) * lateralReach * (0.82 + morphologyProfile.tentacles.swayScale * 0.12),
|
|
4783
4794
|
y: anchorPoint.y + flowLength * 0.66,
|
|
4784
4795
|
z: anchorPoint.z + Math.cos(orbitAngle) * depthReach * 0.72 + sway * size * 0.02,
|
|
4785
4796
|
};
|
|
@@ -4844,8 +4855,7 @@ function drawTentacleStroke(context, tentacleStroke, palette) {
|
|
|
4844
4855
|
context.beginPath();
|
|
4845
4856
|
context.moveTo(startPoint.x, startPoint.y);
|
|
4846
4857
|
context.lineTo(endPoint.x, endPoint.y);
|
|
4847
|
-
context.strokeStyle =
|
|
4848
|
-
tentacleStroke.colorBias > 0.6 ? `${palette.secondary}f0` : `${palette.primary}f0`;
|
|
4858
|
+
context.strokeStyle = tentacleStroke.colorBias > 0.6 ? `${palette.secondary}f0` : `${palette.primary}f0`;
|
|
4849
4859
|
context.lineWidth = width;
|
|
4850
4860
|
context.lineCap = 'round';
|
|
4851
4861
|
context.stroke();
|
|
@@ -17533,6 +17543,212 @@ const DEFAULT_LIST_TIMEOUTS_LIMIT = 20;
|
|
|
17533
17543
|
* @private internal USE TIMEOUT constant
|
|
17534
17544
|
*/
|
|
17535
17545
|
const MAX_LIST_TIMEOUTS_LIMIT = 100;
|
|
17546
|
+
/**
|
|
17547
|
+
* Creates one formatted timeout-argument validation error.
|
|
17548
|
+
*
|
|
17549
|
+
* @private internal utility of USE TIMEOUT
|
|
17550
|
+
*/
|
|
17551
|
+
function createTimeoutToolArgsError(message) {
|
|
17552
|
+
return new PipelineExecutionError(spaceTrim$1(`
|
|
17553
|
+
${message}
|
|
17554
|
+
`));
|
|
17555
|
+
}
|
|
17556
|
+
/**
|
|
17557
|
+
* Normalizes one optional timeout id string.
|
|
17558
|
+
*
|
|
17559
|
+
* @private internal utility of USE TIMEOUT
|
|
17560
|
+
*/
|
|
17561
|
+
function normalizeOptionalTimeoutId(value) {
|
|
17562
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
17563
|
+
}
|
|
17564
|
+
/**
|
|
17565
|
+
* Parses timeout target selection for tools that accept either `timeoutId` or `allActive: true`.
|
|
17566
|
+
*
|
|
17567
|
+
* @private internal utility of USE TIMEOUT
|
|
17568
|
+
*/
|
|
17569
|
+
function parseTimeoutTargetSelection(args, options) {
|
|
17570
|
+
const timeoutId = normalizeOptionalTimeoutId(args.timeoutId);
|
|
17571
|
+
const allActive = args.allActive === true;
|
|
17572
|
+
if (timeoutId && allActive) {
|
|
17573
|
+
throw createTimeoutToolArgsError(options.bothMessage);
|
|
17574
|
+
}
|
|
17575
|
+
if (allActive) {
|
|
17576
|
+
return { allActive: true };
|
|
17577
|
+
}
|
|
17578
|
+
if (!timeoutId) {
|
|
17579
|
+
throw createTimeoutToolArgsError(options.missingMessage);
|
|
17580
|
+
}
|
|
17581
|
+
return {
|
|
17582
|
+
timeoutId,
|
|
17583
|
+
allActive: false,
|
|
17584
|
+
};
|
|
17585
|
+
}
|
|
17586
|
+
/**
|
|
17587
|
+
* Parses one explicit `dueAt` update value.
|
|
17588
|
+
*
|
|
17589
|
+
* @private internal utility of USE TIMEOUT
|
|
17590
|
+
*/
|
|
17591
|
+
function parseOptionalTimeoutDueAt(value) {
|
|
17592
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
17593
|
+
return undefined;
|
|
17594
|
+
}
|
|
17595
|
+
const normalizedDueAt = value.trim();
|
|
17596
|
+
const dueAtTimestamp = Date.parse(normalizedDueAt);
|
|
17597
|
+
if (!Number.isFinite(dueAtTimestamp)) {
|
|
17598
|
+
throw createTimeoutToolArgsError('Timeout `dueAt` must be one valid ISO timestamp.');
|
|
17599
|
+
}
|
|
17600
|
+
return new Date(dueAtTimestamp).toISOString();
|
|
17601
|
+
}
|
|
17602
|
+
/**
|
|
17603
|
+
* Parses one explicit `extendByMs` update value.
|
|
17604
|
+
*
|
|
17605
|
+
* @private internal utility of USE TIMEOUT
|
|
17606
|
+
*/
|
|
17607
|
+
function parseOptionalTimeoutExtendByMs(value) {
|
|
17608
|
+
if (typeof value !== 'number') {
|
|
17609
|
+
return undefined;
|
|
17610
|
+
}
|
|
17611
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
17612
|
+
throw createTimeoutToolArgsError('Timeout `extendByMs` must be a positive number of milliseconds.');
|
|
17613
|
+
}
|
|
17614
|
+
return Math.floor(value);
|
|
17615
|
+
}
|
|
17616
|
+
/**
|
|
17617
|
+
* Parses one explicit `recurrenceIntervalMs` update value.
|
|
17618
|
+
*
|
|
17619
|
+
* @private internal utility of USE TIMEOUT
|
|
17620
|
+
*/
|
|
17621
|
+
function parseOptionalTimeoutRecurrenceInterval(value) {
|
|
17622
|
+
if (value === null) {
|
|
17623
|
+
return null;
|
|
17624
|
+
}
|
|
17625
|
+
if (typeof value !== 'number') {
|
|
17626
|
+
return undefined;
|
|
17627
|
+
}
|
|
17628
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
17629
|
+
throw createTimeoutToolArgsError('Timeout `recurrenceIntervalMs` must be a positive number of milliseconds or `null`.');
|
|
17630
|
+
}
|
|
17631
|
+
return Math.floor(value);
|
|
17632
|
+
}
|
|
17633
|
+
/**
|
|
17634
|
+
* Parses one explicit `message` update value.
|
|
17635
|
+
*
|
|
17636
|
+
* @private internal utility of USE TIMEOUT
|
|
17637
|
+
*/
|
|
17638
|
+
function parseOptionalTimeoutMessage(value) {
|
|
17639
|
+
if (value === null) {
|
|
17640
|
+
return null;
|
|
17641
|
+
}
|
|
17642
|
+
if (typeof value !== 'string') {
|
|
17643
|
+
return undefined;
|
|
17644
|
+
}
|
|
17645
|
+
const normalizedMessage = value.trim();
|
|
17646
|
+
return normalizedMessage.length > 0 ? normalizedMessage : null;
|
|
17647
|
+
}
|
|
17648
|
+
/**
|
|
17649
|
+
* Parses one explicit `parameters` update value.
|
|
17650
|
+
*
|
|
17651
|
+
* @private internal utility of USE TIMEOUT
|
|
17652
|
+
*/
|
|
17653
|
+
function parseOptionalTimeoutParameters(value) {
|
|
17654
|
+
if (value === undefined) {
|
|
17655
|
+
return undefined;
|
|
17656
|
+
}
|
|
17657
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
17658
|
+
throw createTimeoutToolArgsError('Timeout `parameters` must be one JSON object.');
|
|
17659
|
+
}
|
|
17660
|
+
return value;
|
|
17661
|
+
}
|
|
17662
|
+
/**
|
|
17663
|
+
* Parses one explicit `paused` update value.
|
|
17664
|
+
*
|
|
17665
|
+
* @private internal utility of USE TIMEOUT
|
|
17666
|
+
*/
|
|
17667
|
+
function parseOptionalTimeoutPaused(value) {
|
|
17668
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
17669
|
+
}
|
|
17670
|
+
/**
|
|
17671
|
+
* Parses patch fields for `update_timeout`.
|
|
17672
|
+
*
|
|
17673
|
+
* @private internal utility of USE TIMEOUT
|
|
17674
|
+
*/
|
|
17675
|
+
function parseTimeoutUpdatePatch(args) {
|
|
17676
|
+
const patch = {};
|
|
17677
|
+
const dueAt = parseOptionalTimeoutDueAt(args.dueAt);
|
|
17678
|
+
const extendByMs = parseOptionalTimeoutExtendByMs(args.extendByMs);
|
|
17679
|
+
const recurrenceIntervalMs = parseOptionalTimeoutRecurrenceInterval(args.recurrenceIntervalMs);
|
|
17680
|
+
const message = parseOptionalTimeoutMessage(args.message);
|
|
17681
|
+
const parameters = parseOptionalTimeoutParameters(args.parameters);
|
|
17682
|
+
const paused = parseOptionalTimeoutPaused(args.paused);
|
|
17683
|
+
if (dueAt !== undefined) {
|
|
17684
|
+
patch.dueAt = dueAt;
|
|
17685
|
+
}
|
|
17686
|
+
if (extendByMs !== undefined) {
|
|
17687
|
+
patch.extendByMs = extendByMs;
|
|
17688
|
+
}
|
|
17689
|
+
if (patch.dueAt !== undefined && patch.extendByMs !== undefined) {
|
|
17690
|
+
throw createTimeoutToolArgsError('Timeout update cannot include both `dueAt` and `extendByMs`.');
|
|
17691
|
+
}
|
|
17692
|
+
if (recurrenceIntervalMs !== undefined) {
|
|
17693
|
+
patch.recurrenceIntervalMs = recurrenceIntervalMs;
|
|
17694
|
+
}
|
|
17695
|
+
if (message !== undefined) {
|
|
17696
|
+
patch.message = message;
|
|
17697
|
+
}
|
|
17698
|
+
if (parameters !== undefined) {
|
|
17699
|
+
patch.parameters = parameters;
|
|
17700
|
+
}
|
|
17701
|
+
if (paused !== undefined) {
|
|
17702
|
+
patch.paused = paused;
|
|
17703
|
+
}
|
|
17704
|
+
return patch;
|
|
17705
|
+
}
|
|
17706
|
+
/**
|
|
17707
|
+
* Determines whether the patch contains fields that are only supported for single-timeout updates.
|
|
17708
|
+
*
|
|
17709
|
+
* @private internal utility of USE TIMEOUT
|
|
17710
|
+
*/
|
|
17711
|
+
function hasSingleTimeoutOnlyPatchFields(patch) {
|
|
17712
|
+
return (patch.dueAt !== undefined ||
|
|
17713
|
+
patch.extendByMs !== undefined ||
|
|
17714
|
+
patch.recurrenceIntervalMs !== undefined ||
|
|
17715
|
+
patch.message !== undefined ||
|
|
17716
|
+
patch.parameters !== undefined);
|
|
17717
|
+
}
|
|
17718
|
+
/**
|
|
17719
|
+
* Parses bulk timeout update arguments.
|
|
17720
|
+
*
|
|
17721
|
+
* @private internal utility of USE TIMEOUT
|
|
17722
|
+
*/
|
|
17723
|
+
function parseBulkTimeoutUpdateArgs(patch) {
|
|
17724
|
+
if (patch.paused === undefined) {
|
|
17725
|
+
throw createTimeoutToolArgsError('Bulk timeout update with `allActive: true` requires `paused` to be explicitly set.');
|
|
17726
|
+
}
|
|
17727
|
+
if (hasSingleTimeoutOnlyPatchFields(patch)) {
|
|
17728
|
+
throw createTimeoutToolArgsError('Bulk timeout update only supports the `paused` field.');
|
|
17729
|
+
}
|
|
17730
|
+
return {
|
|
17731
|
+
allActive: true,
|
|
17732
|
+
paused: patch.paused,
|
|
17733
|
+
};
|
|
17734
|
+
}
|
|
17735
|
+
/**
|
|
17736
|
+
* Parses single-timeout update arguments.
|
|
17737
|
+
*
|
|
17738
|
+
* @private internal utility of USE TIMEOUT
|
|
17739
|
+
*/
|
|
17740
|
+
function parseSingleTimeoutUpdateArgs(timeoutId, patch) {
|
|
17741
|
+
if (!timeoutId) {
|
|
17742
|
+
throw createTimeoutToolArgsError('Timeout `timeoutId` is required for single-timeout updates.');
|
|
17743
|
+
}
|
|
17744
|
+
if (Object.keys(patch).length === 0) {
|
|
17745
|
+
throw createTimeoutToolArgsError('Timeout update must include at least one editable field.');
|
|
17746
|
+
}
|
|
17747
|
+
return {
|
|
17748
|
+
timeoutId,
|
|
17749
|
+
patch,
|
|
17750
|
+
};
|
|
17751
|
+
}
|
|
17536
17752
|
/**
|
|
17537
17753
|
* Parses and validates `USE TIMEOUT` tool arguments.
|
|
17538
17754
|
*
|
|
@@ -17559,22 +17775,14 @@ const parseTimeoutToolArgs = {
|
|
|
17559
17775
|
* Parses `cancel_timeout` input.
|
|
17560
17776
|
*/
|
|
17561
17777
|
cancel(args) {
|
|
17562
|
-
const
|
|
17563
|
-
|
|
17564
|
-
|
|
17565
|
-
|
|
17566
|
-
|
|
17567
|
-
`));
|
|
17568
|
-
}
|
|
17569
|
-
if (allActive) {
|
|
17778
|
+
const target = parseTimeoutTargetSelection(args, {
|
|
17779
|
+
bothMessage: 'Timeout cancellation must target either one `timeoutId` or `allActive: true`, not both.',
|
|
17780
|
+
missingMessage: 'Timeout `timeoutId` is required unless you pass `allActive: true`.',
|
|
17781
|
+
});
|
|
17782
|
+
if (target.allActive) {
|
|
17570
17783
|
return { allActive: true };
|
|
17571
17784
|
}
|
|
17572
|
-
|
|
17573
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17574
|
-
Timeout \`timeoutId\` is required unless you pass \`allActive: true\`.
|
|
17575
|
-
`));
|
|
17576
|
-
}
|
|
17577
|
-
return { timeoutId };
|
|
17785
|
+
return { timeoutId: target.timeoutId };
|
|
17578
17786
|
},
|
|
17579
17787
|
/**
|
|
17580
17788
|
* Parses `list_timeouts` input.
|
|
@@ -17605,106 +17813,14 @@ const parseTimeoutToolArgs = {
|
|
|
17605
17813
|
* Parses `update_timeout` input.
|
|
17606
17814
|
*/
|
|
17607
17815
|
update(args) {
|
|
17608
|
-
const
|
|
17609
|
-
|
|
17610
|
-
|
|
17611
|
-
|
|
17612
|
-
|
|
17613
|
-
|
|
17614
|
-
|
|
17615
|
-
|
|
17616
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17617
|
-
Timeout update requires one \`timeoutId\` or \`allActive: true\`.
|
|
17618
|
-
`));
|
|
17619
|
-
}
|
|
17620
|
-
const patch = {};
|
|
17621
|
-
if (typeof args.dueAt === 'string' && args.dueAt.trim().length > 0) {
|
|
17622
|
-
const normalizedDueAt = args.dueAt.trim();
|
|
17623
|
-
const dueAtTimestamp = Date.parse(normalizedDueAt);
|
|
17624
|
-
if (!Number.isFinite(dueAtTimestamp)) {
|
|
17625
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17626
|
-
Timeout \`dueAt\` must be one valid ISO timestamp.
|
|
17627
|
-
`));
|
|
17628
|
-
}
|
|
17629
|
-
patch.dueAt = new Date(dueAtTimestamp).toISOString();
|
|
17630
|
-
}
|
|
17631
|
-
if (typeof args.extendByMs === 'number') {
|
|
17632
|
-
if (!Number.isFinite(args.extendByMs) || args.extendByMs <= 0) {
|
|
17633
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17634
|
-
Timeout \`extendByMs\` must be a positive number of milliseconds.
|
|
17635
|
-
`));
|
|
17636
|
-
}
|
|
17637
|
-
patch.extendByMs = Math.floor(args.extendByMs);
|
|
17638
|
-
}
|
|
17639
|
-
if (patch.dueAt !== undefined && patch.extendByMs !== undefined) {
|
|
17640
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17641
|
-
Timeout update cannot include both \`dueAt\` and \`extendByMs\`.
|
|
17642
|
-
`));
|
|
17643
|
-
}
|
|
17644
|
-
if (args.recurrenceIntervalMs === null) {
|
|
17645
|
-
patch.recurrenceIntervalMs = null;
|
|
17646
|
-
}
|
|
17647
|
-
else if (typeof args.recurrenceIntervalMs === 'number') {
|
|
17648
|
-
if (!Number.isFinite(args.recurrenceIntervalMs) || args.recurrenceIntervalMs <= 0) {
|
|
17649
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17650
|
-
Timeout \`recurrenceIntervalMs\` must be a positive number of milliseconds or \`null\`.
|
|
17651
|
-
`));
|
|
17652
|
-
}
|
|
17653
|
-
patch.recurrenceIntervalMs = Math.floor(args.recurrenceIntervalMs);
|
|
17654
|
-
}
|
|
17655
|
-
if (args.message === null) {
|
|
17656
|
-
patch.message = null;
|
|
17657
|
-
}
|
|
17658
|
-
else if (typeof args.message === 'string') {
|
|
17659
|
-
const normalizedMessage = args.message.trim();
|
|
17660
|
-
patch.message = normalizedMessage.length > 0 ? normalizedMessage : null;
|
|
17661
|
-
}
|
|
17662
|
-
if (args.parameters !== undefined) {
|
|
17663
|
-
if (!args.parameters || typeof args.parameters !== 'object' || Array.isArray(args.parameters)) {
|
|
17664
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17665
|
-
Timeout \`parameters\` must be one JSON object.
|
|
17666
|
-
`));
|
|
17667
|
-
}
|
|
17668
|
-
patch.parameters = args.parameters;
|
|
17669
|
-
}
|
|
17670
|
-
if (typeof args.paused === 'boolean') {
|
|
17671
|
-
patch.paused = args.paused;
|
|
17672
|
-
}
|
|
17673
|
-
if (allActive) {
|
|
17674
|
-
if (patch.paused === undefined) {
|
|
17675
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17676
|
-
Bulk timeout update with \`allActive: true\` requires \`paused\` to be explicitly set.
|
|
17677
|
-
`));
|
|
17678
|
-
}
|
|
17679
|
-
const hasSingleOnlyPatch = patch.dueAt !== undefined ||
|
|
17680
|
-
patch.extendByMs !== undefined ||
|
|
17681
|
-
patch.recurrenceIntervalMs !== undefined ||
|
|
17682
|
-
patch.message !== undefined ||
|
|
17683
|
-
patch.parameters !== undefined;
|
|
17684
|
-
if (hasSingleOnlyPatch) {
|
|
17685
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17686
|
-
Bulk timeout update only supports the \`paused\` field.
|
|
17687
|
-
`));
|
|
17688
|
-
}
|
|
17689
|
-
return {
|
|
17690
|
-
allActive: true,
|
|
17691
|
-
paused: patch.paused,
|
|
17692
|
-
};
|
|
17693
|
-
}
|
|
17694
|
-
if (!timeoutId) {
|
|
17695
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17696
|
-
Timeout \`timeoutId\` is required for single-timeout updates.
|
|
17697
|
-
`));
|
|
17698
|
-
}
|
|
17699
|
-
if (Object.keys(patch).length === 0) {
|
|
17700
|
-
throw new PipelineExecutionError(spaceTrim$1(`
|
|
17701
|
-
Timeout update must include at least one editable field.
|
|
17702
|
-
`));
|
|
17703
|
-
}
|
|
17704
|
-
return {
|
|
17705
|
-
timeoutId,
|
|
17706
|
-
patch,
|
|
17707
|
-
};
|
|
17816
|
+
const target = parseTimeoutTargetSelection(args, {
|
|
17817
|
+
bothMessage: 'Timeout update must target either one `timeoutId` or `allActive: true`, not both.',
|
|
17818
|
+
missingMessage: 'Timeout update requires one `timeoutId` or `allActive: true`.',
|
|
17819
|
+
});
|
|
17820
|
+
const patch = parseTimeoutUpdatePatch(args);
|
|
17821
|
+
return target.allActive
|
|
17822
|
+
? parseBulkTimeoutUpdateArgs(patch)
|
|
17823
|
+
: parseSingleTimeoutUpdateArgs(target.timeoutId, patch);
|
|
17708
17824
|
},
|
|
17709
17825
|
};
|
|
17710
17826
|
|
|
@@ -24909,36 +25025,235 @@ const DEFAULT_REPORT_ISSUE_SUCCESS_MESSAGE = 'Issue report submitted. Thank you!
|
|
|
24909
25025
|
*/
|
|
24910
25026
|
const DEFAULT_FEEDBACK_ERROR_MESSAGE = 'Failed to save feedback. Please try again.';
|
|
24911
25027
|
/**
|
|
24912
|
-
*
|
|
25028
|
+
* Constant for feedback status timeout.
|
|
25029
|
+
*/
|
|
25030
|
+
const FEEDBACK_STATUS_TIMEOUT_IN_MILLISECONDS = 3000;
|
|
25031
|
+
/**
|
|
25032
|
+
* Resolves the key used to keep one message rating in the local map.
|
|
24913
25033
|
*
|
|
24914
|
-
* @private
|
|
25034
|
+
* @private function of `useChatRatings`
|
|
24915
25035
|
*/
|
|
24916
|
-
function
|
|
24917
|
-
|
|
25036
|
+
function resolveChatRatingMessageKey$1(message) {
|
|
25037
|
+
return message.id || message.content /* <- TODO: [??][??] Is `message.content` good replacement for the ID */;
|
|
25038
|
+
}
|
|
25039
|
+
/**
|
|
25040
|
+
* Normalizes the stored rating for the current feedback mode.
|
|
25041
|
+
*
|
|
25042
|
+
* @private function of `useChatRatings`
|
|
25043
|
+
*/
|
|
25044
|
+
function normalizeChatRatingValue(feedbackMode, rating) {
|
|
25045
|
+
return feedbackMode === 'report_issue' ? 1 : rating;
|
|
25046
|
+
}
|
|
25047
|
+
/**
|
|
25048
|
+
* Creates the next message-rating map with one updated message entry.
|
|
25049
|
+
*
|
|
25050
|
+
* @private function of `useChatRatings`
|
|
25051
|
+
*/
|
|
25052
|
+
function createUpdatedMessageRatings(previousRatings, message, rating) {
|
|
25053
|
+
const nextRatings = new Map(previousRatings);
|
|
25054
|
+
nextRatings.set(resolveChatRatingMessageKey$1(message), rating);
|
|
25055
|
+
return nextRatings;
|
|
25056
|
+
}
|
|
25057
|
+
/**
|
|
25058
|
+
* Clears the transient feedback-status timeout when it is active.
|
|
25059
|
+
*
|
|
25060
|
+
* @private function of `useChatRatings`
|
|
25061
|
+
*/
|
|
25062
|
+
function clearFeedbackStatusTimeout(feedbackStatusTimeoutRef) {
|
|
25063
|
+
if (feedbackStatusTimeoutRef.current === null) {
|
|
25064
|
+
return;
|
|
25065
|
+
}
|
|
25066
|
+
clearTimeout(feedbackStatusTimeoutRef.current);
|
|
25067
|
+
feedbackStatusTimeoutRef.current = null;
|
|
25068
|
+
}
|
|
25069
|
+
/**
|
|
25070
|
+
* Resolves the rating currently selected for the message being submitted.
|
|
25071
|
+
*
|
|
25072
|
+
* @private function of `useChatRatings`
|
|
25073
|
+
*/
|
|
25074
|
+
function resolveSelectedMessageRating(params) {
|
|
25075
|
+
const { feedbackMode, selectedMessage, messageRatings } = params;
|
|
25076
|
+
const storedRating = messageRatings.get(resolveChatRatingMessageKey$1(selectedMessage));
|
|
25077
|
+
if (feedbackMode === 'report_issue') {
|
|
25078
|
+
return storedRating || 1;
|
|
25079
|
+
}
|
|
25080
|
+
return storedRating || null;
|
|
25081
|
+
}
|
|
25082
|
+
/**
|
|
25083
|
+
* Serializes the current chat thread into the format expected by feedback handlers.
|
|
25084
|
+
*
|
|
25085
|
+
* @private function of `useChatRatings`
|
|
25086
|
+
*/
|
|
25087
|
+
function createChatFeedbackThread(messages) {
|
|
25088
|
+
return messages.map((message) => `${message.content}`).join('\n\n---\n\n');
|
|
25089
|
+
}
|
|
25090
|
+
/**
|
|
25091
|
+
* Builds the payload submitted to the external feedback callback.
|
|
25092
|
+
*
|
|
25093
|
+
* @private function of `useChatRatings`
|
|
25094
|
+
*/
|
|
25095
|
+
function createChatFeedbackSubmission(params) {
|
|
25096
|
+
const { currentRating, messages, selectedMessage, textRating } = params;
|
|
25097
|
+
return {
|
|
25098
|
+
message: selectedMessage,
|
|
25099
|
+
rating: currentRating,
|
|
25100
|
+
textRating,
|
|
25101
|
+
chatThread: createChatFeedbackThread(messages),
|
|
25102
|
+
expectedAnswer: selectedMessage.expectedAnswer || selectedMessage.content || null,
|
|
25103
|
+
url: window.location.href,
|
|
25104
|
+
};
|
|
25105
|
+
}
|
|
25106
|
+
/**
|
|
25107
|
+
* Resolves whether the current hook state is ready to submit feedback.
|
|
25108
|
+
*
|
|
25109
|
+
* @private function of `useChatRatings`
|
|
25110
|
+
*/
|
|
25111
|
+
function prepareChatFeedbackSubmission(params) {
|
|
25112
|
+
const { feedbackMode, messageRatings, messages, selectedMessage, textRating } = params;
|
|
25113
|
+
if (!selectedMessage || feedbackMode === 'off') {
|
|
25114
|
+
return null;
|
|
25115
|
+
}
|
|
25116
|
+
const currentRating = resolveSelectedMessageRating({
|
|
25117
|
+
feedbackMode,
|
|
25118
|
+
selectedMessage,
|
|
25119
|
+
messageRatings,
|
|
25120
|
+
});
|
|
25121
|
+
if (!currentRating) {
|
|
25122
|
+
return null;
|
|
25123
|
+
}
|
|
25124
|
+
return {
|
|
25125
|
+
currentRating,
|
|
25126
|
+
feedbackData: createChatFeedbackSubmission({
|
|
25127
|
+
currentRating,
|
|
25128
|
+
messages,
|
|
25129
|
+
selectedMessage,
|
|
25130
|
+
textRating,
|
|
25131
|
+
}),
|
|
25132
|
+
};
|
|
25133
|
+
}
|
|
25134
|
+
/**
|
|
25135
|
+
* Resolves the success message shown after a rating or issue report is submitted.
|
|
25136
|
+
*
|
|
25137
|
+
* @private function of `useChatRatings`
|
|
25138
|
+
*/
|
|
25139
|
+
function resolveChatFeedbackSuccessMessage(params) {
|
|
25140
|
+
var _a, _b;
|
|
25141
|
+
const { feedbackMode, feedbackTranslations, feedbackResponse } = params;
|
|
25142
|
+
if (feedbackResponse === null || feedbackResponse === void 0 ? void 0 : feedbackResponse.message) {
|
|
25143
|
+
return feedbackResponse.message;
|
|
25144
|
+
}
|
|
25145
|
+
if (feedbackMode === 'report_issue') {
|
|
25146
|
+
return (_a = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.reportIssueSuccessMessage) !== null && _a !== void 0 ? _a : DEFAULT_REPORT_ISSUE_SUCCESS_MESSAGE;
|
|
25147
|
+
}
|
|
25148
|
+
return (_b = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackSuccessMessage) !== null && _b !== void 0 ? _b : DEFAULT_FEEDBACK_SUCCESS_MESSAGE;
|
|
25149
|
+
}
|
|
25150
|
+
/**
|
|
25151
|
+
* Resolves the error message shown when feedback submission fails.
|
|
25152
|
+
*
|
|
25153
|
+
* @private function of `useChatRatings`
|
|
25154
|
+
*/
|
|
25155
|
+
function resolveChatFeedbackErrorMessage(error, feedbackTranslations) {
|
|
25156
|
+
var _a;
|
|
25157
|
+
if (error instanceof Error) {
|
|
25158
|
+
return error.message;
|
|
25159
|
+
}
|
|
25160
|
+
return (_a = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackErrorMessage) !== null && _a !== void 0 ? _a : DEFAULT_FEEDBACK_ERROR_MESSAGE;
|
|
25161
|
+
}
|
|
25162
|
+
/**
|
|
25163
|
+
* Logs the fallback feedback submission when no external handler is provided.
|
|
25164
|
+
*
|
|
25165
|
+
* @private function of `useChatRatings`
|
|
25166
|
+
*/
|
|
25167
|
+
function logChatFeedbackSubmission(feedbackData) {
|
|
25168
|
+
console.info('Rating submitted:', {
|
|
25169
|
+
rating: '?'.repeat(feedbackData.rating),
|
|
25170
|
+
textRating: feedbackData.textRating,
|
|
25171
|
+
chatThread: feedbackData.chatThread,
|
|
25172
|
+
expectedAnswer: feedbackData.expectedAnswer,
|
|
25173
|
+
url: feedbackData.url,
|
|
25174
|
+
});
|
|
25175
|
+
}
|
|
25176
|
+
/**
|
|
25177
|
+
* Submits feedback through the external callback when present, otherwise logs it locally.
|
|
25178
|
+
*
|
|
25179
|
+
* @private function of `useChatRatings`
|
|
25180
|
+
*/
|
|
25181
|
+
async function submitChatFeedback(params) {
|
|
25182
|
+
const { feedbackData, feedbackMode, feedbackTranslations, onFeedback } = params;
|
|
25183
|
+
const feedbackResponse = onFeedback ? await onFeedback(feedbackData) : undefined;
|
|
25184
|
+
if (!onFeedback) {
|
|
25185
|
+
logChatFeedbackSubmission(feedbackData);
|
|
25186
|
+
}
|
|
25187
|
+
return {
|
|
25188
|
+
message: resolveChatFeedbackSuccessMessage({
|
|
25189
|
+
feedbackMode,
|
|
25190
|
+
feedbackTranslations,
|
|
25191
|
+
feedbackResponse,
|
|
25192
|
+
}),
|
|
25193
|
+
variant: 'success',
|
|
25194
|
+
};
|
|
25195
|
+
}
|
|
25196
|
+
/**
|
|
25197
|
+
* Clears the rating modal state after a successful submission.
|
|
25198
|
+
*
|
|
25199
|
+
* @private function of `useChatRatings`
|
|
25200
|
+
*/
|
|
25201
|
+
function resetChatRatingSubmissionState(params) {
|
|
25202
|
+
const { setRatingModalOpen, setSelectedMessage, setTextRating } = params;
|
|
25203
|
+
setRatingModalOpen(false);
|
|
25204
|
+
setTextRating('');
|
|
25205
|
+
setSelectedMessage(null);
|
|
25206
|
+
}
|
|
25207
|
+
/**
|
|
25208
|
+
* Owns the mutable chat-rating state and the message-rating selection handler.
|
|
25209
|
+
*
|
|
25210
|
+
* @private internal hook of `useChatRatings`
|
|
25211
|
+
*/
|
|
25212
|
+
function useChatRatingState(feedbackMode) {
|
|
24918
25213
|
const [ratingModalOpen, setRatingModalOpen] = useState(false);
|
|
24919
25214
|
const [selectedMessage, setSelectedMessage] = useState(null);
|
|
24920
25215
|
const [messageRatings, setMessageRatings] = useState(new Map());
|
|
24921
25216
|
const [textRating, setTextRating] = useState('');
|
|
24922
25217
|
const [hoveredRating, setHoveredRating] = useState(0);
|
|
24923
25218
|
const [expandedMessageId, setExpandedMessageId] = useState(null);
|
|
24924
|
-
const [feedbackStatus, setFeedbackStatus] = useState(null);
|
|
24925
|
-
const feedbackStatusTimeoutRef = useRef(null);
|
|
24926
25219
|
const handleRating = useCallback((message, newRating) => {
|
|
24927
|
-
const normalizedRating = feedbackMode
|
|
25220
|
+
const normalizedRating = normalizeChatRatingValue(feedbackMode, newRating);
|
|
24928
25221
|
setSelectedMessage(message);
|
|
24929
25222
|
setMessageRatings((previousRatings) => {
|
|
24930
|
-
|
|
24931
|
-
nextRatings.set(message.id ||
|
|
24932
|
-
message.content /* <- TODO: [??][??] Is `message.content` good replacement for the ID */, normalizedRating);
|
|
24933
|
-
return nextRatings;
|
|
25223
|
+
return createUpdatedMessageRatings(previousRatings, message, normalizedRating);
|
|
24934
25224
|
});
|
|
24935
25225
|
setRatingModalOpen(true);
|
|
24936
25226
|
}, [feedbackMode]);
|
|
25227
|
+
return {
|
|
25228
|
+
state: {
|
|
25229
|
+
ratingModalOpen,
|
|
25230
|
+
selectedMessage,
|
|
25231
|
+
messageRatings,
|
|
25232
|
+
textRating,
|
|
25233
|
+
hoveredRating,
|
|
25234
|
+
expandedMessageId,
|
|
25235
|
+
},
|
|
25236
|
+
actions: {
|
|
25237
|
+
setRatingModalOpen,
|
|
25238
|
+
setSelectedMessage,
|
|
25239
|
+
setMessageRatings,
|
|
25240
|
+
setTextRating,
|
|
25241
|
+
setHoveredRating,
|
|
25242
|
+
setExpandedMessageId,
|
|
25243
|
+
handleRating,
|
|
25244
|
+
},
|
|
25245
|
+
};
|
|
25246
|
+
}
|
|
25247
|
+
/**
|
|
25248
|
+
* Owns the transient feedback-status toast state and auto-hide lifecycle.
|
|
25249
|
+
*
|
|
25250
|
+
* @private internal hook of `useChatRatings`
|
|
25251
|
+
*/
|
|
25252
|
+
function useChatFeedbackStatus() {
|
|
25253
|
+
const [feedbackStatus, setFeedbackStatus] = useState(null);
|
|
25254
|
+
const feedbackStatusTimeoutRef = useRef(null);
|
|
24937
25255
|
const showFeedbackStatus = useCallback((status) => {
|
|
24938
|
-
|
|
24939
|
-
clearTimeout(feedbackStatusTimeoutRef.current);
|
|
24940
|
-
feedbackStatusTimeoutRef.current = null;
|
|
24941
|
-
}
|
|
25256
|
+
clearFeedbackStatusTimeout(feedbackStatusTimeoutRef);
|
|
24942
25257
|
setFeedbackStatus(status);
|
|
24943
25258
|
if (!status || typeof window === 'undefined') {
|
|
24944
25259
|
return;
|
|
@@ -24946,111 +25261,122 @@ function useChatRatings(options) {
|
|
|
24946
25261
|
feedbackStatusTimeoutRef.current = window.setTimeout(() => {
|
|
24947
25262
|
setFeedbackStatus(null);
|
|
24948
25263
|
feedbackStatusTimeoutRef.current = null;
|
|
24949
|
-
},
|
|
25264
|
+
}, FEEDBACK_STATUS_TIMEOUT_IN_MILLISECONDS);
|
|
24950
25265
|
}, []);
|
|
24951
25266
|
useEffect(() => {
|
|
24952
25267
|
return () => {
|
|
24953
|
-
|
|
24954
|
-
clearTimeout(feedbackStatusTimeoutRef.current);
|
|
24955
|
-
feedbackStatusTimeoutRef.current = null;
|
|
24956
|
-
}
|
|
25268
|
+
clearFeedbackStatusTimeout(feedbackStatusTimeoutRef);
|
|
24957
25269
|
};
|
|
24958
25270
|
}, []);
|
|
24959
|
-
|
|
24960
|
-
|
|
24961
|
-
|
|
24962
|
-
|
|
24963
|
-
|
|
24964
|
-
|
|
24965
|
-
|
|
24966
|
-
|
|
24967
|
-
|
|
25271
|
+
return {
|
|
25272
|
+
feedbackStatus,
|
|
25273
|
+
showFeedbackStatus,
|
|
25274
|
+
};
|
|
25275
|
+
}
|
|
25276
|
+
/**
|
|
25277
|
+
* Builds the submit handler that validates, submits, reports status, and resets the modal.
|
|
25278
|
+
*
|
|
25279
|
+
* @private internal hook of `useChatRatings`
|
|
25280
|
+
*/
|
|
25281
|
+
function useChatRatingSubmission(options) {
|
|
25282
|
+
const { feedbackMode, feedbackTranslations, messageRatings, messages, onFeedback, selectedMessage, setRatingModalOpen, setSelectedMessage, setTextRating, showFeedbackStatus, textRating, } = options;
|
|
25283
|
+
return useCallback(async () => {
|
|
25284
|
+
const preparedSubmission = prepareChatFeedbackSubmission({
|
|
25285
|
+
feedbackMode,
|
|
25286
|
+
messageRatings,
|
|
25287
|
+
messages,
|
|
25288
|
+
selectedMessage,
|
|
25289
|
+
textRating,
|
|
25290
|
+
});
|
|
25291
|
+
if (!preparedSubmission) {
|
|
24968
25292
|
return;
|
|
24969
25293
|
}
|
|
24970
|
-
|
|
24971
|
-
|
|
24972
|
-
|
|
24973
|
-
|
|
24974
|
-
|
|
24975
|
-
|
|
24976
|
-
expectedAnswer: selectedMessage.expectedAnswer || selectedMessage.content || null,
|
|
24977
|
-
url: window.location.href,
|
|
24978
|
-
};
|
|
24979
|
-
if (onFeedback) {
|
|
24980
|
-
try {
|
|
24981
|
-
const feedbackResponse = await onFeedback(feedbackData);
|
|
24982
|
-
showFeedbackStatus({
|
|
24983
|
-
message: (_a = feedbackResponse === null || feedbackResponse === void 0 ? void 0 : feedbackResponse.message) !== null && _a !== void 0 ? _a : (feedbackMode === 'report_issue'
|
|
24984
|
-
? (_b = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.reportIssueSuccessMessage) !== null && _b !== void 0 ? _b : DEFAULT_REPORT_ISSUE_SUCCESS_MESSAGE
|
|
24985
|
-
: (_c = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackSuccessMessage) !== null && _c !== void 0 ? _c : DEFAULT_FEEDBACK_SUCCESS_MESSAGE),
|
|
24986
|
-
variant: 'success',
|
|
24987
|
-
});
|
|
24988
|
-
}
|
|
24989
|
-
catch (error) {
|
|
24990
|
-
console.error('Error submitting feedback:', error);
|
|
24991
|
-
const message = error instanceof Error
|
|
24992
|
-
? error.message
|
|
24993
|
-
: (_d = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackErrorMessage) !== null && _d !== void 0 ? _d : DEFAULT_FEEDBACK_ERROR_MESSAGE;
|
|
24994
|
-
showFeedbackStatus({ message, variant: 'error' });
|
|
24995
|
-
return;
|
|
24996
|
-
}
|
|
24997
|
-
}
|
|
24998
|
-
else {
|
|
24999
|
-
console.info('Rating submitted:', {
|
|
25000
|
-
rating: '?'.repeat(currentRating),
|
|
25001
|
-
textRating: textRating,
|
|
25002
|
-
chatThread,
|
|
25003
|
-
expectedAnswer: selectedMessage.expectedAnswer || selectedMessage.content || null,
|
|
25004
|
-
url: window.location.href,
|
|
25294
|
+
try {
|
|
25295
|
+
const feedbackStatus = await submitChatFeedback({
|
|
25296
|
+
feedbackData: preparedSubmission.feedbackData,
|
|
25297
|
+
feedbackMode,
|
|
25298
|
+
feedbackTranslations,
|
|
25299
|
+
onFeedback,
|
|
25005
25300
|
});
|
|
25301
|
+
showFeedbackStatus(feedbackStatus);
|
|
25302
|
+
}
|
|
25303
|
+
catch (error) {
|
|
25304
|
+
console.error('Error submitting feedback:', error);
|
|
25006
25305
|
showFeedbackStatus({
|
|
25007
|
-
message:
|
|
25008
|
-
|
|
25009
|
-
: (_f = feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackSuccessMessage) !== null && _f !== void 0 ? _f : DEFAULT_FEEDBACK_SUCCESS_MESSAGE,
|
|
25010
|
-
variant: 'success',
|
|
25306
|
+
message: resolveChatFeedbackErrorMessage(error, feedbackTranslations),
|
|
25307
|
+
variant: 'error',
|
|
25011
25308
|
});
|
|
25309
|
+
return;
|
|
25012
25310
|
}
|
|
25013
|
-
|
|
25014
|
-
|
|
25015
|
-
|
|
25311
|
+
resetChatRatingSubmissionState({
|
|
25312
|
+
setRatingModalOpen,
|
|
25313
|
+
setSelectedMessage,
|
|
25314
|
+
setTextRating,
|
|
25315
|
+
});
|
|
25016
25316
|
}, [
|
|
25017
25317
|
feedbackMode,
|
|
25018
|
-
feedbackTranslations
|
|
25019
|
-
feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.feedbackSuccessMessage,
|
|
25020
|
-
feedbackTranslations === null || feedbackTranslations === void 0 ? void 0 : feedbackTranslations.reportIssueSuccessMessage,
|
|
25021
|
-
messages,
|
|
25318
|
+
feedbackTranslations,
|
|
25022
25319
|
messageRatings,
|
|
25320
|
+
messages,
|
|
25023
25321
|
onFeedback,
|
|
25024
25322
|
selectedMessage,
|
|
25323
|
+
setRatingModalOpen,
|
|
25324
|
+
setSelectedMessage,
|
|
25325
|
+
setTextRating,
|
|
25025
25326
|
showFeedbackStatus,
|
|
25026
25327
|
textRating,
|
|
25027
25328
|
]);
|
|
25329
|
+
}
|
|
25330
|
+
/**
|
|
25331
|
+
* Locks page scrolling while the rating modal is open on mobile layouts.
|
|
25332
|
+
*
|
|
25333
|
+
* @private internal hook of `useChatRatings`
|
|
25334
|
+
*/
|
|
25335
|
+
function useChatRatingModalBodyScrollLock(params) {
|
|
25336
|
+
const { isMobile, ratingModalOpen } = params;
|
|
25028
25337
|
useEffect(() => {
|
|
25029
|
-
if (ratingModalOpen && isMobile) {
|
|
25030
|
-
|
|
25031
|
-
return () => {
|
|
25032
|
-
document.body.style.overflow = 'unset';
|
|
25033
|
-
};
|
|
25338
|
+
if (!(ratingModalOpen && isMobile)) {
|
|
25339
|
+
return;
|
|
25034
25340
|
}
|
|
25035
|
-
|
|
25341
|
+
document.body.style.overflow = 'hidden';
|
|
25342
|
+
return () => {
|
|
25343
|
+
document.body.style.overflow = 'unset';
|
|
25344
|
+
};
|
|
25345
|
+
}, [isMobile, ratingModalOpen]);
|
|
25346
|
+
}
|
|
25347
|
+
/**
|
|
25348
|
+
* Hook that centralizes rating state and handlers for Chat.
|
|
25349
|
+
*
|
|
25350
|
+
* @private component of `<Chat/>`
|
|
25351
|
+
*/
|
|
25352
|
+
function useChatRatings(options) {
|
|
25353
|
+
const { messages, onFeedback, feedbackMode, feedbackTranslations, isMobile } = options;
|
|
25354
|
+
const { state, actions } = useChatRatingState(feedbackMode);
|
|
25355
|
+
const { feedbackStatus, showFeedbackStatus } = useChatFeedbackStatus();
|
|
25356
|
+
const submitRating = useChatRatingSubmission({
|
|
25357
|
+
feedbackMode,
|
|
25358
|
+
feedbackTranslations,
|
|
25359
|
+
messageRatings: state.messageRatings,
|
|
25360
|
+
messages,
|
|
25361
|
+
onFeedback,
|
|
25362
|
+
selectedMessage: state.selectedMessage,
|
|
25363
|
+
setRatingModalOpen: actions.setRatingModalOpen,
|
|
25364
|
+
setSelectedMessage: actions.setSelectedMessage,
|
|
25365
|
+
setTextRating: actions.setTextRating,
|
|
25366
|
+
showFeedbackStatus,
|
|
25367
|
+
textRating: state.textRating,
|
|
25368
|
+
});
|
|
25369
|
+
useChatRatingModalBodyScrollLock({
|
|
25370
|
+
isMobile,
|
|
25371
|
+
ratingModalOpen: state.ratingModalOpen,
|
|
25372
|
+
});
|
|
25036
25373
|
return {
|
|
25037
25374
|
state: {
|
|
25038
|
-
|
|
25039
|
-
selectedMessage,
|
|
25040
|
-
messageRatings,
|
|
25041
|
-
textRating,
|
|
25042
|
-
hoveredRating,
|
|
25043
|
-
expandedMessageId,
|
|
25375
|
+
...state,
|
|
25044
25376
|
feedbackStatus,
|
|
25045
25377
|
},
|
|
25046
25378
|
actions: {
|
|
25047
|
-
|
|
25048
|
-
setSelectedMessage,
|
|
25049
|
-
setMessageRatings,
|
|
25050
|
-
setTextRating,
|
|
25051
|
-
setHoveredRating,
|
|
25052
|
-
setExpandedMessageId,
|
|
25053
|
-
handleRating,
|
|
25379
|
+
...actions,
|
|
25054
25380
|
submitRating,
|
|
25055
25381
|
},
|
|
25056
25382
|
};
|
|
@@ -31729,43 +32055,21 @@ function isTimeoutToolCallName$1(toolName) {
|
|
|
31729
32055
|
* @private internal utility of `<Chat/>`
|
|
31730
32056
|
*/
|
|
31731
32057
|
function resolveTimeoutToolCallPresentation(options) {
|
|
31732
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
31733
32058
|
const { toolCallName, args, resultRaw, locale } = options;
|
|
31734
32059
|
if (!isTimeoutToolCallName$1(toolCallName)) {
|
|
31735
32060
|
return null;
|
|
31736
32061
|
}
|
|
31737
|
-
const
|
|
31738
|
-
|
|
31739
|
-
|
|
31740
|
-
|
|
31741
|
-
|
|
31742
|
-
|
|
31743
|
-
:
|
|
31744
|
-
|
|
31745
|
-
|
|
31746
|
-
|
|
31747
|
-
|
|
31748
|
-
const dueAtRaw = (_h = (_g = normalizeStringValue(resultObject === null || resultObject === void 0 ? void 0 : resultObject.dueAt)) !== null && _g !== void 0 ? _g : normalizeStringValue(args.dueAt)) !== null && _h !== void 0 ? _h : null;
|
|
31749
|
-
const dueAtDate = dueAtRaw ? parseDateValue(dueAtRaw) : null;
|
|
31750
|
-
const effectiveCurrentDate = options.currentDate || new Date();
|
|
31751
|
-
const dueAtLabels = dueAtDate
|
|
31752
|
-
? formatToolCallDateTime(dueAtDate, { locale, currentDate: effectiveCurrentDate })
|
|
31753
|
-
: null;
|
|
31754
|
-
return {
|
|
31755
|
-
action,
|
|
31756
|
-
status,
|
|
31757
|
-
milliseconds,
|
|
31758
|
-
timeoutId,
|
|
31759
|
-
message,
|
|
31760
|
-
dueAtDate,
|
|
31761
|
-
dueAtIsoUtc: dueAtDate ? dueAtDate.toISOString() : null,
|
|
31762
|
-
localTimezone: resolveLocalTimezone(),
|
|
31763
|
-
compactDurationLabel: milliseconds !== null ? formatTimeoutDurationCompact(milliseconds) : null,
|
|
31764
|
-
humanDurationLabel: milliseconds !== null ? formatTimeoutDurationHuman(milliseconds) : null,
|
|
31765
|
-
relativeDueLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.relativeTimeLabel) || null,
|
|
31766
|
-
localDueTimeLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.localTimeLabel) || null,
|
|
31767
|
-
localDueDateLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.localDateLabel) || null,
|
|
31768
|
-
};
|
|
32062
|
+
const timeoutToolCallCoreData = resolveTimeoutToolCallCoreData({
|
|
32063
|
+
toolCallName,
|
|
32064
|
+
args,
|
|
32065
|
+
resultObject: resolveTimeoutToolCallResultObject(resultRaw),
|
|
32066
|
+
});
|
|
32067
|
+
const dueAtLabels = resolveTimeoutToolCallDueAtLabels({
|
|
32068
|
+
dueAtDate: timeoutToolCallCoreData.dueAtDate,
|
|
32069
|
+
currentDate: options.currentDate || new Date(),
|
|
32070
|
+
locale,
|
|
32071
|
+
});
|
|
32072
|
+
return createTimeoutToolCallPresentation({ timeoutToolCallCoreData, dueAtLabels });
|
|
31769
32073
|
}
|
|
31770
32074
|
/**
|
|
31771
32075
|
* Builds concise chip text for timeout tool calls.
|
|
@@ -31901,6 +32205,121 @@ function formatTimeoutDurationHuman(milliseconds) {
|
|
|
31901
32205
|
function formatTimeoutUnit(value, unit) {
|
|
31902
32206
|
return `${value} ${unit}${value === 1 ? '' : 's'}`;
|
|
31903
32207
|
}
|
|
32208
|
+
/**
|
|
32209
|
+
* Normalizes the raw timeout result payload when it is an object.
|
|
32210
|
+
*
|
|
32211
|
+
* @private internal timeout-chat helper
|
|
32212
|
+
*/
|
|
32213
|
+
function resolveTimeoutToolCallResultObject(resultRaw) {
|
|
32214
|
+
return resultRaw && typeof resultRaw === 'object' && !Array.isArray(resultRaw)
|
|
32215
|
+
? resultRaw
|
|
32216
|
+
: null;
|
|
32217
|
+
}
|
|
32218
|
+
/**
|
|
32219
|
+
* Resolves all timeout fields that depend only on arguments and raw result metadata.
|
|
32220
|
+
*
|
|
32221
|
+
* @private internal timeout-chat helper
|
|
32222
|
+
*/
|
|
32223
|
+
function resolveTimeoutToolCallCoreData(options) {
|
|
32224
|
+
const { toolCallName, args, resultObject } = options;
|
|
32225
|
+
return {
|
|
32226
|
+
action: resolveTimeoutToolCallAction(toolCallName, resultObject),
|
|
32227
|
+
status: resolveTimeoutToolCallStatus(resultObject),
|
|
32228
|
+
milliseconds: pickPositiveNumber(args.milliseconds, resultObject === null || resultObject === void 0 ? void 0 : resultObject.milliseconds),
|
|
32229
|
+
timeoutId: pickNormalizedStringValue(resultObject === null || resultObject === void 0 ? void 0 : resultObject.timeoutId, args.timeoutId),
|
|
32230
|
+
message: pickNormalizedStringValue(args.message, resultObject === null || resultObject === void 0 ? void 0 : resultObject.message),
|
|
32231
|
+
dueAtDate: resolveTimeoutToolCallDueAtDate(args, resultObject),
|
|
32232
|
+
};
|
|
32233
|
+
}
|
|
32234
|
+
/**
|
|
32235
|
+
* Resolves the timeout action, preferring an explicit runtime result value.
|
|
32236
|
+
*
|
|
32237
|
+
* @private internal timeout-chat helper
|
|
32238
|
+
*/
|
|
32239
|
+
function resolveTimeoutToolCallAction(toolCallName, resultObject) {
|
|
32240
|
+
if ((resultObject === null || resultObject === void 0 ? void 0 : resultObject.action) === 'cancel' || (resultObject === null || resultObject === void 0 ? void 0 : resultObject.action) === 'set') {
|
|
32241
|
+
return resultObject.action;
|
|
32242
|
+
}
|
|
32243
|
+
return toolCallName === 'cancel_timeout' ? 'cancel' : 'set';
|
|
32244
|
+
}
|
|
32245
|
+
/**
|
|
32246
|
+
* Resolves the timeout status from the runtime result payload.
|
|
32247
|
+
*
|
|
32248
|
+
* @private internal timeout-chat helper
|
|
32249
|
+
*/
|
|
32250
|
+
function resolveTimeoutToolCallStatus(resultObject) {
|
|
32251
|
+
return typeof (resultObject === null || resultObject === void 0 ? void 0 : resultObject.status) === 'string' ? resultObject.status : null;
|
|
32252
|
+
}
|
|
32253
|
+
/**
|
|
32254
|
+
* Resolves the scheduled due date, preferring the runtime result over input arguments.
|
|
32255
|
+
*
|
|
32256
|
+
* @private internal timeout-chat helper
|
|
32257
|
+
*/
|
|
32258
|
+
function resolveTimeoutToolCallDueAtDate(args, resultObject) {
|
|
32259
|
+
const dueAtRaw = pickNormalizedStringValue(resultObject === null || resultObject === void 0 ? void 0 : resultObject.dueAt, args.dueAt);
|
|
32260
|
+
return dueAtRaw ? parseDateValue(dueAtRaw) : null;
|
|
32261
|
+
}
|
|
32262
|
+
/**
|
|
32263
|
+
* Resolves localized due-date labels when a valid due date exists.
|
|
32264
|
+
*
|
|
32265
|
+
* @private internal timeout-chat helper
|
|
32266
|
+
*/
|
|
32267
|
+
function resolveTimeoutToolCallDueAtLabels(options) {
|
|
32268
|
+
const { dueAtDate, currentDate, locale } = options;
|
|
32269
|
+
return dueAtDate ? formatToolCallDateTime(dueAtDate, { locale, currentDate }) : null;
|
|
32270
|
+
}
|
|
32271
|
+
/**
|
|
32272
|
+
* Creates the final timeout presentation payload with derived labels.
|
|
32273
|
+
*
|
|
32274
|
+
* @private internal timeout-chat helper
|
|
32275
|
+
*/
|
|
32276
|
+
function createTimeoutToolCallPresentation(options) {
|
|
32277
|
+
const { timeoutToolCallCoreData, dueAtLabels } = options;
|
|
32278
|
+
const { action, status, milliseconds, timeoutId, message, dueAtDate } = timeoutToolCallCoreData;
|
|
32279
|
+
return {
|
|
32280
|
+
action,
|
|
32281
|
+
status,
|
|
32282
|
+
milliseconds,
|
|
32283
|
+
timeoutId,
|
|
32284
|
+
message,
|
|
32285
|
+
dueAtDate,
|
|
32286
|
+
dueAtIsoUtc: dueAtDate ? dueAtDate.toISOString() : null,
|
|
32287
|
+
localTimezone: resolveLocalTimezone(),
|
|
32288
|
+
compactDurationLabel: milliseconds !== null ? formatTimeoutDurationCompact(milliseconds) : null,
|
|
32289
|
+
humanDurationLabel: milliseconds !== null ? formatTimeoutDurationHuman(milliseconds) : null,
|
|
32290
|
+
relativeDueLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.relativeTimeLabel) || null,
|
|
32291
|
+
localDueTimeLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.localTimeLabel) || null,
|
|
32292
|
+
localDueDateLabel: (dueAtLabels === null || dueAtLabels === void 0 ? void 0 : dueAtLabels.localDateLabel) || null,
|
|
32293
|
+
};
|
|
32294
|
+
}
|
|
32295
|
+
/**
|
|
32296
|
+
* Parses the first positive finite number from a prioritized list of values.
|
|
32297
|
+
*
|
|
32298
|
+
* @private internal timeout-chat helper
|
|
32299
|
+
*/
|
|
32300
|
+
function pickPositiveNumber(...values) {
|
|
32301
|
+
for (const value of values) {
|
|
32302
|
+
const positiveNumber = parsePositiveNumber(value);
|
|
32303
|
+
if (positiveNumber !== null) {
|
|
32304
|
+
return positiveNumber;
|
|
32305
|
+
}
|
|
32306
|
+
}
|
|
32307
|
+
return null;
|
|
32308
|
+
}
|
|
32309
|
+
/**
|
|
32310
|
+
* Resolves the first non-empty trimmed string from a prioritized list of values.
|
|
32311
|
+
*
|
|
32312
|
+
* @private internal timeout-chat helper
|
|
32313
|
+
*/
|
|
32314
|
+
function pickNormalizedStringValue(...values) {
|
|
32315
|
+
for (const value of values) {
|
|
32316
|
+
const normalizedStringValue = normalizeStringValue(value);
|
|
32317
|
+
if (normalizedStringValue !== null) {
|
|
32318
|
+
return normalizedStringValue;
|
|
32319
|
+
}
|
|
32320
|
+
}
|
|
32321
|
+
return null;
|
|
32322
|
+
}
|
|
31904
32323
|
/**
|
|
31905
32324
|
* Parses date-like values into a valid `Date`.
|
|
31906
32325
|
*
|
|
@@ -32241,6 +32660,39 @@ const MEMORY_CHIP_MAX_LENGTH = 48;
|
|
|
32241
32660
|
* Length of memory chip truncate.
|
|
32242
32661
|
*/
|
|
32243
32662
|
const MEMORY_CHIP_TRUNCATE_LENGTH = 45;
|
|
32663
|
+
/**
|
|
32664
|
+
* Tool names that render a localized current-time chip.
|
|
32665
|
+
*
|
|
32666
|
+
* @private utility of `<Chat/>`
|
|
32667
|
+
*/
|
|
32668
|
+
const TIME_TOOL_CALL_NAMES = new Set(['get_current_time', 'useTime']);
|
|
32669
|
+
/**
|
|
32670
|
+
* Tool names that render the email subject when available.
|
|
32671
|
+
*
|
|
32672
|
+
* @private utility of `<Chat/>`
|
|
32673
|
+
*/
|
|
32674
|
+
const EMAIL_TOOL_CALL_NAMES = new Set(['send_email', 'useEmail']);
|
|
32675
|
+
/**
|
|
32676
|
+
* Tool names that render a memory preview.
|
|
32677
|
+
*
|
|
32678
|
+
* @private utility of `<Chat/>`
|
|
32679
|
+
*/
|
|
32680
|
+
const MEMORY_TOOL_CALL_NAMES = new Set(['retrieve_user_memory', 'store_user_memory']);
|
|
32681
|
+
/**
|
|
32682
|
+
* Ordered specialized chiplet resolvers evaluated before the generic fallback.
|
|
32683
|
+
*
|
|
32684
|
+
* @private utility of `<Chat/>`
|
|
32685
|
+
*/
|
|
32686
|
+
const SPECIALIZED_TOOL_CALL_CHIPLET_RESOLVERS = [
|
|
32687
|
+
resolveWalletCredentialChipletInfo,
|
|
32688
|
+
resolveTeamToolCallChipletInfo,
|
|
32689
|
+
resolveTimeToolCallChipletInfo,
|
|
32690
|
+
resolveEmailToolCallChipletInfo,
|
|
32691
|
+
resolveMemoryToolCallChipletInfo,
|
|
32692
|
+
resolveTimeoutToolCallChipletInfo,
|
|
32693
|
+
resolveQueryToolCallChipletInfo,
|
|
32694
|
+
resolveUrlToolCallChipletInfo,
|
|
32695
|
+
];
|
|
32244
32696
|
/**
|
|
32245
32697
|
* Builds display text for a tool call chiplet.
|
|
32246
32698
|
*
|
|
@@ -32304,96 +32756,310 @@ const TOOL_TITLES = {
|
|
|
32304
32756
|
* @private [🧠] Maybe public?
|
|
32305
32757
|
*/
|
|
32306
32758
|
function getToolCallChipletInfo(toolCall, locale, titleOverrides, chipTranslations) {
|
|
32307
|
-
const
|
|
32308
|
-
|
|
32309
|
-
|
|
32759
|
+
const context = createToolCallChipletContext(toolCall, locale, titleOverrides, chipTranslations);
|
|
32760
|
+
return resolveSpecializedToolCallChipletInfo(context) || createDefaultToolCallChipletInfo(context);
|
|
32761
|
+
}
|
|
32762
|
+
/**
|
|
32763
|
+
* Collects the parsed values shared by all chiplet resolution steps.
|
|
32764
|
+
*
|
|
32765
|
+
* @param toolCall - Tool call being rendered.
|
|
32766
|
+
* @param locale - Optional locale used by time-sensitive helpers.
|
|
32767
|
+
* @param titleOverrides - Optional localized title overrides.
|
|
32768
|
+
* @param chipTranslations - Optional localized chip templates reused by specialized resolvers.
|
|
32769
|
+
* @returns Shared chiplet resolution context.
|
|
32770
|
+
*
|
|
32771
|
+
* @private utility of `<Chat/>`
|
|
32772
|
+
*/
|
|
32773
|
+
function createToolCallChipletContext(toolCall, locale, titleOverrides, chipTranslations) {
|
|
32310
32774
|
const args = parseToolCallArguments(toolCall);
|
|
32311
|
-
const isTimeTool = toolCall.name === 'get_current_time' || toolCall.name === 'useTime';
|
|
32312
|
-
const isEmailTool = toolCall.name === 'send_email' || toolCall.name === 'useEmail';
|
|
32313
|
-
const isMemoryTool = toolCall.name === 'retrieve_user_memory' || toolCall.name === 'store_user_memory';
|
|
32314
|
-
const isTimeoutTool = toolCall.name === 'set_timeout' || toolCall.name === 'cancel_timeout';
|
|
32315
32775
|
const resultRaw = parseToolCallResult(toolCall.result);
|
|
32316
|
-
|
|
32317
|
-
|
|
32318
|
-
|
|
32319
|
-
|
|
32320
|
-
|
|
32321
|
-
|
|
32322
|
-
|
|
32323
|
-
|
|
32324
|
-
:
|
|
32325
|
-
|
|
32326
|
-
|
|
32327
|
-
|
|
32328
|
-
|
|
32329
|
-
|
|
32330
|
-
|
|
32776
|
+
return {
|
|
32777
|
+
toolCall,
|
|
32778
|
+
locale,
|
|
32779
|
+
chipTranslations,
|
|
32780
|
+
args,
|
|
32781
|
+
resultRaw,
|
|
32782
|
+
baseTitle: resolveToolCallBaseTitle(toolCall.name, titleOverrides),
|
|
32783
|
+
emoji: resolveToolCallEmoji(toolCall.name),
|
|
32784
|
+
timeoutPresentation: resolveToolCallChipletTimeoutPresentation(toolCall.name, args, resultRaw, locale),
|
|
32785
|
+
};
|
|
32786
|
+
}
|
|
32787
|
+
/**
|
|
32788
|
+
* Resolves the first specialized chiplet branch that matches the tool call.
|
|
32789
|
+
*
|
|
32790
|
+
* @param context - Shared chiplet resolution context.
|
|
32791
|
+
* @returns Specialized chiplet info when any resolver matches, otherwise `null`.
|
|
32792
|
+
*
|
|
32793
|
+
* @private utility of `<Chat/>`
|
|
32794
|
+
*/
|
|
32795
|
+
function resolveSpecializedToolCallChipletInfo(context) {
|
|
32796
|
+
for (const resolveToolCallChipletInfo of SPECIALIZED_TOOL_CALL_CHIPLET_RESOLVERS) {
|
|
32797
|
+
const chipletInfo = resolveToolCallChipletInfo(context);
|
|
32798
|
+
if (chipletInfo) {
|
|
32799
|
+
return chipletInfo;
|
|
32800
|
+
}
|
|
32331
32801
|
}
|
|
32332
|
-
|
|
32333
|
-
|
|
32334
|
-
|
|
32335
|
-
|
|
32336
|
-
|
|
32337
|
-
|
|
32338
|
-
|
|
32339
|
-
|
|
32340
|
-
|
|
32341
|
-
|
|
32802
|
+
return null;
|
|
32803
|
+
}
|
|
32804
|
+
/**
|
|
32805
|
+
* Resolves the human-friendly fallback title for one tool call.
|
|
32806
|
+
*
|
|
32807
|
+
* @param toolName - Raw tool name.
|
|
32808
|
+
* @param titleOverrides - Optional localized title overrides.
|
|
32809
|
+
* @returns Title used when no specialized chip label applies.
|
|
32810
|
+
*
|
|
32811
|
+
* @private utility of `<Chat/>`
|
|
32812
|
+
*/
|
|
32813
|
+
function resolveToolCallBaseTitle(toolName, titleOverrides) {
|
|
32814
|
+
var _a;
|
|
32815
|
+
return (titleOverrides === null || titleOverrides === void 0 ? void 0 : titleOverrides[toolName]) || ((_a = TOOL_TITLES[toolName]) === null || _a === void 0 ? void 0 : _a.title) || toolName;
|
|
32816
|
+
}
|
|
32817
|
+
/**
|
|
32818
|
+
* Resolves the emoji prefix used by standard tool chips.
|
|
32819
|
+
*
|
|
32820
|
+
* @param toolName - Raw tool name.
|
|
32821
|
+
* @returns Emoji shown at the beginning of the chip.
|
|
32822
|
+
*
|
|
32823
|
+
* @private utility of `<Chat/>`
|
|
32824
|
+
*/
|
|
32825
|
+
function resolveToolCallEmoji(toolName) {
|
|
32826
|
+
var _a;
|
|
32827
|
+
return ((_a = TOOL_TITLES[toolName]) === null || _a === void 0 ? void 0 : _a.emoji) || '🛠️';
|
|
32828
|
+
}
|
|
32829
|
+
/**
|
|
32830
|
+
* Resolves timeout presentation metadata only for timeout-aware tools.
|
|
32831
|
+
*
|
|
32832
|
+
* @param toolName - Raw tool name.
|
|
32833
|
+
* @param args - Parsed tool arguments.
|
|
32834
|
+
* @param resultRaw - Parsed tool result payload.
|
|
32835
|
+
* @param locale - Optional locale used for friendly date formatting.
|
|
32836
|
+
* @returns Timeout presentation metadata or `null`.
|
|
32837
|
+
*
|
|
32838
|
+
* @private utility of `<Chat/>`
|
|
32839
|
+
*/
|
|
32840
|
+
function resolveToolCallChipletTimeoutPresentation(toolName, args, resultRaw, locale) {
|
|
32841
|
+
if (!isTimeoutToolCallName$1(toolName)) {
|
|
32842
|
+
return null;
|
|
32342
32843
|
}
|
|
32343
|
-
|
|
32344
|
-
|
|
32345
|
-
|
|
32346
|
-
|
|
32347
|
-
|
|
32348
|
-
|
|
32349
|
-
|
|
32350
|
-
|
|
32351
|
-
|
|
32844
|
+
return resolveTimeoutToolCallPresentation({
|
|
32845
|
+
toolCallName: toolName,
|
|
32846
|
+
args,
|
|
32847
|
+
resultRaw,
|
|
32848
|
+
currentDate: new Date(),
|
|
32849
|
+
locale,
|
|
32850
|
+
});
|
|
32851
|
+
}
|
|
32852
|
+
/**
|
|
32853
|
+
* Resolves a chip label for synthetic wallet-credential tool calls.
|
|
32854
|
+
*
|
|
32855
|
+
* @param context - Shared chiplet resolution context.
|
|
32856
|
+
* @returns Chiplet info when the tool result represents wallet credentials, otherwise `null`.
|
|
32857
|
+
*
|
|
32858
|
+
* @private utility of `<Chat/>`
|
|
32859
|
+
*/
|
|
32860
|
+
function resolveWalletCredentialChipletInfo(context) {
|
|
32861
|
+
const walletCredentialResult = parseWalletCredentialToolCallResult(context.resultRaw);
|
|
32862
|
+
if (!walletCredentialResult) {
|
|
32863
|
+
return null;
|
|
32352
32864
|
}
|
|
32353
|
-
|
|
32354
|
-
|
|
32355
|
-
|
|
32356
|
-
|
|
32357
|
-
|
|
32358
|
-
|
|
32865
|
+
return createEmojiToolCallChipletInfo(context, walletCredentialResult.credentialName);
|
|
32866
|
+
}
|
|
32867
|
+
/**
|
|
32868
|
+
* Resolves a chip label and agent metadata for TEAM tool calls.
|
|
32869
|
+
*
|
|
32870
|
+
* @param context - Shared chiplet resolution context.
|
|
32871
|
+
* @returns Chiplet info when the result contains teammate metadata, otherwise `null`.
|
|
32872
|
+
*
|
|
32873
|
+
* @private utility of `<Chat/>`
|
|
32874
|
+
*/
|
|
32875
|
+
function resolveTeamToolCallChipletInfo(context) {
|
|
32876
|
+
const teamResult = parseTeamToolResult(context.resultRaw);
|
|
32877
|
+
if (!(teamResult === null || teamResult === void 0 ? void 0 : teamResult.teammate)) {
|
|
32878
|
+
return null;
|
|
32359
32879
|
}
|
|
32360
|
-
|
|
32361
|
-
|
|
32362
|
-
|
|
32363
|
-
|
|
32364
|
-
|
|
32365
|
-
|
|
32366
|
-
|
|
32880
|
+
const label = teamResult.teammate.label || teamResult.teammate.url || context.baseTitle;
|
|
32881
|
+
const agentData = {
|
|
32882
|
+
url: teamResult.teammate.url,
|
|
32883
|
+
label,
|
|
32884
|
+
};
|
|
32885
|
+
return {
|
|
32886
|
+
text: label,
|
|
32887
|
+
agentData,
|
|
32888
|
+
};
|
|
32889
|
+
}
|
|
32890
|
+
/**
|
|
32891
|
+
* Resolves the specialized time chip label when the tool returns a valid date.
|
|
32892
|
+
*
|
|
32893
|
+
* @param context - Shared chiplet resolution context.
|
|
32894
|
+
* @returns Chiplet info when a time label can be built, otherwise `null`.
|
|
32895
|
+
*
|
|
32896
|
+
* @private utility of `<Chat/>`
|
|
32897
|
+
*/
|
|
32898
|
+
function resolveTimeToolCallChipletInfo(context) {
|
|
32899
|
+
var _a;
|
|
32900
|
+
if (!isTimeToolCallName$1(context.toolCall.name)) {
|
|
32901
|
+
return null;
|
|
32367
32902
|
}
|
|
32368
|
-
|
|
32369
|
-
|
|
32370
|
-
|
|
32371
|
-
};
|
|
32903
|
+
const resultDate = getToolCallResultDate(context.resultRaw);
|
|
32904
|
+
if (!resultDate) {
|
|
32905
|
+
return null;
|
|
32372
32906
|
}
|
|
32373
|
-
|
|
32374
|
-
|
|
32375
|
-
|
|
32376
|
-
|
|
32907
|
+
return createEmojiToolCallChipletInfo(context, formatToolCallTranslationTemplate(((_a = context.chipTranslations) === null || _a === void 0 ? void 0 : _a.toolCallTimeChipLabel) || '{time}', {
|
|
32908
|
+
time: formatToolCallLocalTime(resultDate, context.locale),
|
|
32909
|
+
}));
|
|
32910
|
+
}
|
|
32911
|
+
/**
|
|
32912
|
+
* Resolves the email-subject chip label when a subject is present.
|
|
32913
|
+
*
|
|
32914
|
+
* @param context - Shared chiplet resolution context.
|
|
32915
|
+
* @returns Chiplet info when the email subject can be shown, otherwise `null`.
|
|
32916
|
+
*
|
|
32917
|
+
* @private utility of `<Chat/>`
|
|
32918
|
+
*/
|
|
32919
|
+
function resolveEmailToolCallChipletInfo(context) {
|
|
32920
|
+
if (!isEmailToolCallName$1(context.toolCall.name) || typeof context.args.subject !== 'string') {
|
|
32921
|
+
return null;
|
|
32377
32922
|
}
|
|
32378
|
-
|
|
32379
|
-
|
|
32380
|
-
|
|
32381
|
-
|
|
32382
|
-
|
|
32383
|
-
|
|
32384
|
-
|
|
32385
|
-
|
|
32386
|
-
|
|
32387
|
-
|
|
32388
|
-
|
|
32389
|
-
|
|
32923
|
+
return createEmojiToolCallChipletInfo(context, context.args.subject);
|
|
32924
|
+
}
|
|
32925
|
+
/**
|
|
32926
|
+
* Resolves the memory-preview chip label for MEMORY tools.
|
|
32927
|
+
*
|
|
32928
|
+
* @param context - Shared chiplet resolution context.
|
|
32929
|
+
* @returns Chiplet info when a memory preview is available, otherwise `null`.
|
|
32930
|
+
*
|
|
32931
|
+
* @private utility of `<Chat/>`
|
|
32932
|
+
*/
|
|
32933
|
+
function resolveMemoryToolCallChipletInfo(context) {
|
|
32934
|
+
if (!isMemoryToolCallName(context.toolCall.name)) {
|
|
32935
|
+
return null;
|
|
32936
|
+
}
|
|
32937
|
+
const memoryPreview = getMemoryPreviewText(context.args, context.resultRaw);
|
|
32938
|
+
if (!memoryPreview) {
|
|
32939
|
+
return null;
|
|
32390
32940
|
}
|
|
32941
|
+
return createEmojiToolCallChipletInfo(context, memoryPreview);
|
|
32942
|
+
}
|
|
32943
|
+
/**
|
|
32944
|
+
* Resolves the timeout-specific chip label when timeout presentation metadata is available.
|
|
32945
|
+
*
|
|
32946
|
+
* @param context - Shared chiplet resolution context.
|
|
32947
|
+
* @returns Chiplet info when the tool is a timeout tool, otherwise `null`.
|
|
32948
|
+
*
|
|
32949
|
+
* @private utility of `<Chat/>`
|
|
32950
|
+
*/
|
|
32951
|
+
function resolveTimeoutToolCallChipletInfo(context) {
|
|
32952
|
+
if (!context.timeoutPresentation) {
|
|
32953
|
+
return null;
|
|
32954
|
+
}
|
|
32955
|
+
return createEmojiToolCallChipletInfo(context, buildTimeoutToolCallChipLabel(context.timeoutPresentation, context.chipTranslations));
|
|
32956
|
+
}
|
|
32957
|
+
/**
|
|
32958
|
+
* Resolves a query-based chip label used by search-like tools.
|
|
32959
|
+
*
|
|
32960
|
+
* @param context - Shared chiplet resolution context.
|
|
32961
|
+
* @returns Chiplet info when a query string is present, otherwise `null`.
|
|
32962
|
+
*
|
|
32963
|
+
* @private utility of `<Chat/>`
|
|
32964
|
+
*/
|
|
32965
|
+
function resolveQueryToolCallChipletInfo(context) {
|
|
32966
|
+
if (typeof context.args.query !== 'string') {
|
|
32967
|
+
return null;
|
|
32968
|
+
}
|
|
32969
|
+
return createEmojiToolCallChipletInfo(context, context.args.query);
|
|
32970
|
+
}
|
|
32971
|
+
/**
|
|
32972
|
+
* Resolves a URL-based chip label by preferring the hostname over the raw URL.
|
|
32973
|
+
*
|
|
32974
|
+
* @param context - Shared chiplet resolution context.
|
|
32975
|
+
* @returns Chiplet info when a URL string is present, otherwise `null`.
|
|
32976
|
+
*
|
|
32977
|
+
* @private utility of `<Chat/>`
|
|
32978
|
+
*/
|
|
32979
|
+
function resolveUrlToolCallChipletInfo(context) {
|
|
32980
|
+
if (typeof context.args.url !== 'string') {
|
|
32981
|
+
return null;
|
|
32982
|
+
}
|
|
32983
|
+
return createEmojiToolCallChipletInfo(context, resolveUrlChipLabel(context.args.url));
|
|
32984
|
+
}
|
|
32985
|
+
/**
|
|
32986
|
+
* Builds the final fallback chip label when no specialized branch matches.
|
|
32987
|
+
*
|
|
32988
|
+
* @param context - Shared chiplet resolution context.
|
|
32989
|
+
* @returns Fallback chiplet info.
|
|
32990
|
+
*
|
|
32991
|
+
* @private utility of `<Chat/>`
|
|
32992
|
+
*/
|
|
32993
|
+
function createDefaultToolCallChipletInfo(context) {
|
|
32994
|
+
return createEmojiToolCallChipletInfo(context, context.baseTitle);
|
|
32995
|
+
}
|
|
32996
|
+
/**
|
|
32997
|
+
* Builds a standard emoji-prefixed chip info object.
|
|
32998
|
+
*
|
|
32999
|
+
* @param context - Shared chiplet resolution context.
|
|
33000
|
+
* @param label - User-facing chip label without emoji prefix.
|
|
33001
|
+
* @returns Emoji-prefixed chiplet info.
|
|
33002
|
+
*
|
|
33003
|
+
* @private utility of `<Chat/>`
|
|
33004
|
+
*/
|
|
33005
|
+
function createEmojiToolCallChipletInfo(context, label) {
|
|
32391
33006
|
return {
|
|
32392
|
-
text: `${emoji} ${
|
|
33007
|
+
text: `${context.emoji} ${label}`,
|
|
32393
33008
|
};
|
|
32394
33009
|
}
|
|
33010
|
+
/**
|
|
33011
|
+
* Resolves a friendly URL chip label, preferring the hostname over the raw input.
|
|
33012
|
+
*
|
|
33013
|
+
* @param rawUrl - Raw URL argument value.
|
|
33014
|
+
* @returns Hostname when URL parsing succeeds, otherwise the original string.
|
|
33015
|
+
*
|
|
33016
|
+
* @private utility of `<Chat/>`
|
|
33017
|
+
*/
|
|
33018
|
+
function resolveUrlChipLabel(rawUrl) {
|
|
33019
|
+
try {
|
|
33020
|
+
return new URL(rawUrl).hostname;
|
|
33021
|
+
}
|
|
33022
|
+
catch (_a) {
|
|
33023
|
+
return rawUrl;
|
|
33024
|
+
}
|
|
33025
|
+
}
|
|
33026
|
+
/**
|
|
33027
|
+
* Checks whether a tool name belongs to the time commitment.
|
|
33028
|
+
*
|
|
33029
|
+
* @param toolName - Raw tool name.
|
|
33030
|
+
* @returns `true` when the chip should show a localized time label.
|
|
33031
|
+
*
|
|
33032
|
+
* @private utility of `<Chat/>`
|
|
33033
|
+
*/
|
|
33034
|
+
function isTimeToolCallName$1(toolName) {
|
|
33035
|
+
return TIME_TOOL_CALL_NAMES.has(toolName);
|
|
33036
|
+
}
|
|
33037
|
+
/**
|
|
33038
|
+
* Checks whether a tool name belongs to the email commitment.
|
|
33039
|
+
*
|
|
33040
|
+
* @param toolName - Raw tool name.
|
|
33041
|
+
* @returns `true` when the chip may show an email subject.
|
|
33042
|
+
*
|
|
33043
|
+
* @private utility of `<Chat/>`
|
|
33044
|
+
*/
|
|
33045
|
+
function isEmailToolCallName$1(toolName) {
|
|
33046
|
+
return EMAIL_TOOL_CALL_NAMES.has(toolName);
|
|
33047
|
+
}
|
|
33048
|
+
/**
|
|
33049
|
+
* Checks whether a tool name belongs to the memory commitment.
|
|
33050
|
+
*
|
|
33051
|
+
* @param toolName - Raw tool name.
|
|
33052
|
+
* @returns `true` when the chip may show a memory preview.
|
|
33053
|
+
*
|
|
33054
|
+
* @private utility of `<Chat/>`
|
|
33055
|
+
*/
|
|
33056
|
+
function isMemoryToolCallName(toolName) {
|
|
33057
|
+
return MEMORY_TOOL_CALL_NAMES.has(toolName);
|
|
33058
|
+
}
|
|
32395
33059
|
/**
|
|
32396
33060
|
* Builds memory preview text for MEMORY commitment tool calls.
|
|
33061
|
+
*
|
|
33062
|
+
* @private utility of `<Chat/>`
|
|
32397
33063
|
*/
|
|
32398
33064
|
function getMemoryPreviewText(args, resultRaw) {
|
|
32399
33065
|
var _a, _b, _c;
|
|
@@ -32416,6 +33082,8 @@ function getMemoryPreviewText(args, resultRaw) {
|
|
|
32416
33082
|
}
|
|
32417
33083
|
/**
|
|
32418
33084
|
* Shortens long memory content for compact chip display.
|
|
33085
|
+
*
|
|
33086
|
+
* @private utility of `<Chat/>`
|
|
32419
33087
|
*/
|
|
32420
33088
|
function shortenMemoryPreview(content) {
|
|
32421
33089
|
const trimmed = content.trim().replace(/\s+/g, ' ');
|
|
@@ -55459,26 +56127,13 @@ var styles = {"PromptbookAgentSeamlessIntegration":"PromptbookAgentSeamlessInteg
|
|
|
55459
56127
|
styleInject(css_248z);
|
|
55460
56128
|
|
|
55461
56129
|
/**
|
|
55462
|
-
*
|
|
56130
|
+
* Handles controlled/uncontrolled open state for the widget.
|
|
55463
56131
|
*
|
|
55464
|
-
* @private
|
|
56132
|
+
* @private internal hook of PromptbookAgentSeamlessIntegration
|
|
55465
56133
|
*/
|
|
55466
|
-
function
|
|
55467
|
-
var _a, _b;
|
|
55468
|
-
const { agentUrl, meta, onOpenChange, isOpen: controlledIsOpen, defaultOpen = false, className, style, isFocusedOnLoad, isIframeUsed = false, } = props;
|
|
56134
|
+
function usePromptbookAgentSeamlessIntegrationOpenState({ agentUrl, defaultOpen = false, isOpen: controlledIsOpen, onOpenChange, }) {
|
|
55469
56135
|
const [internalIsOpen, setInternalIsOpen] = useState(defaultOpen);
|
|
55470
|
-
const [headerElement, setHeaderElement] = useState(null);
|
|
55471
|
-
const [isIframeLoaded, setIsIframeLoaded] = useState(false);
|
|
55472
|
-
const [isChatConnected, setIsChatConnected] = useState(false);
|
|
55473
|
-
const rootElementRef = useRef(null);
|
|
55474
|
-
const windowId = useId();
|
|
55475
56136
|
const isOpen = controlledIsOpen !== null && controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
|
|
55476
|
-
/**
|
|
55477
|
-
* Updates the widget open state and notifies integration callbacks.
|
|
55478
|
-
*
|
|
55479
|
-
* @param nextIsOpen - Target open state.
|
|
55480
|
-
* @private internal utility of PromptbookAgentSeamlessIntegration
|
|
55481
|
-
*/
|
|
55482
56137
|
const setOpen = useCallback((nextIsOpen) => {
|
|
55483
56138
|
if (controlledIsOpen === undefined) {
|
|
55484
56139
|
setInternalIsOpen(nextIsOpen);
|
|
@@ -55491,22 +56146,21 @@ function PromptbookAgentSeamlessIntegration(props) {
|
|
|
55491
56146
|
}
|
|
55492
56147
|
setInternalIsOpen(defaultOpen);
|
|
55493
56148
|
}, [agentUrl, controlledIsOpen, defaultOpen]);
|
|
55494
|
-
|
|
55495
|
-
|
|
55496
|
-
|
|
55497
|
-
|
|
55498
|
-
|
|
55499
|
-
|
|
55500
|
-
|
|
55501
|
-
|
|
55502
|
-
}, [agentUrl]);
|
|
56149
|
+
return { isOpen, setOpen };
|
|
56150
|
+
}
|
|
56151
|
+
/**
|
|
56152
|
+
* Closes the widget when the user presses Escape or clicks outside.
|
|
56153
|
+
*
|
|
56154
|
+
* @private internal hook of PromptbookAgentSeamlessIntegration
|
|
56155
|
+
*/
|
|
56156
|
+
function useClosePromptbookAgentSeamlessIntegrationOnOutsideInteraction({ isOpen, rootElementRef, onClose, }) {
|
|
55503
56157
|
useEffect(() => {
|
|
55504
56158
|
if (!isOpen) {
|
|
55505
56159
|
return;
|
|
55506
56160
|
}
|
|
55507
56161
|
const handleKeyDown = (event) => {
|
|
55508
56162
|
if (event.key === 'Escape') {
|
|
55509
|
-
|
|
56163
|
+
onClose();
|
|
55510
56164
|
}
|
|
55511
56165
|
};
|
|
55512
56166
|
const handlePointerDown = (event) => {
|
|
@@ -55518,7 +56172,7 @@ function PromptbookAgentSeamlessIntegration(props) {
|
|
|
55518
56172
|
if (target instanceof Node && rootElement.contains(target)) {
|
|
55519
56173
|
return;
|
|
55520
56174
|
}
|
|
55521
|
-
|
|
56175
|
+
onClose();
|
|
55522
56176
|
};
|
|
55523
56177
|
window.addEventListener('keydown', handleKeyDown);
|
|
55524
56178
|
window.addEventListener('pointerdown', handlePointerDown);
|
|
@@ -55526,23 +56180,22 @@ function PromptbookAgentSeamlessIntegration(props) {
|
|
|
55526
56180
|
window.removeEventListener('keydown', handleKeyDown);
|
|
55527
56181
|
window.removeEventListener('pointerdown', handlePointerDown);
|
|
55528
56182
|
};
|
|
55529
|
-
}, [isOpen,
|
|
56183
|
+
}, [isOpen, onClose, rootElementRef]);
|
|
56184
|
+
}
|
|
56185
|
+
/**
|
|
56186
|
+
* Connects to the remote agent and tracks the connection lifecycle.
|
|
56187
|
+
*
|
|
56188
|
+
* @private internal hook of PromptbookAgentSeamlessIntegration
|
|
56189
|
+
*/
|
|
56190
|
+
function useRemotePromptbookAgent(agentUrl) {
|
|
55530
56191
|
const [agent, setAgent] = useState(null);
|
|
55531
56192
|
const [error, setError] = useState(null);
|
|
55532
|
-
|
|
55533
|
-
if (agent && meta) {
|
|
55534
|
-
if (agent.meta.image && meta.image && agent.meta.image !== meta.image) {
|
|
55535
|
-
console.warn('Conflict in agent meta image:', { server: agent.meta.image, props: meta.image });
|
|
55536
|
-
}
|
|
55537
|
-
if (agent.meta.color && meta.color && agent.meta.color !== meta.color) {
|
|
55538
|
-
console.warn('Conflict in agent meta color:', { server: agent.meta.color, props: meta.color });
|
|
55539
|
-
}
|
|
55540
|
-
}
|
|
55541
|
-
}, [agent, meta]);
|
|
56193
|
+
const [isAgentConnected, setIsAgentConnected] = useState(false);
|
|
55542
56194
|
useEffect(() => {
|
|
55543
56195
|
let isMounted = true;
|
|
55544
56196
|
setAgent(null);
|
|
55545
56197
|
setError(null);
|
|
56198
|
+
setIsAgentConnected(false);
|
|
55546
56199
|
const connectToAgent = async () => {
|
|
55547
56200
|
try {
|
|
55548
56201
|
// TODO: [🧠] Maybe we should not connect immediately but only when the user clicks the button or hovers?
|
|
@@ -55550,7 +56203,7 @@ function PromptbookAgentSeamlessIntegration(props) {
|
|
|
55550
56203
|
const connectedAgent = await RemoteAgent.connect({ agentUrl });
|
|
55551
56204
|
if (isMounted) {
|
|
55552
56205
|
setAgent(connectedAgent);
|
|
55553
|
-
|
|
56206
|
+
setIsAgentConnected(true);
|
|
55554
56207
|
}
|
|
55555
56208
|
}
|
|
55556
56209
|
catch (err) {
|
|
@@ -55565,30 +56218,169 @@ function PromptbookAgentSeamlessIntegration(props) {
|
|
|
55565
56218
|
isMounted = false;
|
|
55566
56219
|
};
|
|
55567
56220
|
}, [agentUrl]);
|
|
55568
|
-
|
|
55569
|
-
|
|
55570
|
-
|
|
55571
|
-
|
|
55572
|
-
|
|
55573
|
-
|
|
55574
|
-
|
|
55575
|
-
|
|
56221
|
+
return { agent, error, isAgentConnected };
|
|
56222
|
+
}
|
|
56223
|
+
/**
|
|
56224
|
+
* Warns when props branding conflicts with the branding returned by the server.
|
|
56225
|
+
*
|
|
56226
|
+
* @private internal hook of PromptbookAgentSeamlessIntegration
|
|
56227
|
+
*/
|
|
56228
|
+
function useWarnAboutPromptbookAgentMetaConflicts(agent, meta) {
|
|
56229
|
+
useEffect(() => {
|
|
56230
|
+
if (!agent || !meta) {
|
|
56231
|
+
return;
|
|
56232
|
+
}
|
|
56233
|
+
if (agent.meta.image && meta.image && agent.meta.image !== meta.image) {
|
|
56234
|
+
console.warn('Conflict in agent meta image:', { server: agent.meta.image, props: meta.image });
|
|
56235
|
+
}
|
|
56236
|
+
if (agent.meta.color && meta.color && agent.meta.color !== meta.color) {
|
|
56237
|
+
console.warn('Conflict in agent meta color:', { server: agent.meta.color, props: meta.color });
|
|
56238
|
+
}
|
|
56239
|
+
}, [agent, meta]);
|
|
56240
|
+
}
|
|
56241
|
+
/**
|
|
56242
|
+
* Resolves the avatar, color, and display name shown by the widget.
|
|
56243
|
+
*
|
|
56244
|
+
* @private internal utility of PromptbookAgentSeamlessIntegration
|
|
56245
|
+
*/
|
|
56246
|
+
function resolvePromptbookAgentSeamlessIntegrationDisplayInfo({ agent, agentUrl, meta, }) {
|
|
56247
|
+
var _a, _b;
|
|
56248
|
+
return {
|
|
56249
|
+
image: ((_a = agent === null || agent === void 0 ? void 0 : agent.meta) === null || _a === void 0 ? void 0 : _a.image) ||
|
|
56250
|
+
(meta === null || meta === void 0 ? void 0 : meta.image) ||
|
|
56251
|
+
// Note: [🤹] Using default avatar from the agent server
|
|
56252
|
+
`${agentUrl}/images/default-avatar.png`,
|
|
56253
|
+
color: ((_b = agent === null || agent === void 0 ? void 0 : agent.meta) === null || _b === void 0 ? void 0 : _b.color) || (meta === null || meta === void 0 ? void 0 : meta.color),
|
|
56254
|
+
displayName: (agent === null || agent === void 0 ? void 0 : agent.meta.fullname) || (meta === null || meta === void 0 ? void 0 : meta.fullname) || (agent === null || agent === void 0 ? void 0 : agent.agentName) || 'Chat with Agent',
|
|
56255
|
+
};
|
|
56256
|
+
}
|
|
56257
|
+
/**
|
|
56258
|
+
* Resolves the connection status label and indicator class.
|
|
56259
|
+
*
|
|
56260
|
+
* @private internal utility of PromptbookAgentSeamlessIntegration
|
|
56261
|
+
*/
|
|
56262
|
+
function createPromptbookAgentSeamlessIntegrationConnectionPresentation({ isConnected, error, isIframeUsed, }) {
|
|
55576
56263
|
let connectionStatus = 'pending';
|
|
55577
|
-
if (
|
|
56264
|
+
if (isConnected) {
|
|
55578
56265
|
connectionStatus = 'connected';
|
|
55579
56266
|
}
|
|
55580
56267
|
else if (error && !isIframeUsed) {
|
|
55581
56268
|
connectionStatus = 'error';
|
|
55582
56269
|
}
|
|
55583
|
-
|
|
55584
|
-
|
|
55585
|
-
|
|
55586
|
-
|
|
55587
|
-
|
|
55588
|
-
|
|
55589
|
-
|
|
55590
|
-
|
|
55591
|
-
|
|
56270
|
+
return {
|
|
56271
|
+
connectionStatus,
|
|
56272
|
+
connectionStatusText: connectionStatus === 'connected'
|
|
56273
|
+
? 'Online'
|
|
56274
|
+
: connectionStatus === 'error'
|
|
56275
|
+
? 'Connection issue'
|
|
56276
|
+
: 'Connecting',
|
|
56277
|
+
connectionStatusClassName: getPromptbookAgentSeamlessIntegrationStatusClassName(connectionStatus),
|
|
56278
|
+
};
|
|
56279
|
+
}
|
|
56280
|
+
/**
|
|
56281
|
+
* Resolves the CSS class for the connection status indicator.
|
|
56282
|
+
*
|
|
56283
|
+
* @private internal utility of PromptbookAgentSeamlessIntegration
|
|
56284
|
+
*/
|
|
56285
|
+
function getPromptbookAgentSeamlessIntegrationStatusClassName(connectionStatus) {
|
|
56286
|
+
if (connectionStatus === 'connected') {
|
|
56287
|
+
return styles.PromptbookAgentSeamlessIntegrationStatusConnected;
|
|
56288
|
+
}
|
|
56289
|
+
if (connectionStatus === 'error') {
|
|
56290
|
+
return styles.PromptbookAgentSeamlessIntegrationStatusError;
|
|
56291
|
+
}
|
|
56292
|
+
return styles.PromptbookAgentSeamlessIntegrationStatusPending;
|
|
56293
|
+
}
|
|
56294
|
+
/**
|
|
56295
|
+
* Renders the shared close button used by the widget.
|
|
56296
|
+
*
|
|
56297
|
+
* @private internal subcomponent of PromptbookAgentSeamlessIntegration
|
|
56298
|
+
*/
|
|
56299
|
+
function PromptbookAgentSeamlessIntegrationCloseButton({ onClose, }) {
|
|
56300
|
+
return (jsx("button", { className: styles.PromptbookAgentSeamlessIntegrationClose, onClick: onClose, title: "Close", "aria-label": "Close chat", children: jsx(CloseIcon, {}) }));
|
|
56301
|
+
}
|
|
56302
|
+
/**
|
|
56303
|
+
* Renders the loading state shared by iframe and embedded chat modes.
|
|
56304
|
+
*
|
|
56305
|
+
* @private internal subcomponent of PromptbookAgentSeamlessIntegration
|
|
56306
|
+
*/
|
|
56307
|
+
function PromptbookAgentSeamlessIntegrationLoadingState({ displayName, }) {
|
|
56308
|
+
return (jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationLoading, children: [jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationLoadingShimmer }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationLoadingSpinner }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationLoadingTitle, children: "Preparing your chat" }), jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationLoadingText, children: ["Connecting to ", displayName, "..."] })] }));
|
|
56309
|
+
}
|
|
56310
|
+
/**
|
|
56311
|
+
* Renders the inline error state for direct chat mode.
|
|
56312
|
+
*
|
|
56313
|
+
* @private internal subcomponent of PromptbookAgentSeamlessIntegration
|
|
56314
|
+
*/
|
|
56315
|
+
function PromptbookAgentSeamlessIntegrationErrorState({ error }) {
|
|
56316
|
+
return (jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationError, children: [jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationErrorTitle, children: "Failed to connect to the agent" }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationErrorMessage, children: error.message })] }));
|
|
56317
|
+
}
|
|
56318
|
+
/**
|
|
56319
|
+
* Renders the main content area based on the selected integration mode.
|
|
56320
|
+
*
|
|
56321
|
+
* @private internal subcomponent of PromptbookAgentSeamlessIntegration
|
|
56322
|
+
*/
|
|
56323
|
+
function PromptbookAgentSeamlessIntegrationContent({ agent, agentUrl, displayName, error, headerElement, isFocusedOnLoad, isIframeLoaded, isIframeUsed, onClose, onIframeLoad, }) {
|
|
56324
|
+
if (isIframeUsed) {
|
|
56325
|
+
return (jsxs(Fragment, { children: [!isIframeLoaded && jsx(PromptbookAgentSeamlessIntegrationLoadingState, { displayName: displayName }), jsx("iframe", { src: agentUrl + '/chat?headless', className: styles.PromptbookAgentSeamlessIntegrationIframe, style: { opacity: isIframeLoaded ? 1 : 0 }, tabIndex: -1, onLoad: onIframeLoad })] }));
|
|
56326
|
+
}
|
|
56327
|
+
if (agent) {
|
|
56328
|
+
return (jsx(AgentChat, { agent: agent, actionsContainer: headerElement, isFocusedOnLoad: isFocusedOnLoad, extraActions: jsx(PromptbookAgentSeamlessIntegrationCloseButton, { onClose: onClose }), layout: "STANDALONE" }));
|
|
56329
|
+
}
|
|
56330
|
+
if (error) {
|
|
56331
|
+
return jsx(PromptbookAgentSeamlessIntegrationErrorState, { error: error });
|
|
56332
|
+
}
|
|
56333
|
+
return jsx(PromptbookAgentSeamlessIntegrationLoadingState, { displayName: displayName });
|
|
56334
|
+
}
|
|
56335
|
+
/**
|
|
56336
|
+
* Renders a floating agent button that opens a chat window with the remote agent.
|
|
56337
|
+
*
|
|
56338
|
+
* @private component of PromptbookAgentIntegration
|
|
56339
|
+
*/
|
|
56340
|
+
function PromptbookAgentSeamlessIntegration(props) {
|
|
56341
|
+
const { agentUrl, meta, className, style, isFocusedOnLoad, isIframeUsed = false } = props;
|
|
56342
|
+
const [headerElement, setHeaderElement] = useState(null);
|
|
56343
|
+
const [isIframeLoaded, setIsIframeLoaded] = useState(false);
|
|
56344
|
+
const rootElementRef = useRef(null);
|
|
56345
|
+
const windowId = useId();
|
|
56346
|
+
const { isOpen, setOpen } = usePromptbookAgentSeamlessIntegrationOpenState(props);
|
|
56347
|
+
const { agent, error, isAgentConnected } = useRemotePromptbookAgent(agentUrl);
|
|
56348
|
+
const handleClose = useCallback(() => {
|
|
56349
|
+
setOpen(false);
|
|
56350
|
+
}, [setOpen]);
|
|
56351
|
+
const handleToggle = useCallback(() => {
|
|
56352
|
+
setOpen(!isOpen);
|
|
56353
|
+
}, [isOpen, setOpen]);
|
|
56354
|
+
const handleIframeLoad = useCallback(() => {
|
|
56355
|
+
setIsIframeLoaded(true);
|
|
56356
|
+
}, []);
|
|
56357
|
+
useEffect(() => {
|
|
56358
|
+
if (!isOpen) {
|
|
56359
|
+
setIsIframeLoaded(false);
|
|
56360
|
+
}
|
|
56361
|
+
}, [isOpen]);
|
|
56362
|
+
useEffect(() => {
|
|
56363
|
+
setIsIframeLoaded(false);
|
|
56364
|
+
}, [agentUrl]);
|
|
56365
|
+
useClosePromptbookAgentSeamlessIntegrationOnOutsideInteraction({
|
|
56366
|
+
isOpen,
|
|
56367
|
+
rootElementRef,
|
|
56368
|
+
onClose: handleClose,
|
|
56369
|
+
});
|
|
56370
|
+
useWarnAboutPromptbookAgentMetaConflicts(agent, meta);
|
|
56371
|
+
// TODO: [🧠] Handle loading state better (show spinner or skeleton in the chat window)
|
|
56372
|
+
// TODO: [🧠] Handle error state (show error message in the chat window)
|
|
56373
|
+
const { image, color, displayName } = resolvePromptbookAgentSeamlessIntegrationDisplayInfo({
|
|
56374
|
+
agent,
|
|
56375
|
+
agentUrl,
|
|
56376
|
+
meta,
|
|
56377
|
+
});
|
|
56378
|
+
const { connectionStatusText, connectionStatusClassName } = createPromptbookAgentSeamlessIntegrationConnectionPresentation({
|
|
56379
|
+
isConnected: isAgentConnected || isIframeLoaded,
|
|
56380
|
+
error,
|
|
56381
|
+
isIframeUsed,
|
|
56382
|
+
});
|
|
56383
|
+
return (jsxs("div", { className: classNames(`${styles.PromptbookAgentSeamlessIntegration} ${isOpen ? styles.open : styles.closed}`, className), style: style, ref: rootElementRef, children: [jsxs("button", { type: "button", className: styles.PromptbookAgentSeamlessIntegrationButton, onClick: handleToggle, style: { backgroundColor: color }, "aria-expanded": isOpen, "aria-controls": windowId, title: isOpen ? `Close chat with ${displayName}` : `Open chat with ${displayName}`, children: [jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationAvatar, children: jsx("img", { src: image, alt: `${displayName} avatar` }) }), jsx("div", { className: classNames(styles.PromptbookAgentSeamlessIntegrationStatus, connectionStatusClassName) }), jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationText, children: [jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationLabel, children: "Chat" }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationHint, children: displayName })] }), jsx("span", { className: styles.PromptbookAgentSeamlessIntegrationScreenReaderOnly, children: connectionStatusText })] }), isOpen && (jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationWindow, id: windowId, children: [jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationHeader, style: { backgroundColor: color }, ref: setHeaderElement, children: [jsxs("div", { className: styles.PromptbookAgentSeamlessIntegrationTitleWrap, children: [jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationTitle, children: displayName }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationSubtitle, children: connectionStatusText })] }), isIframeUsed && jsx(PromptbookAgentSeamlessIntegrationCloseButton, { onClose: handleClose })] }), jsx("div", { className: styles.PromptbookAgentSeamlessIntegrationContent, children: jsx(PromptbookAgentSeamlessIntegrationContent, { agent: agent, agentUrl: agentUrl, displayName: displayName, error: error, headerElement: headerElement, isFocusedOnLoad: isFocusedOnLoad, isIframeLoaded: isIframeLoaded, isIframeUsed: isIframeUsed, onClose: handleClose, onIframeLoad: handleIframeLoad }) })] }))] }));
|
|
55592
56384
|
}
|
|
55593
56385
|
|
|
55594
56386
|
/**
|