@apotech-os/support-kit 6.0.0 → 6.1.0

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/dist/index.cjs CHANGED
@@ -157,14 +157,18 @@ function isStopMessage(message) {
157
157
  const cleaned = normalise(message).replace(/^[^\p{L}\d]+|[^\p{L}\d]+$/gu, "").replace(/\s+/g, " ");
158
158
  return STOP_PHRASES.has(cleaned);
159
159
  }
160
+ var ATTACHMENT_MARKER_ONLY = /^\[Pièces? jointes? : \d+ fichiers?\]$/;
161
+ function isCustomerTurnWithWords(message) {
162
+ return message.role === "user" && !ATTACHMENT_MARKER_ONLY.test(message.content.trim());
163
+ }
160
164
  function firstCustomerMessage(conversation) {
161
- return conversation.messages.find((m) => m.role === "user")?.content ?? null;
165
+ return conversation.messages.find(isCustomerTurnWithWords)?.content ?? null;
162
166
  }
163
167
  function lastCustomerMessage(conversation) {
164
168
  const { messages } = conversation;
165
169
  for (let i = messages.length - 1; i >= 0; i--) {
166
170
  const message = messages[i];
167
- if (message?.role === "user") return message.content;
171
+ if (message && isCustomerTurnWithWords(message)) return message.content;
168
172
  }
169
173
  return null;
170
174
  }
@@ -4828,9 +4832,22 @@ async function createAgentHandler(ctx, input) {
4828
4832
  return toAgent(await ctx.api.create("agent", { ...base, promptName }));
4829
4833
  }
4830
4834
  const created = await ctx.api.create("agent", { ...base, promptName: PENDING_PROMPT_NAME });
4831
- const withPromptName = await ctx.api.update("agent", created.id, { promptName: `agent/${created.id}` });
4835
+ const derivedName = `agent/${created.id}`;
4836
+ const withPromptName = await ctx.api.update("agent", created.id, { promptName: derivedName });
4837
+ await seedInitialVersion(ctx, derivedName, input.systemPromptSnapshot?.trim() ?? "");
4832
4838
  return toAgent(withPromptName);
4833
4839
  }
4840
+ async function seedInitialVersion(ctx, promptName, content) {
4841
+ if (!content) return;
4842
+ try {
4843
+ const { version } = await ctx.api.prompts.createVersion(promptName, { content });
4844
+ await ctx.api.prompts.promote(promptName, version, "production");
4845
+ } catch (err) {
4846
+ ctx.logger.warn(
4847
+ `create-agent: could not seed "${promptName}" with its initial version \u2014 the text is kept as the agent's fallback (${err instanceof Error ? err.message : String(err)})`
4848
+ );
4849
+ }
4850
+ }
4834
4851
  var DEFAULT_KEY_VALUE = "default";
4835
4852
  function buildSetDefaultAgentFunctionDef(config) {
4836
4853
  return {
@@ -5933,6 +5950,7 @@ function buildSupportPipeline(config) {
5933
5950
  exports.AGENT_GUARDRAILS = AGENT_GUARDRAILS;
5934
5951
  exports.AGENT_STATUSES = AGENT_STATUSES;
5935
5952
  exports.AGENT_TOOLS = AGENT_TOOLS;
5953
+ exports.ATTACHMENT_MARKER_ONLY = ATTACHMENT_MARKER_ONLY;
5936
5954
  exports.CANDIDATE_MIN_LENGTH = CANDIDATE_MIN_LENGTH;
5937
5955
  exports.DEFAULT_CHANNEL_PROMPT_EMAIL = DEFAULT_CHANNEL_PROMPT_EMAIL;
5938
5956
  exports.DEFAULT_CHANNEL_PROMPT_WHATSAPP = DEFAULT_CHANNEL_PROMPT_WHATSAPP;