@paymanai/payman-ask-sdk 4.0.2 → 4.0.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.
package/dist/index.mjs CHANGED
@@ -131,11 +131,17 @@ var DEFAULT_SLASH_COMMANDS = [
131
131
  requiredAnyPermissions: ["vault:author", "vault:publish"]
132
132
  }
133
133
  ];
134
+ function hasCommandPermission(granted, requiredPermission) {
135
+ if (granted.has("*") || granted.has(requiredPermission)) return true;
136
+ if (!requiredPermission.includes(".")) return false;
137
+ const wildcard = requiredPermission.substring(0, requiredPermission.lastIndexOf(".")) + ".*";
138
+ return granted.has(wildcard);
139
+ }
134
140
  function filterSlashCommands(commands, permissions) {
135
141
  const granted = new Set(permissions ?? []);
136
142
  return commands.filter((command) => {
137
143
  const required = command.requiredAnyPermissions ?? [];
138
- return required.length === 0 || required.some((permission) => granted.has(permission));
144
+ return required.length === 0 || required.some((permission) => hasCommandPermission(granted, permission));
139
145
  });
140
146
  }
141
147
  function parseSlashCommand(content) {
@@ -148,9 +154,19 @@ function parseSlashCommand(content) {
148
154
  body: match[2] ?? ""
149
155
  };
150
156
  }
151
- function slashCommandBodyIsEmpty(content) {
157
+ function getSlashCommandValidationHint(content) {
152
158
  const parsed = parseSlashCommand(content);
153
- return parsed?.command === "/draft-knowledge" && parsed.body.trim().length === 0;
159
+ if (parsed?.command !== "/draft-knowledge") return null;
160
+ const lines = parsed.body.split(/\r?\n/);
161
+ const title = lines[0]?.trim() ?? "";
162
+ const markdownContent = lines.slice(1).join("\n").trim();
163
+ if (!title) {
164
+ return "Add a title after /draft-knowledge, then add markdown content on the next line.";
165
+ }
166
+ if (!markdownContent) {
167
+ return "Add markdown content on a new line below the title.";
168
+ }
169
+ return null;
154
170
  }
155
171
 
156
172
  // src/utils/errorMessages.ts
@@ -2622,8 +2638,9 @@ var ChatInputV2 = forwardRef(
2622
2638
  }, [isRecording, transcribedText]);
2623
2639
  const handleSend = useCallback(() => {
2624
2640
  if (!value.trim() || disabled) return;
2625
- if (slashCommandBodyIsEmpty(value)) {
2626
- setInlineHint("Add markdown content below the command line.");
2641
+ const commandHint = getSlashCommandValidationHint(value);
2642
+ if (commandHint) {
2643
+ setInlineHint(commandHint);
2627
2644
  return;
2628
2645
  }
2629
2646
  voiceDraftSyncActiveRef.current = false;