pika-shared 1.4.2 → 1.4.4

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.
@@ -1,5 +1,5 @@
1
1
  import { UploadStatus } from '../upload-types.mjs';
2
- import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.mjs';
2
+ import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, ChatAppActionMenu, ChatAppAction, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.mjs';
3
3
  import '@aws-sdk/client-bedrock-agent-runtime';
4
4
  import '@aws-sdk/client-bedrock-agentcore';
5
5
 
@@ -174,6 +174,8 @@ interface IChatAppState {
174
174
  readonly chatApp: ChatApp;
175
175
  readonly retrievingMessages: boolean;
176
176
  readonly pageTitle: string | undefined;
177
+ readonly customDataForChatApp: Record<string, unknown> | undefined;
178
+ readonly customTitleBarActions: (ChatAppActionMenu | ChatAppAction)[];
177
179
  setCurrentSessionById(sessionId: string): void;
178
180
  removeFile(s3Key: string): void;
179
181
  startNewChatSession(): void;
@@ -187,6 +189,8 @@ interface IChatAppState {
187
189
  renderTag(tagId: string, context: 'spotlight' | 'inline' | 'dialog' | 'canvas', data?: Record<string, any>): Promise<void>;
188
190
  closeCanvas(): void;
189
191
  closeDialog(): void;
192
+ setOrUpdateCustomTitleBarAction(action: ChatAppActionMenu | ChatAppAction): void;
193
+ removeCustomTitleBarAction(actionId: string): void;
190
194
  /**
191
195
  * Invoke the agent directly from a web component using the 'chat-app-component' invocation mode.
192
196
  * This allows components to make out-of-band requests to the LLM without creating user sessions.
@@ -276,6 +280,28 @@ interface IChatAppState {
276
280
  * ```
277
281
  */
278
282
  getWidgetMetadataAPI(scope: string, tag: string, instanceId: string, renderingContext: WidgetRenderingContextType): IWidgetMetadataAPI;
283
+ /**
284
+ * Retrieve text content from an S3 file stored in the Pika S3 bucket.
285
+ * This is a secure helper that allows web components to access files without
286
+ * needing to manage AWS credentials or know the bucket name.
287
+ *
288
+ * @param s3Key - The S3 key (path) to the file in the Pika S3 bucket
289
+ * @returns Promise that resolves to the file content as a string
290
+ * @throws Error if the file doesn't exist or cannot be accessed
291
+ *
292
+ * @example
293
+ * ```js
294
+ * const context = await getPikaContext($host());
295
+ * try {
296
+ * const content = await context.chatAppState.getS3TextFileContent('data/config.json');
297
+ * const config = JSON.parse(content);
298
+ * console.log('Config loaded:', config);
299
+ * } catch (error) {
300
+ * console.error('Failed to load config:', error);
301
+ * }
302
+ * ```
303
+ */
304
+ getS3TextFileContent(s3Key: string): Promise<string>;
279
305
  }
280
306
  interface IUserPrefsState {
281
307
  readonly initialized: boolean;
@@ -1,5 +1,5 @@
1
1
  import { UploadStatus } from '../upload-types.js';
2
- import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.js';
2
+ import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, ChatAppActionMenu, ChatAppAction, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.js';
3
3
  import '@aws-sdk/client-bedrock-agent-runtime';
4
4
  import '@aws-sdk/client-bedrock-agentcore';
5
5
 
@@ -174,6 +174,8 @@ interface IChatAppState {
174
174
  readonly chatApp: ChatApp;
175
175
  readonly retrievingMessages: boolean;
176
176
  readonly pageTitle: string | undefined;
177
+ readonly customDataForChatApp: Record<string, unknown> | undefined;
178
+ readonly customTitleBarActions: (ChatAppActionMenu | ChatAppAction)[];
177
179
  setCurrentSessionById(sessionId: string): void;
178
180
  removeFile(s3Key: string): void;
179
181
  startNewChatSession(): void;
@@ -187,6 +189,8 @@ interface IChatAppState {
187
189
  renderTag(tagId: string, context: 'spotlight' | 'inline' | 'dialog' | 'canvas', data?: Record<string, any>): Promise<void>;
188
190
  closeCanvas(): void;
189
191
  closeDialog(): void;
192
+ setOrUpdateCustomTitleBarAction(action: ChatAppActionMenu | ChatAppAction): void;
193
+ removeCustomTitleBarAction(actionId: string): void;
190
194
  /**
191
195
  * Invoke the agent directly from a web component using the 'chat-app-component' invocation mode.
192
196
  * This allows components to make out-of-band requests to the LLM without creating user sessions.
@@ -276,6 +280,28 @@ interface IChatAppState {
276
280
  * ```
277
281
  */
278
282
  getWidgetMetadataAPI(scope: string, tag: string, instanceId: string, renderingContext: WidgetRenderingContextType): IWidgetMetadataAPI;
283
+ /**
284
+ * Retrieve text content from an S3 file stored in the Pika S3 bucket.
285
+ * This is a secure helper that allows web components to access files without
286
+ * needing to manage AWS credentials or know the bucket name.
287
+ *
288
+ * @param s3Key - The S3 key (path) to the file in the Pika S3 bucket
289
+ * @returns Promise that resolves to the file content as a string
290
+ * @throws Error if the file doesn't exist or cannot be accessed
291
+ *
292
+ * @example
293
+ * ```js
294
+ * const context = await getPikaContext($host());
295
+ * try {
296
+ * const content = await context.chatAppState.getS3TextFileContent('data/config.json');
297
+ * const config = JSON.parse(content);
298
+ * console.log('Config loaded:', config);
299
+ * } catch (error) {
300
+ * console.error('Failed to load config:', error);
301
+ * }
302
+ * ```
303
+ */
304
+ getS3TextFileContent(s3Key: string): Promise<string>;
279
305
  }
280
306
  interface IUserPrefsState {
281
307
  readonly initialized: boolean;
@@ -2,14 +2,6 @@
2
2
 
3
3
  // src/util/instruction-assistance-utils.ts
4
4
  function generateInstructionAssistanceContent(instructionAssistanceConfig, tags, agentInstructionFeature, tagDefinitions) {
5
- console.log("Generating instruction assistance content:", {
6
- enabled: agentInstructionFeature?.enabled,
7
- includeOutputFormattingRequirements: agentInstructionFeature?.includeOutputFormattingRequirements,
8
- includeInstructionsForTags: agentInstructionFeature?.includeInstructionsForTags,
9
- completeExampleEnabled: agentInstructionFeature?.completeExampleInstructionEnabled,
10
- jsonOnlyEnabled: agentInstructionFeature?.jsonOnlyImperativeInstructionEnabled,
11
- includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature?.includeTypescriptBackedOutputFormattingRequirements
12
- });
13
5
  let outputFormattingRequirements = "";
14
6
  let tagInstructions = "";
15
7
  let completeExampleInstructionLine = "";
@@ -29,18 +21,43 @@ function generateInstructionAssistanceContent(instructionAssistanceConfig, tags,
29
21
  - **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.
30
22
  - **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;
31
23
  }
32
- if (agentInstructionFeature.includeInstructionsForTags && tags && tags.tagsEnabled?.length > 0) {
33
- console.log("Fetching tag definitions for instruction generation:", tags.tagsEnabled);
24
+ if (agentInstructionFeature.includeInstructionsForTags && tags) {
34
25
  if (tagDefinitions.length > 0) {
35
- const tagDictionary = tagDefinitions.filter((tagDef) => tagDef.canBeGeneratedByLlm && tagDef.status === "enabled").map((tagDef) => ` - ${tagDef.tagTitle}: \`${tagDef.shortTagEx}\``).join("\n");
26
+ const enabledTagIds = /* @__PURE__ */ new Set();
27
+ if (tags.tagsEnabled) {
28
+ for (const tag of tags.tagsEnabled) {
29
+ const tagId = `${tag.scope}.${tag.tag}`;
30
+ enabledTagIds.add(tagId);
31
+ }
32
+ }
33
+ const disabledTagIds = /* @__PURE__ */ new Set();
34
+ if (tags.tagsDisabled) {
35
+ for (const tag of tags.tagsDisabled) {
36
+ const tagId = `${tag.scope}.${tag.tag}`;
37
+ disabledTagIds.add(tagId);
38
+ }
39
+ }
40
+ for (const tagDef of tagDefinitions) {
41
+ if (tagDef.usageMode === "global") {
42
+ const tagId = `${tagDef.scope}.${tagDef.tag}`;
43
+ if (!disabledTagIds.has(tagId)) {
44
+ enabledTagIds.add(tagId);
45
+ }
46
+ }
47
+ }
48
+ const enabledTagDefinitions = tagDefinitions.filter((tagDef) => {
49
+ const tagId = `${tagDef.scope}.${tagDef.tag}`;
50
+ return enabledTagIds.has(tagId) && tagDef.canBeGeneratedByLlm && tagDef.status === "enabled";
51
+ });
52
+ const tagDictionary = enabledTagDefinitions.map((tagDef) => ` - ${tagDef.tagTitle}: \`${tagDef.shortTagEx}\``).join("\n");
36
53
  let tagInstructionsContent = "";
37
54
  if (tagDictionary) {
38
55
  tagInstructionsContent += `- **Custom Tags Supported:**
39
56
  ${tagDictionary}
40
57
  `;
41
58
  }
42
- for (const tagDef of tagDefinitions) {
43
- if (tagDef.canBeGeneratedByLlm && tagDef.status === "enabled" && tagDef.llmInstructionsMd) {
59
+ for (const tagDef of enabledTagDefinitions) {
60
+ if (tagDef.llmInstructionsMd) {
44
61
  const tagType = `${tagDef.scope}.${tagDef.tag}`;
45
62
  tagInstructionsContent += `- **${tagDef.tagTitle}:**
46
63
  <tag-instructions type="${tagType}">
@@ -60,13 +77,6 @@ ${tagDef.llmInstructionsMd}
60
77
  if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {
61
78
  jsonOnlyImperativeInstructionLine = agentInstructionFeature.jsonOnlyImperativeInstructionLine || instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine || "BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.";
62
79
  }
63
- console.log("Generated instruction assistance content:", {
64
- hasOutputFormatting: !!outputFormattingRequirements,
65
- hasTagInstructions: !!tagInstructions,
66
- hasCompleteExample: !!completeExampleInstructionLine,
67
- hasJsonValidation: !!jsonOnlyImperativeInstructionLine,
68
- hasTypescriptBackedOutputFormattingRequirements: false
69
- });
70
80
  return {
71
81
  outputFormattingRequirements,
72
82
  tagInstructions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/instruction-assistance-utils.ts"],"names":[],"mappings":";;;AAgCO,SAAS,oCAAA,CACZ,2BAAA,EACA,IAAA,EACA,uBAAA,EACA,cAAA,EAC2B;AAC3B,EAAA,OAAA,CAAQ,IAAI,4CAAA,EAA8C;AAAA,IACtD,SAAS,uBAAA,EAAyB,OAAA;AAAA,IAClC,qCAAqC,uBAAA,EAAyB,mCAAA;AAAA,IAC9D,4BAA4B,uBAAA,EAAyB,0BAAA;AAAA,IACrD,wBAAwB,uBAAA,EAAyB,iCAAA;AAAA,IACjD,iBAAiB,uBAAA,EAAyB,oCAAA;AAAA,IAC1C,qDAAqD,uBAAA,EAAyB;AAAA,GACjF,CAAA;AAED,EAAA,IAAI,4BAAA,GAA+B,EAAA;AACnC,EAAA,IAAI,eAAA,GAAkB,EAAA;AACtB,EAAA,IAAI,8BAAA,GAAiC,EAAA;AACrC,EAAA,IAAI,iCAAA,GAAoC,EAAA;AACxC,EAAA,IAAI,4CAAA,GAA+C,EAAA;AAEnD,EAAA,IAAI,CAAC,yBAAyB,OAAA,EAAS;AACnC,IAAA,OAAO;AAAA,MACH,4BAAA;AAAA,MACA,eAAA;AAAA,MACA,8BAAA;AAAA,MACA,iCAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ;AAGA,EAAA,IAAI,wBAAwB,mCAAA,EAAqC;AAC7D,IAAA,4BAAA,GACI,6BAA6B,4BAAA,IAC7B,CAAA;AAAA;AAAA,0F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both by the front end svelte kit web client in the browser\n * and in the backend lambda converse functions. So, that means it needs to be able\n * to run in a browser. Do not add additional imports beyond anodine types.\n *\n * To be super clear: this is just logic to generate instruction assistance content given\n * the right inputs. It does not collect up those inputs, it is given them.\n *\n */\n\nimport type {\n AgentInstructionChatAppOverridableFeature,\n InstructionAssistanceConfig,\n TagDefinition,\n TagDefinitionWidget,\n TagsChatAppOverridableFeature\n} from '../types/chatbot/chatbot-types';\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate instruction assistance content based on enabled features\n *\n * @param instructionAssistanceConfig - The instruction assistance configuration from SSM\n * @param tags - The tags configuration from the chat app\n * @param agentInstructionFeature - The agent instruction feature configuration from the chat app\n * @returns The instruction assistance content\n */\nexport function generateInstructionAssistanceContent(\n instructionAssistanceConfig: InstructionAssistanceConfig | undefined,\n tags: TagsChatAppOverridableFeature | undefined,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature | undefined,\n tagDefinitions: TagDefinition<TagDefinitionWidget>[]\n): InstructionAssistanceConfig {\n console.log('Generating instruction assistance content:', {\n enabled: agentInstructionFeature?.enabled,\n includeOutputFormattingRequirements: agentInstructionFeature?.includeOutputFormattingRequirements,\n includeInstructionsForTags: agentInstructionFeature?.includeInstructionsForTags,\n completeExampleEnabled: agentInstructionFeature?.completeExampleInstructionEnabled,\n jsonOnlyEnabled: agentInstructionFeature?.jsonOnlyImperativeInstructionEnabled,\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature?.includeTypescriptBackedOutputFormattingRequirements\n });\n\n let outputFormattingRequirements = '';\n let tagInstructions = '';\n let completeExampleInstructionLine = '';\n let jsonOnlyImperativeInstructionLine = '';\n let typescriptBackedOutputFormattingRequirements = '';\n\n if (!agentInstructionFeature?.enabled) {\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n }\n\n // Generate output formatting requirements\n if (agentInstructionFeature.includeOutputFormattingRequirements) {\n outputFormattingRequirements =\n instructionAssistanceConfig?.outputFormattingRequirements ||\n `**Output Formatting Requirements:**\n- **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.\n- **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;\n }\n\n // Generate tag instructions\n if (agentInstructionFeature.includeInstructionsForTags && tags && tags.tagsEnabled?.length > 0) {\n console.log('Fetching tag definitions for instruction generation:', tags.tagsEnabled);\n\n if (tagDefinitions.length > 0) {\n // First create a dictionary listing all supported tags\n const tagDictionary = tagDefinitions\n .filter((tagDef) => tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled')\n .map((tagDef) => ` - ${tagDef.tagTitle}: \\`${tagDef.shortTagEx}\\``)\n .join('\\n');\n\n let tagInstructionsContent = '';\n if (tagDictionary) {\n tagInstructionsContent += `- **Custom Tags Supported:**\\n${tagDictionary}\\n`;\n }\n\n // Then add detailed instructions for each tag\n for (const tagDef of tagDefinitions) {\n if (tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled' && tagDef.llmInstructionsMd) {\n const tagType = `${tagDef.scope}.${tagDef.tag}`;\n tagInstructionsContent += `- **${tagDef.tagTitle}:**\\n <tag-instructions type=\"${tagType}\">\\n${tagDef.llmInstructionsMd}\\n </tag-instructions>\\n`;\n }\n }\n\n if (tagInstructionsContent) {\n tagInstructions = tagInstructionsContent;\n }\n }\n }\n\n // Generate complete example instruction line\n if (agentInstructionFeature.completeExampleInstructionEnabled) {\n completeExampleInstructionLine =\n agentInstructionFeature.completeExampleInstructionLine ||\n instructionAssistanceConfig?.completeExampleInstructionLine ||\n '- **Complete Example Output:**\\n `<answer>##Example markdown\\nNormal text and an <image>http://some.url</image> and some **bold text**\\n<chart>(...)</chart></answer>`';\n }\n\n // Generate JSON validation instruction line\n if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {\n jsonOnlyImperativeInstructionLine =\n agentInstructionFeature.jsonOnlyImperativeInstructionLine ||\n instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine ||\n 'BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.';\n }\n\n console.log('Generated instruction assistance content:', {\n hasOutputFormatting: !!outputFormattingRequirements,\n hasTagInstructions: !!tagInstructions,\n hasCompleteExample: !!completeExampleInstructionLine,\n hasJsonValidation: !!jsonOnlyImperativeInstructionLine,\n hasTypescriptBackedOutputFormattingRequirements: !!typescriptBackedOutputFormattingRequirements\n });\n\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance to the base prompt using placeholder replacement\n */\nexport function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string {\n let enhancedPrompt = basePrompt;\n\n // Check for primary placeholder first\n if (enhancedPrompt.includes('{{prompt-assistance}}')) {\n console.log('Found {{prompt-assistance}} placeholder');\n\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ]\n .filter((content) => content && content.trim().length > 0)\n .join('\\n\\n');\n\n enhancedPrompt = enhancedPrompt.replace('{{prompt-assistance}}', allContent);\n } else {\n // Look for fine-grained placeholders\n const placeholders = [\n { placeholder: '{{output-formatting-requirements}}', content: instructionContent.outputFormattingRequirements },\n { placeholder: '{{tag-instructions}}', content: instructionContent.tagInstructions },\n { placeholder: '{{complete-example-instruction-line}}', content: instructionContent.completeExampleInstructionLine },\n { placeholder: '{{json-only-imperative-instruction-line}}', content: instructionContent.jsonOnlyImperativeInstructionLine }\n ];\n\n let hasAnyPlaceholder = false;\n for (const { placeholder, content } of placeholders) {\n if (enhancedPrompt.includes(placeholder) && content) {\n console.log(`Found ${placeholder} placeholder`);\n hasAnyPlaceholder = true;\n enhancedPrompt = enhancedPrompt.replace(placeholder, content);\n }\n }\n\n // If no placeholders found, append to end\n if (!hasAnyPlaceholder) {\n console.log('No placeholders found, appending to end of prompt');\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ].filter((content) => content && content.trim().length > 0);\n\n if (allContent.length > 0) {\n enhancedPrompt = enhancedPrompt + '\\n\\n' + allContent.join('\\n\\n');\n }\n }\n }\n\n return enhancedPrompt;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate component-specific instruction content for direct component invocations\n *\n * @param tagDefinition - The tag definition with component invocation instructions\n * @param componentAgentInstructionName - The name of the instruction set to use\n * @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement\n * @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced\n * @returns The component instruction content or undefined if not found\n */\nexport function generateComponentInstructionContent(\n tagDefinition: TagDefinition<TagDefinitionWidget>,\n componentAgentInstructionName: string,\n instructionAssistanceConfig?: InstructionAssistanceConfig,\n agentInstructionFeature?: AgentInstructionChatAppOverridableFeature\n): string | undefined {\n console.log('Generating component instruction content:', {\n scope: tagDefinition.scope,\n tag: tagDefinition.tag,\n componentAgentInstructionName,\n hasDirectInvocationInstructions: !!tagDefinition.componentAgentInstructionsMd,\n hasInstructionAssistanceConfig: !!instructionAssistanceConfig\n });\n\n if (!tagDefinition.componentAgentInstructionsMd) {\n // console.log('No componentAgentInstructionsMd found on tag definition');\n return undefined;\n }\n\n const instructions = tagDefinition.componentAgentInstructionsMd[componentAgentInstructionName];\n\n if (!instructions) {\n console.log(`No instructions found for componentAgentInstructionName: ${componentAgentInstructionName}`);\n console.log('Available instruction names:', Object.keys(tagDefinition.componentAgentInstructionsMd));\n return undefined;\n }\n\n console.log('Component instructions found:', {\n instructionLength: instructions.length\n });\n\n // Apply placeholder replacement if instruction assistance config is provided\n if (instructionAssistanceConfig && agentInstructionFeature) {\n return applyComponentInstructionAssistance(instructions, instructionAssistanceConfig, agentInstructionFeature);\n }\n\n return instructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance placeholder replacement to component instructions\n *\n * @param componentInstructions - The raw component instructions with placeholders\n * @param instructionConfig - The instruction assistance configuration\n * @param agentInstructionFeature - The agent instruction feature configuration\n * @returns The component instructions with placeholders replaced\n */\nexport function applyComponentInstructionAssistance(\n componentInstructions: string,\n instructionConfig: InstructionAssistanceConfig,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature\n): string {\n let enhancedInstructions = componentInstructions;\n\n console.log('Applying component instruction assistance:', {\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements,\n hasPlaceholder: enhancedInstructions.includes('{{typescript-backed-output-formatting-requirements}}')\n });\n\n // Replace typescript-backed-output-formatting-requirements placeholder if enabled\n if (agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements && instructionConfig.typescriptBackedOutputFormattingRequirements) {\n const placeholder = '{{typescript-backed-output-formatting-requirements}}';\n if (enhancedInstructions.includes(placeholder)) {\n console.log('Replacing typescript-backed-output-formatting-requirements placeholder');\n enhancedInstructions = enhancedInstructions.replace(placeholder, instructionConfig.typescriptBackedOutputFormattingRequirements);\n }\n }\n\n return enhancedInstructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Get the instruction assistance configuration from raw SSM parameters\n *\n * @param params - The raw SSM parameters\n * @returns The instruction assistance configuration\n */\nexport function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig {\n const expectedKeys = ['output-formatting-requirements', 'default-complete-example-line', 'default-json-validation-line', 'typescript-backed-output-formatting-requirements'];\n const missingKeys = expectedKeys.filter((key) => !params[key]);\n if (missingKeys.length > 0) {\n throw new Error(\n `Missing required instruction assistance parameters: ${Object.keys(params)\n .filter((key) => !expectedKeys.includes(key))\n .join(', ')}`\n );\n }\n\n return {\n outputFormattingRequirements: params['output-formatting-requirements'],\n completeExampleInstructionLine: params['default-complete-example-line'],\n jsonOnlyImperativeInstructionLine: params['default-json-validation-line'],\n typescriptBackedOutputFormattingRequirements: params['typescript-backed-output-formatting-requirements']\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/util/instruction-assistance-utils.ts"],"names":[],"mappings":";;;AAgCO,SAAS,oCAAA,CACZ,2BAAA,EACA,IAAA,EACA,uBAAA,EACA,cAAA,EAC2B;AAC3B,EAAA,IAAI,4BAAA,GAA+B,EAAA;AACnC,EAAA,IAAI,eAAA,GAAkB,EAAA;AACtB,EAAA,IAAI,8BAAA,GAAiC,EAAA;AACrC,EAAA,IAAI,iCAAA,GAAoC,EAAA;AACxC,EAAA,IAAI,4CAAA,GAA+C,EAAA;AAEnD,EAAA,IAAI,CAAC,yBAAyB,OAAA,EAAS;AACnC,IAAA,OAAO;AAAA,MACH,4BAAA;AAAA,MACA,eAAA;AAAA,MACA,8BAAA;AAAA,MACA,iCAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ;AAGA,EAAA,IAAI,wBAAwB,mCAAA,EAAqC;AAC7D,IAAA,4BAAA,GACI,6BAA6B,4BAAA,IAC7B,CAAA;AAAA;AAAA,0FAAA,CAAA;AAAA,EAGR;AAGA,EAAA,IAAI,uBAAA,CAAwB,8BAA8B,IAAA,EAAM;AAC5D,IAAA,IAAI,cAAA,CAAe,SAAS,CAAA,EAAG;AAE3B,MAAA,MAAM,aAAA,uBAAoB,GAAA,EAAY;AAGtC,MAAA,IAAI,KAAK,WAAA,EAAa;AAClB,QAAA,KAAA,MAAW,GAAA,IAAO,KAAK,WAAA,EAAa;AAChC,UAAA,MAAM,QAAQ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AAA,KAAQ,CAAC,YAAA,CAAa,SAAS,GAAG,CAAC,CAAA,CAC3C,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACnB;AAAA,EACJ;AAEA,EAAA,OAAO;AAAA,IACH,4BAAA,EAA8B,OAAO,gCAAgC,CAAA;AAAA,IACrE,8BAAA,EAAgC,OAAO,+BAA+B,CAAA;AAAA,IACtE,iCAAA,EAAmC,OAAO,8BAA8B,CAAA;AAAA,IACxE,4CAAA,EAA8C,OAAO,kDAAkD;AAAA,GAC3G;AACJ","file":"instruction-assistance-utils.js","sourcesContent":["/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * The functions in this utility are used both by the front end svelte kit web client in the browser\n * and in the backend lambda converse functions. So, that means it needs to be able\n * to run in a browser. Do not add additional imports beyond anodine types.\n *\n * To be super clear: this is just logic to generate instruction assistance content given\n * the right inputs. It does not collect up those inputs, it is given them.\n *\n */\n\nimport type {\n AgentInstructionChatAppOverridableFeature,\n InstructionAssistanceConfig,\n TagDefinition,\n TagDefinitionWidget,\n TagsChatAppOverridableFeature\n} from '../types/chatbot/chatbot-types';\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate instruction assistance content based on enabled features\n *\n * @param instructionAssistanceConfig - The instruction assistance configuration from SSM\n * @param tags - The tags configuration from the chat app\n * @param agentInstructionFeature - The agent instruction feature configuration from the chat app\n * @returns The instruction assistance content\n */\nexport function generateInstructionAssistanceContent(\n instructionAssistanceConfig: InstructionAssistanceConfig | undefined,\n tags: TagsChatAppOverridableFeature | undefined,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature | undefined,\n tagDefinitions: TagDefinition<TagDefinitionWidget>[]\n): InstructionAssistanceConfig {\n let outputFormattingRequirements = '';\n let tagInstructions = '';\n let completeExampleInstructionLine = '';\n let jsonOnlyImperativeInstructionLine = '';\n let typescriptBackedOutputFormattingRequirements = '';\n\n if (!agentInstructionFeature?.enabled) {\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n }\n\n // Generate output formatting requirements\n if (agentInstructionFeature.includeOutputFormattingRequirements) {\n outputFormattingRequirements =\n instructionAssistanceConfig?.outputFormattingRequirements ||\n `**Output Formatting Requirements:**\n- **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.\n- **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;\n }\n\n // Generate tag instructions\n if (agentInstructionFeature.includeInstructionsForTags && tags) {\n if (tagDefinitions.length > 0) {\n // Build a set of enabled tag identifiers\n const enabledTagIds = new Set<string>();\n\n // Add all explicitly enabled chat-app tags\n if (tags.tagsEnabled) {\n for (const tag of tags.tagsEnabled) {\n const tagId = `${tag.scope}.${tag.tag}`;\n enabledTagIds.add(tagId);\n }\n }\n\n // Add all global tags that aren't explicitly disabled\n const disabledTagIds = new Set<string>();\n if (tags.tagsDisabled) {\n for (const tag of tags.tagsDisabled) {\n const tagId = `${tag.scope}.${tag.tag}`;\n disabledTagIds.add(tagId);\n }\n }\n\n for (const tagDef of tagDefinitions) {\n if (tagDef.usageMode === 'global') {\n const tagId = `${tagDef.scope}.${tagDef.tag}`;\n if (!disabledTagIds.has(tagId)) {\n enabledTagIds.add(tagId);\n }\n }\n }\n\n // Filter to only include enabled tags\n const enabledTagDefinitions = tagDefinitions.filter((tagDef) => {\n const tagId = `${tagDef.scope}.${tagDef.tag}`;\n return enabledTagIds.has(tagId) && tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled';\n });\n\n // First create a dictionary listing all supported tags\n const tagDictionary = enabledTagDefinitions.map((tagDef) => ` - ${tagDef.tagTitle}: \\`${tagDef.shortTagEx}\\``).join('\\n');\n\n let tagInstructionsContent = '';\n if (tagDictionary) {\n tagInstructionsContent += `- **Custom Tags Supported:**\\n${tagDictionary}\\n`;\n }\n\n // Then add detailed instructions for each tag\n for (const tagDef of enabledTagDefinitions) {\n if (tagDef.llmInstructionsMd) {\n const tagType = `${tagDef.scope}.${tagDef.tag}`;\n tagInstructionsContent += `- **${tagDef.tagTitle}:**\\n <tag-instructions type=\"${tagType}\">\\n${tagDef.llmInstructionsMd}\\n </tag-instructions>\\n`;\n }\n }\n\n if (tagInstructionsContent) {\n tagInstructions = tagInstructionsContent;\n }\n }\n }\n\n // Generate complete example instruction line\n if (agentInstructionFeature.completeExampleInstructionEnabled) {\n completeExampleInstructionLine =\n agentInstructionFeature.completeExampleInstructionLine ||\n instructionAssistanceConfig?.completeExampleInstructionLine ||\n '- **Complete Example Output:**\\n `<answer>##Example markdown\\nNormal text and an <image>http://some.url</image> and some **bold text**\\n<chart>(...)</chart></answer>`';\n }\n\n // Generate JSON validation instruction line\n if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {\n jsonOnlyImperativeInstructionLine =\n agentInstructionFeature.jsonOnlyImperativeInstructionLine ||\n instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine ||\n 'BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.';\n }\n\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance to the base prompt using placeholder replacement\n */\nexport function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string {\n let enhancedPrompt = basePrompt;\n\n // Check for primary placeholder first\n if (enhancedPrompt.includes('{{prompt-assistance}}')) {\n console.log('Found {{prompt-assistance}} placeholder');\n\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ]\n .filter((content) => content && content.trim().length > 0)\n .join('\\n\\n');\n\n enhancedPrompt = enhancedPrompt.replace('{{prompt-assistance}}', allContent);\n } else {\n // Look for fine-grained placeholders\n const placeholders = [\n { placeholder: '{{output-formatting-requirements}}', content: instructionContent.outputFormattingRequirements },\n { placeholder: '{{tag-instructions}}', content: instructionContent.tagInstructions },\n { placeholder: '{{complete-example-instruction-line}}', content: instructionContent.completeExampleInstructionLine },\n { placeholder: '{{json-only-imperative-instruction-line}}', content: instructionContent.jsonOnlyImperativeInstructionLine }\n ];\n\n let hasAnyPlaceholder = false;\n for (const { placeholder, content } of placeholders) {\n if (enhancedPrompt.includes(placeholder) && content) {\n console.log(`Found ${placeholder} placeholder`);\n hasAnyPlaceholder = true;\n enhancedPrompt = enhancedPrompt.replace(placeholder, content);\n }\n }\n\n // If no placeholders found, append to end\n if (!hasAnyPlaceholder) {\n console.log('No placeholders found, appending to end of prompt');\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ].filter((content) => content && content.trim().length > 0);\n\n if (allContent.length > 0) {\n enhancedPrompt = enhancedPrompt + '\\n\\n' + allContent.join('\\n\\n');\n }\n }\n }\n\n return enhancedPrompt;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate component-specific instruction content for direct component invocations\n *\n * @param tagDefinition - The tag definition with component invocation instructions\n * @param componentAgentInstructionName - The name of the instruction set to use\n * @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement\n * @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced\n * @returns The component instruction content or undefined if not found\n */\nexport function generateComponentInstructionContent(\n tagDefinition: TagDefinition<TagDefinitionWidget>,\n componentAgentInstructionName: string,\n instructionAssistanceConfig?: InstructionAssistanceConfig,\n agentInstructionFeature?: AgentInstructionChatAppOverridableFeature\n): string | undefined {\n console.log('Generating component instruction content:', {\n scope: tagDefinition.scope,\n tag: tagDefinition.tag,\n componentAgentInstructionName,\n hasDirectInvocationInstructions: !!tagDefinition.componentAgentInstructionsMd,\n hasInstructionAssistanceConfig: !!instructionAssistanceConfig\n });\n\n if (!tagDefinition.componentAgentInstructionsMd) {\n // console.log('No componentAgentInstructionsMd found on tag definition');\n return undefined;\n }\n\n const instructions = tagDefinition.componentAgentInstructionsMd[componentAgentInstructionName];\n\n if (!instructions) {\n console.log(`No instructions found for componentAgentInstructionName: ${componentAgentInstructionName}`);\n console.log('Available instruction names:', Object.keys(tagDefinition.componentAgentInstructionsMd));\n return undefined;\n }\n\n console.log('Component instructions found:', {\n instructionLength: instructions.length\n });\n\n // Apply placeholder replacement if instruction assistance config is provided\n if (instructionAssistanceConfig && agentInstructionFeature) {\n return applyComponentInstructionAssistance(instructions, instructionAssistanceConfig, agentInstructionFeature);\n }\n\n return instructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance placeholder replacement to component instructions\n *\n * @param componentInstructions - The raw component instructions with placeholders\n * @param instructionConfig - The instruction assistance configuration\n * @param agentInstructionFeature - The agent instruction feature configuration\n * @returns The component instructions with placeholders replaced\n */\nexport function applyComponentInstructionAssistance(\n componentInstructions: string,\n instructionConfig: InstructionAssistanceConfig,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature\n): string {\n let enhancedInstructions = componentInstructions;\n\n console.log('Applying component instruction assistance:', {\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements,\n hasPlaceholder: enhancedInstructions.includes('{{typescript-backed-output-formatting-requirements}}')\n });\n\n // Replace typescript-backed-output-formatting-requirements placeholder if enabled\n if (agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements && instructionConfig.typescriptBackedOutputFormattingRequirements) {\n const placeholder = '{{typescript-backed-output-formatting-requirements}}';\n if (enhancedInstructions.includes(placeholder)) {\n console.log('Replacing typescript-backed-output-formatting-requirements placeholder');\n enhancedInstructions = enhancedInstructions.replace(placeholder, instructionConfig.typescriptBackedOutputFormattingRequirements);\n }\n }\n\n return enhancedInstructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Get the instruction assistance configuration from raw SSM parameters\n *\n * @param params - The raw SSM parameters\n * @returns The instruction assistance configuration\n */\nexport function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig {\n const expectedKeys = ['output-formatting-requirements', 'default-complete-example-line', 'default-json-validation-line', 'typescript-backed-output-formatting-requirements'];\n const missingKeys = expectedKeys.filter((key) => !params[key]);\n if (missingKeys.length > 0) {\n throw new Error(\n `Missing required instruction assistance parameters: ${Object.keys(params)\n .filter((key) => !expectedKeys.includes(key))\n .join(', ')}`\n );\n }\n\n return {\n outputFormattingRequirements: params['output-formatting-requirements'],\n completeExampleInstructionLine: params['default-complete-example-line'],\n jsonOnlyImperativeInstructionLine: params['default-json-validation-line'],\n typescriptBackedOutputFormattingRequirements: params['typescript-backed-output-formatting-requirements']\n };\n}\n"]}
@@ -1,13 +1,5 @@
1
1
  // src/util/instruction-assistance-utils.ts
2
2
  function generateInstructionAssistanceContent(instructionAssistanceConfig, tags, agentInstructionFeature, tagDefinitions) {
3
- console.log("Generating instruction assistance content:", {
4
- enabled: agentInstructionFeature?.enabled,
5
- includeOutputFormattingRequirements: agentInstructionFeature?.includeOutputFormattingRequirements,
6
- includeInstructionsForTags: agentInstructionFeature?.includeInstructionsForTags,
7
- completeExampleEnabled: agentInstructionFeature?.completeExampleInstructionEnabled,
8
- jsonOnlyEnabled: agentInstructionFeature?.jsonOnlyImperativeInstructionEnabled,
9
- includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature?.includeTypescriptBackedOutputFormattingRequirements
10
- });
11
3
  let outputFormattingRequirements = "";
12
4
  let tagInstructions = "";
13
5
  let completeExampleInstructionLine = "";
@@ -27,18 +19,43 @@ function generateInstructionAssistanceContent(instructionAssistanceConfig, tags,
27
19
  - **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.
28
20
  - **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;
29
21
  }
30
- if (agentInstructionFeature.includeInstructionsForTags && tags && tags.tagsEnabled?.length > 0) {
31
- console.log("Fetching tag definitions for instruction generation:", tags.tagsEnabled);
22
+ if (agentInstructionFeature.includeInstructionsForTags && tags) {
32
23
  if (tagDefinitions.length > 0) {
33
- const tagDictionary = tagDefinitions.filter((tagDef) => tagDef.canBeGeneratedByLlm && tagDef.status === "enabled").map((tagDef) => ` - ${tagDef.tagTitle}: \`${tagDef.shortTagEx}\``).join("\n");
24
+ const enabledTagIds = /* @__PURE__ */ new Set();
25
+ if (tags.tagsEnabled) {
26
+ for (const tag of tags.tagsEnabled) {
27
+ const tagId = `${tag.scope}.${tag.tag}`;
28
+ enabledTagIds.add(tagId);
29
+ }
30
+ }
31
+ const disabledTagIds = /* @__PURE__ */ new Set();
32
+ if (tags.tagsDisabled) {
33
+ for (const tag of tags.tagsDisabled) {
34
+ const tagId = `${tag.scope}.${tag.tag}`;
35
+ disabledTagIds.add(tagId);
36
+ }
37
+ }
38
+ for (const tagDef of tagDefinitions) {
39
+ if (tagDef.usageMode === "global") {
40
+ const tagId = `${tagDef.scope}.${tagDef.tag}`;
41
+ if (!disabledTagIds.has(tagId)) {
42
+ enabledTagIds.add(tagId);
43
+ }
44
+ }
45
+ }
46
+ const enabledTagDefinitions = tagDefinitions.filter((tagDef) => {
47
+ const tagId = `${tagDef.scope}.${tagDef.tag}`;
48
+ return enabledTagIds.has(tagId) && tagDef.canBeGeneratedByLlm && tagDef.status === "enabled";
49
+ });
50
+ const tagDictionary = enabledTagDefinitions.map((tagDef) => ` - ${tagDef.tagTitle}: \`${tagDef.shortTagEx}\``).join("\n");
34
51
  let tagInstructionsContent = "";
35
52
  if (tagDictionary) {
36
53
  tagInstructionsContent += `- **Custom Tags Supported:**
37
54
  ${tagDictionary}
38
55
  `;
39
56
  }
40
- for (const tagDef of tagDefinitions) {
41
- if (tagDef.canBeGeneratedByLlm && tagDef.status === "enabled" && tagDef.llmInstructionsMd) {
57
+ for (const tagDef of enabledTagDefinitions) {
58
+ if (tagDef.llmInstructionsMd) {
42
59
  const tagType = `${tagDef.scope}.${tagDef.tag}`;
43
60
  tagInstructionsContent += `- **${tagDef.tagTitle}:**
44
61
  <tag-instructions type="${tagType}">
@@ -58,13 +75,6 @@ ${tagDef.llmInstructionsMd}
58
75
  if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {
59
76
  jsonOnlyImperativeInstructionLine = agentInstructionFeature.jsonOnlyImperativeInstructionLine || instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine || "BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.";
60
77
  }
61
- console.log("Generated instruction assistance content:", {
62
- hasOutputFormatting: !!outputFormattingRequirements,
63
- hasTagInstructions: !!tagInstructions,
64
- hasCompleteExample: !!completeExampleInstructionLine,
65
- hasJsonValidation: !!jsonOnlyImperativeInstructionLine,
66
- hasTypescriptBackedOutputFormattingRequirements: false
67
- });
68
78
  return {
69
79
  outputFormattingRequirements,
70
80
  tagInstructions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/instruction-assistance-utils.ts"],"names":[],"mappings":";AAgCO,SAAS,oCAAA,CACZ,2BAAA,EACA,IAAA,EACA,uBAAA,EACA,cAAA,EAC2B;AAC3B,EAAA,OAAA,CAAQ,IAAI,4CAAA,EAA8C;AAAA,IACtD,SAAS,uBAAA,EAAyB,OAAA;AAAA,IAClC,qCAAqC,uBAAA,EAAyB,mCAAA;AAAA,IAC9D,4BAA4B,uBAAA,EAAyB,0BAAA;AAAA,IACrD,wBAAwB,uBAAA,EAAyB,iCAAA;AAAA,IACjD,iBAAiB,uBAAA,EAAyB,oCAAA;AAAA,IAC1C,qDAAqD,uBA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A;AAAA,MACN,uDAAuD,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CACpE,OAAO,CAAC,GAAA,KAAQ,CAAC,YAAA,CAAa,SAAS,GAAG,CAAC,CAAA,CAC3C,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACnB;AAAA,EACJ;AAEA,EAAA,OAAO;AAAA,IACH,4BAAA,EAA8B,OAAO,gCAAgC,CAAA;AAAA,IACrE,8BAAA,EAAgC,OAAO,+BAA+B,CAAA;AAAA,IACtE,iCAAA,EAAmC,OAAO,8BAA8B,CAAA;AAAA,IACxE,4CAAA,EAA8C,OAAO,kDAAkD;AAAA,GAC3G;AACJ","file":"instruction-assistance-utils.mjs","sourcesContent":["/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * The functions in this utility are used both by the front end svelte kit web client in the browser\n * and in the backend lambda converse functions. So, that means it needs to be able\n * to run in a browser. Do not add additional imports beyond anodine types.\n *\n * To be super clear: this is just logic to generate instruction assistance content given\n * the right inputs. It does not collect up those inputs, it is given them.\n *\n */\n\nimport type {\n AgentInstructionChatAppOverridableFeature,\n InstructionAssistanceConfig,\n TagDefinition,\n TagDefinitionWidget,\n TagsChatAppOverridableFeature\n} from '../types/chatbot/chatbot-types';\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate instruction assistance content based on enabled features\n *\n * @param instructionAssistanceConfig - The instruction assistance configuration from SSM\n * @param tags - The tags configuration from the chat app\n * @param agentInstructionFeature - The agent instruction feature configuration from the chat app\n * @returns The instruction assistance content\n */\nexport function generateInstructionAssistanceContent(\n instructionAssistanceConfig: InstructionAssistanceConfig | undefined,\n tags: TagsChatAppOverridableFeature | undefined,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature | undefined,\n tagDefinitions: TagDefinition<TagDefinitionWidget>[]\n): InstructionAssistanceConfig {\n console.log('Generating instruction assistance content:', {\n enabled: agentInstructionFeature?.enabled,\n includeOutputFormattingRequirements: agentInstructionFeature?.includeOutputFormattingRequirements,\n includeInstructionsForTags: agentInstructionFeature?.includeInstructionsForTags,\n completeExampleEnabled: agentInstructionFeature?.completeExampleInstructionEnabled,\n jsonOnlyEnabled: agentInstructionFeature?.jsonOnlyImperativeInstructionEnabled,\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature?.includeTypescriptBackedOutputFormattingRequirements\n });\n\n let outputFormattingRequirements = '';\n let tagInstructions = '';\n let completeExampleInstructionLine = '';\n let jsonOnlyImperativeInstructionLine = '';\n let typescriptBackedOutputFormattingRequirements = '';\n\n if (!agentInstructionFeature?.enabled) {\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n }\n\n // Generate output formatting requirements\n if (agentInstructionFeature.includeOutputFormattingRequirements) {\n outputFormattingRequirements =\n instructionAssistanceConfig?.outputFormattingRequirements ||\n `**Output Formatting Requirements:**\n- **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.\n- **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;\n }\n\n // Generate tag instructions\n if (agentInstructionFeature.includeInstructionsForTags && tags && tags.tagsEnabled?.length > 0) {\n console.log('Fetching tag definitions for instruction generation:', tags.tagsEnabled);\n\n if (tagDefinitions.length > 0) {\n // First create a dictionary listing all supported tags\n const tagDictionary = tagDefinitions\n .filter((tagDef) => tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled')\n .map((tagDef) => ` - ${tagDef.tagTitle}: \\`${tagDef.shortTagEx}\\``)\n .join('\\n');\n\n let tagInstructionsContent = '';\n if (tagDictionary) {\n tagInstructionsContent += `- **Custom Tags Supported:**\\n${tagDictionary}\\n`;\n }\n\n // Then add detailed instructions for each tag\n for (const tagDef of tagDefinitions) {\n if (tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled' && tagDef.llmInstructionsMd) {\n const tagType = `${tagDef.scope}.${tagDef.tag}`;\n tagInstructionsContent += `- **${tagDef.tagTitle}:**\\n <tag-instructions type=\"${tagType}\">\\n${tagDef.llmInstructionsMd}\\n </tag-instructions>\\n`;\n }\n }\n\n if (tagInstructionsContent) {\n tagInstructions = tagInstructionsContent;\n }\n }\n }\n\n // Generate complete example instruction line\n if (agentInstructionFeature.completeExampleInstructionEnabled) {\n completeExampleInstructionLine =\n agentInstructionFeature.completeExampleInstructionLine ||\n instructionAssistanceConfig?.completeExampleInstructionLine ||\n '- **Complete Example Output:**\\n `<answer>##Example markdown\\nNormal text and an <image>http://some.url</image> and some **bold text**\\n<chart>(...)</chart></answer>`';\n }\n\n // Generate JSON validation instruction line\n if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {\n jsonOnlyImperativeInstructionLine =\n agentInstructionFeature.jsonOnlyImperativeInstructionLine ||\n instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine ||\n 'BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.';\n }\n\n console.log('Generated instruction assistance content:', {\n hasOutputFormatting: !!outputFormattingRequirements,\n hasTagInstructions: !!tagInstructions,\n hasCompleteExample: !!completeExampleInstructionLine,\n hasJsonValidation: !!jsonOnlyImperativeInstructionLine,\n hasTypescriptBackedOutputFormattingRequirements: !!typescriptBackedOutputFormattingRequirements\n });\n\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance to the base prompt using placeholder replacement\n */\nexport function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string {\n let enhancedPrompt = basePrompt;\n\n // Check for primary placeholder first\n if (enhancedPrompt.includes('{{prompt-assistance}}')) {\n console.log('Found {{prompt-assistance}} placeholder');\n\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ]\n .filter((content) => content && content.trim().length > 0)\n .join('\\n\\n');\n\n enhancedPrompt = enhancedPrompt.replace('{{prompt-assistance}}', allContent);\n } else {\n // Look for fine-grained placeholders\n const placeholders = [\n { placeholder: '{{output-formatting-requirements}}', content: instructionContent.outputFormattingRequirements },\n { placeholder: '{{tag-instructions}}', content: instructionContent.tagInstructions },\n { placeholder: '{{complete-example-instruction-line}}', content: instructionContent.completeExampleInstructionLine },\n { placeholder: '{{json-only-imperative-instruction-line}}', content: instructionContent.jsonOnlyImperativeInstructionLine }\n ];\n\n let hasAnyPlaceholder = false;\n for (const { placeholder, content } of placeholders) {\n if (enhancedPrompt.includes(placeholder) && content) {\n console.log(`Found ${placeholder} placeholder`);\n hasAnyPlaceholder = true;\n enhancedPrompt = enhancedPrompt.replace(placeholder, content);\n }\n }\n\n // If no placeholders found, append to end\n if (!hasAnyPlaceholder) {\n console.log('No placeholders found, appending to end of prompt');\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ].filter((content) => content && content.trim().length > 0);\n\n if (allContent.length > 0) {\n enhancedPrompt = enhancedPrompt + '\\n\\n' + allContent.join('\\n\\n');\n }\n }\n }\n\n return enhancedPrompt;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate component-specific instruction content for direct component invocations\n *\n * @param tagDefinition - The tag definition with component invocation instructions\n * @param componentAgentInstructionName - The name of the instruction set to use\n * @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement\n * @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced\n * @returns The component instruction content or undefined if not found\n */\nexport function generateComponentInstructionContent(\n tagDefinition: TagDefinition<TagDefinitionWidget>,\n componentAgentInstructionName: string,\n instructionAssistanceConfig?: InstructionAssistanceConfig,\n agentInstructionFeature?: AgentInstructionChatAppOverridableFeature\n): string | undefined {\n console.log('Generating component instruction content:', {\n scope: tagDefinition.scope,\n tag: tagDefinition.tag,\n componentAgentInstructionName,\n hasDirectInvocationInstructions: !!tagDefinition.componentAgentInstructionsMd,\n hasInstructionAssistanceConfig: !!instructionAssistanceConfig\n });\n\n if (!tagDefinition.componentAgentInstructionsMd) {\n // console.log('No componentAgentInstructionsMd found on tag definition');\n return undefined;\n }\n\n const instructions = tagDefinition.componentAgentInstructionsMd[componentAgentInstructionName];\n\n if (!instructions) {\n console.log(`No instructions found for componentAgentInstructionName: ${componentAgentInstructionName}`);\n console.log('Available instruction names:', Object.keys(tagDefinition.componentAgentInstructionsMd));\n return undefined;\n }\n\n console.log('Component instructions found:', {\n instructionLength: instructions.length\n });\n\n // Apply placeholder replacement if instruction assistance config is provided\n if (instructionAssistanceConfig && agentInstructionFeature) {\n return applyComponentInstructionAssistance(instructions, instructionAssistanceConfig, agentInstructionFeature);\n }\n\n return instructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance placeholder replacement to component instructions\n *\n * @param componentInstructions - The raw component instructions with placeholders\n * @param instructionConfig - The instruction assistance configuration\n * @param agentInstructionFeature - The agent instruction feature configuration\n * @returns The component instructions with placeholders replaced\n */\nexport function applyComponentInstructionAssistance(\n componentInstructions: string,\n instructionConfig: InstructionAssistanceConfig,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature\n): string {\n let enhancedInstructions = componentInstructions;\n\n console.log('Applying component instruction assistance:', {\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements,\n hasPlaceholder: enhancedInstructions.includes('{{typescript-backed-output-formatting-requirements}}')\n });\n\n // Replace typescript-backed-output-formatting-requirements placeholder if enabled\n if (agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements && instructionConfig.typescriptBackedOutputFormattingRequirements) {\n const placeholder = '{{typescript-backed-output-formatting-requirements}}';\n if (enhancedInstructions.includes(placeholder)) {\n console.log('Replacing typescript-backed-output-formatting-requirements placeholder');\n enhancedInstructions = enhancedInstructions.replace(placeholder, instructionConfig.typescriptBackedOutputFormattingRequirements);\n }\n }\n\n return enhancedInstructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Get the instruction assistance configuration from raw SSM parameters\n *\n * @param params - The raw SSM parameters\n * @returns The instruction assistance configuration\n */\nexport function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig {\n const expectedKeys = ['output-formatting-requirements', 'default-complete-example-line', 'default-json-validation-line', 'typescript-backed-output-formatting-requirements'];\n const missingKeys = expectedKeys.filter((key) => !params[key]);\n if (missingKeys.length > 0) {\n throw new Error(\n `Missing required instruction assistance parameters: ${Object.keys(params)\n .filter((key) => !expectedKeys.includes(key))\n .join(', ')}`\n );\n }\n\n return {\n outputFormattingRequirements: params['output-formatting-requirements'],\n completeExampleInstructionLine: params['default-complete-example-line'],\n jsonOnlyImperativeInstructionLine: params['default-json-validation-line'],\n typescriptBackedOutputFormattingRequirements: params['typescript-backed-output-formatting-requirements']\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/util/instruction-assistance-utils.ts"],"names":[],"mappings":";AAgCO,SAAS,oCAAA,CACZ,2BAAA,EACA,IAAA,EACA,uBAAA,EACA,cAAA,EAC2B;AAC3B,EAAA,IAAI,4BAAA,GAA+B,EAAA;AACnC,EAAA,IAAI,eAAA,GAAkB,EAAA;AACtB,EAAA,IAAI,8BAAA,GAAiC,EAAA;AACrC,EAAA,IAAI,iCAAA,GAAoC,EAAA;AACxC,EAAA,IAAI,4CAAA,GAA+C,EAAA;AAEnD,EAAA,IAAI,CAAC,yBAAyB,OAAA,EAAS;AACnC,IAAA,OAAO;AA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,oBAAA,CAAqB,OAAA,CAAQ,WAAA,EAAa,iBAAA,CAAkB,4CAA4C,CAAA;AAAA,IACnI;AAAA,EACJ;AAEA,EAAA,OAAO,oBAAA;AACX;AAYO,SAAS,gDAAgD,MAAA,EAA6D;AACzH,EAAA,MAAM,YAAA,GAAe,CAAC,gCAAA,EAAkC,+BAAA,EAAiC,gCAAgC,kDAAkD,CAAA;AAC3K,EAAA,MAAM,WAAA,GAAc,aAAa,MAAA,CAAO,CAAC,QAAQ,CAAC,MAAA,CAAO,GAAG,CAAC,CAAA;AAC7D,EAAA,IAAI,WAAA,CAAY,SAAS,CAAA,EAAG;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,uDAAuD,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CACpE,OAAO,CAAC,GAAA,KAAQ,CAAC,YAAA,CAAa,SAAS,GAAG,CAAC,CAAA,CAC3C,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACnB;AAAA,EACJ;AAEA,EAAA,OAAO;AAAA,IACH,4BAAA,EAA8B,OAAO,gCAAgC,CAAA;AAAA,IACrE,8BAAA,EAAgC,OAAO,+BAA+B,CAAA;AAAA,IACtE,iCAAA,EAAmC,OAAO,8BAA8B,CAAA;AAAA,IACxE,4CAAA,EAA8C,OAAO,kDAAkD;AAAA,GAC3G;AACJ","file":"instruction-assistance-utils.mjs","sourcesContent":["/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * The functions in this utility are used both by the front end svelte kit web client in the browser\n * and in the backend lambda converse functions. So, that means it needs to be able\n * to run in a browser. Do not add additional imports beyond anodine types.\n *\n * To be super clear: this is just logic to generate instruction assistance content given\n * the right inputs. It does not collect up those inputs, it is given them.\n *\n */\n\nimport type {\n AgentInstructionChatAppOverridableFeature,\n InstructionAssistanceConfig,\n TagDefinition,\n TagDefinitionWidget,\n TagsChatAppOverridableFeature\n} from '../types/chatbot/chatbot-types';\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate instruction assistance content based on enabled features\n *\n * @param instructionAssistanceConfig - The instruction assistance configuration from SSM\n * @param tags - The tags configuration from the chat app\n * @param agentInstructionFeature - The agent instruction feature configuration from the chat app\n * @returns The instruction assistance content\n */\nexport function generateInstructionAssistanceContent(\n instructionAssistanceConfig: InstructionAssistanceConfig | undefined,\n tags: TagsChatAppOverridableFeature | undefined,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature | undefined,\n tagDefinitions: TagDefinition<TagDefinitionWidget>[]\n): InstructionAssistanceConfig {\n let outputFormattingRequirements = '';\n let tagInstructions = '';\n let completeExampleInstructionLine = '';\n let jsonOnlyImperativeInstructionLine = '';\n let typescriptBackedOutputFormattingRequirements = '';\n\n if (!agentInstructionFeature?.enabled) {\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n }\n\n // Generate output formatting requirements\n if (agentInstructionFeature.includeOutputFormattingRequirements) {\n outputFormattingRequirements =\n instructionAssistanceConfig?.outputFormattingRequirements ||\n `**Output Formatting Requirements:**\n- **Output Response Enclosure**: All response output MUST be completely enclosed within <answer></answer> tags, including supported custom tags.\n- **Output Content Format:** All responses MUST be in Markdown with supported custom tags.`;\n }\n\n // Generate tag instructions\n if (agentInstructionFeature.includeInstructionsForTags && tags) {\n if (tagDefinitions.length > 0) {\n // Build a set of enabled tag identifiers\n const enabledTagIds = new Set<string>();\n\n // Add all explicitly enabled chat-app tags\n if (tags.tagsEnabled) {\n for (const tag of tags.tagsEnabled) {\n const tagId = `${tag.scope}.${tag.tag}`;\n enabledTagIds.add(tagId);\n }\n }\n\n // Add all global tags that aren't explicitly disabled\n const disabledTagIds = new Set<string>();\n if (tags.tagsDisabled) {\n for (const tag of tags.tagsDisabled) {\n const tagId = `${tag.scope}.${tag.tag}`;\n disabledTagIds.add(tagId);\n }\n }\n\n for (const tagDef of tagDefinitions) {\n if (tagDef.usageMode === 'global') {\n const tagId = `${tagDef.scope}.${tagDef.tag}`;\n if (!disabledTagIds.has(tagId)) {\n enabledTagIds.add(tagId);\n }\n }\n }\n\n // Filter to only include enabled tags\n const enabledTagDefinitions = tagDefinitions.filter((tagDef) => {\n const tagId = `${tagDef.scope}.${tagDef.tag}`;\n return enabledTagIds.has(tagId) && tagDef.canBeGeneratedByLlm && tagDef.status === 'enabled';\n });\n\n // First create a dictionary listing all supported tags\n const tagDictionary = enabledTagDefinitions.map((tagDef) => ` - ${tagDef.tagTitle}: \\`${tagDef.shortTagEx}\\``).join('\\n');\n\n let tagInstructionsContent = '';\n if (tagDictionary) {\n tagInstructionsContent += `- **Custom Tags Supported:**\\n${tagDictionary}\\n`;\n }\n\n // Then add detailed instructions for each tag\n for (const tagDef of enabledTagDefinitions) {\n if (tagDef.llmInstructionsMd) {\n const tagType = `${tagDef.scope}.${tagDef.tag}`;\n tagInstructionsContent += `- **${tagDef.tagTitle}:**\\n <tag-instructions type=\"${tagType}\">\\n${tagDef.llmInstructionsMd}\\n </tag-instructions>\\n`;\n }\n }\n\n if (tagInstructionsContent) {\n tagInstructions = tagInstructionsContent;\n }\n }\n }\n\n // Generate complete example instruction line\n if (agentInstructionFeature.completeExampleInstructionEnabled) {\n completeExampleInstructionLine =\n agentInstructionFeature.completeExampleInstructionLine ||\n instructionAssistanceConfig?.completeExampleInstructionLine ||\n '- **Complete Example Output:**\\n `<answer>##Example markdown\\nNormal text and an <image>http://some.url</image> and some **bold text**\\n<chart>(...)</chart></answer>`';\n }\n\n // Generate JSON validation instruction line\n if (agentInstructionFeature.jsonOnlyImperativeInstructionEnabled) {\n jsonOnlyImperativeInstructionLine =\n agentInstructionFeature.jsonOnlyImperativeInstructionLine ||\n instructionAssistanceConfig?.jsonOnlyImperativeInstructionLine ||\n 'BE ABSOLUTELY CERTAIN ANY JSON INCLUDED IS 100% VALID (especially for charts). Invalid JSON will break the user experience.';\n }\n\n return {\n outputFormattingRequirements,\n tagInstructions,\n completeExampleInstructionLine,\n jsonOnlyImperativeInstructionLine,\n typescriptBackedOutputFormattingRequirements\n };\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance to the base prompt using placeholder replacement\n */\nexport function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string {\n let enhancedPrompt = basePrompt;\n\n // Check for primary placeholder first\n if (enhancedPrompt.includes('{{prompt-assistance}}')) {\n console.log('Found {{prompt-assistance}} placeholder');\n\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ]\n .filter((content) => content && content.trim().length > 0)\n .join('\\n\\n');\n\n enhancedPrompt = enhancedPrompt.replace('{{prompt-assistance}}', allContent);\n } else {\n // Look for fine-grained placeholders\n const placeholders = [\n { placeholder: '{{output-formatting-requirements}}', content: instructionContent.outputFormattingRequirements },\n { placeholder: '{{tag-instructions}}', content: instructionContent.tagInstructions },\n { placeholder: '{{complete-example-instruction-line}}', content: instructionContent.completeExampleInstructionLine },\n { placeholder: '{{json-only-imperative-instruction-line}}', content: instructionContent.jsonOnlyImperativeInstructionLine }\n ];\n\n let hasAnyPlaceholder = false;\n for (const { placeholder, content } of placeholders) {\n if (enhancedPrompt.includes(placeholder) && content) {\n console.log(`Found ${placeholder} placeholder`);\n hasAnyPlaceholder = true;\n enhancedPrompt = enhancedPrompt.replace(placeholder, content);\n }\n }\n\n // If no placeholders found, append to end\n if (!hasAnyPlaceholder) {\n console.log('No placeholders found, appending to end of prompt');\n const allContent = [\n instructionContent.outputFormattingRequirements,\n instructionContent.tagInstructions,\n instructionContent.completeExampleInstructionLine,\n instructionContent.jsonOnlyImperativeInstructionLine\n ].filter((content) => content && content.trim().length > 0);\n\n if (allContent.length > 0) {\n enhancedPrompt = enhancedPrompt + '\\n\\n' + allContent.join('\\n\\n');\n }\n }\n }\n\n return enhancedPrompt;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Generate component-specific instruction content for direct component invocations\n *\n * @param tagDefinition - The tag definition with component invocation instructions\n * @param componentAgentInstructionName - The name of the instruction set to use\n * @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement\n * @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced\n * @returns The component instruction content or undefined if not found\n */\nexport function generateComponentInstructionContent(\n tagDefinition: TagDefinition<TagDefinitionWidget>,\n componentAgentInstructionName: string,\n instructionAssistanceConfig?: InstructionAssistanceConfig,\n agentInstructionFeature?: AgentInstructionChatAppOverridableFeature\n): string | undefined {\n console.log('Generating component instruction content:', {\n scope: tagDefinition.scope,\n tag: tagDefinition.tag,\n componentAgentInstructionName,\n hasDirectInvocationInstructions: !!tagDefinition.componentAgentInstructionsMd,\n hasInstructionAssistanceConfig: !!instructionAssistanceConfig\n });\n\n if (!tagDefinition.componentAgentInstructionsMd) {\n // console.log('No componentAgentInstructionsMd found on tag definition');\n return undefined;\n }\n\n const instructions = tagDefinition.componentAgentInstructionsMd[componentAgentInstructionName];\n\n if (!instructions) {\n console.log(`No instructions found for componentAgentInstructionName: ${componentAgentInstructionName}`);\n console.log('Available instruction names:', Object.keys(tagDefinition.componentAgentInstructionsMd));\n return undefined;\n }\n\n console.log('Component instructions found:', {\n instructionLength: instructions.length\n });\n\n // Apply placeholder replacement if instruction assistance config is provided\n if (instructionAssistanceConfig && agentInstructionFeature) {\n return applyComponentInstructionAssistance(instructions, instructionAssistanceConfig, agentInstructionFeature);\n }\n\n return instructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Apply instruction assistance placeholder replacement to component instructions\n *\n * @param componentInstructions - The raw component instructions with placeholders\n * @param instructionConfig - The instruction assistance configuration\n * @param agentInstructionFeature - The agent instruction feature configuration\n * @returns The component instructions with placeholders replaced\n */\nexport function applyComponentInstructionAssistance(\n componentInstructions: string,\n instructionConfig: InstructionAssistanceConfig,\n agentInstructionFeature: AgentInstructionChatAppOverridableFeature\n): string {\n let enhancedInstructions = componentInstructions;\n\n console.log('Applying component instruction assistance:', {\n includeTypescriptBackedOutputFormattingRequirements: agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements,\n hasPlaceholder: enhancedInstructions.includes('{{typescript-backed-output-formatting-requirements}}')\n });\n\n // Replace typescript-backed-output-formatting-requirements placeholder if enabled\n if (agentInstructionFeature.includeTypescriptBackedOutputFormattingRequirements && instructionConfig.typescriptBackedOutputFormattingRequirements) {\n const placeholder = '{{typescript-backed-output-formatting-requirements}}';\n if (enhancedInstructions.includes(placeholder)) {\n console.log('Replacing typescript-backed-output-formatting-requirements placeholder');\n enhancedInstructions = enhancedInstructions.replace(placeholder, instructionConfig.typescriptBackedOutputFormattingRequirements);\n }\n }\n\n return enhancedInstructions;\n}\n\n/**\n * IMPORTANT!!!!!!!!!!!!!!!!!!!!!!\n *\n * See header at top of file for important notes.\n *\n * Get the instruction assistance configuration from raw SSM parameters\n *\n * @param params - The raw SSM parameters\n * @returns The instruction assistance configuration\n */\nexport function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig {\n const expectedKeys = ['output-formatting-requirements', 'default-complete-example-line', 'default-json-validation-line', 'typescript-backed-output-formatting-requirements'];\n const missingKeys = expectedKeys.filter((key) => !params[key]);\n if (missingKeys.length > 0) {\n throw new Error(\n `Missing required instruction assistance parameters: ${Object.keys(params)\n .filter((key) => !expectedKeys.includes(key))\n .join(', ')}`\n );\n }\n\n return {\n outputFormattingRequirements: params['output-formatting-requirements'],\n completeExampleInstructionLine: params['default-complete-example-line'],\n jsonOnlyImperativeInstructionLine: params['default-json-validation-line'],\n typescriptBackedOutputFormattingRequirements: params['typescript-backed-output-formatting-requirements']\n };\n}\n"]}
@@ -58,7 +58,8 @@ function getOverridableFeatures(siteFeatures, chatApp, user) {
58
58
  websiteEnabled: false
59
59
  },
60
60
  tags: {
61
- tagsEnabled: []
61
+ tagsEnabled: [],
62
+ tagsDisabled: []
62
63
  },
63
64
  agentInstructionAssistance: {
64
65
  enabled: false,
@@ -157,7 +158,8 @@ function getOverridableFeatures(siteFeatures, chatApp, user) {
157
158
  result.chatDisclaimerNotice = disclaimerResult.notice;
158
159
  const effectiveTagsFeature = chatApp.override?.features?.tags || chatApp.features?.tags;
159
160
  result.tags = handleSimpleFeature("tags", effectiveTagsFeature, siteFeatures?.tags, result.tags, (feature) => ({
160
- tagsEnabled: feature.tagsEnabled ?? []
161
+ tagsEnabled: feature.tagsEnabled ?? [],
162
+ tagsDisabled: feature.tagsDisabled ?? []
161
163
  }));
162
164
  const effectiveAgentInstructionAssistanceFeature = chatApp.override?.features?.agentInstructionAssistance || chatApp.features?.agentInstructionAssistance;
163
165
  result.agentInstructionAssistance = handleSimpleFeature(