chat 4.27.0 → 4.29.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.
Files changed (49) hide show
  1. package/dist/ai/index.d.ts +501 -0
  2. package/dist/ai/index.js +500 -0
  3. package/dist/chat-D9UYaaNO.d.ts +3156 -0
  4. package/dist/chunk-HD375J7S.js +128 -0
  5. package/dist/{chunk-AN7MRAVW.js → chunk-V25FKIIL.js} +5 -1
  6. package/dist/index.d.ts +35 -2934
  7. package/dist/index.js +567 -210
  8. package/dist/{jsx-runtime-Co9uV6l7.d.ts → jsx-runtime-CFq1K_Ve.d.ts} +11 -1
  9. package/dist/jsx-runtime.d.ts +1 -1
  10. package/dist/jsx-runtime.js +1 -1
  11. package/docs/actions.mdx +52 -1
  12. package/docs/adapters.mdx +72 -36
  13. package/docs/ai/ai-sdk-tools.mdx +227 -0
  14. package/docs/ai/index.mdx +63 -0
  15. package/docs/ai/meta.json +4 -0
  16. package/docs/{api → ai}/to-ai-messages.mdx +16 -3
  17. package/docs/ai/types.mdx +243 -0
  18. package/docs/api/cards.mdx +4 -0
  19. package/docs/api/chat.mdx +132 -10
  20. package/docs/api/index.mdx +6 -6
  21. package/docs/api/markdown.mdx +28 -5
  22. package/docs/api/message.mdx +54 -1
  23. package/docs/api/meta.json +1 -0
  24. package/docs/api/modals.mdx +50 -0
  25. package/docs/api/postable-message.mdx +58 -4
  26. package/docs/api/thread.mdx +11 -3
  27. package/docs/api/transcripts.mdx +220 -0
  28. package/docs/cards.mdx +6 -0
  29. package/docs/concurrency.mdx +58 -15
  30. package/docs/contributing/building.mdx +74 -2
  31. package/docs/contributing/testing.mdx +4 -0
  32. package/docs/conversation-history.mdx +137 -0
  33. package/docs/direct-messages.mdx +23 -5
  34. package/docs/ephemeral-messages.mdx +1 -1
  35. package/docs/error-handling.mdx +15 -3
  36. package/docs/files.mdx +21 -1
  37. package/docs/handling-events.mdx +10 -7
  38. package/docs/index.mdx +8 -5
  39. package/docs/meta.json +17 -3
  40. package/docs/modals.mdx +24 -0
  41. package/docs/posting-messages.mdx +10 -4
  42. package/docs/slash-commands.mdx +4 -4
  43. package/docs/streaming.mdx +75 -27
  44. package/docs/subject.mdx +53 -0
  45. package/docs/testing.mdx +142 -0
  46. package/docs/threads-messages-channels.mdx +10 -1
  47. package/docs/usage.mdx +15 -2
  48. package/package.json +23 -2
  49. package/resources/guides/how-to-build-an-ai-agent-for-slack-with-chat-sdk-and-ai-sdk.md +1 -1
@@ -0,0 +1,128 @@
1
+ // src/ai/messages.ts
2
+ var TEXT_MIME_PREFIXES = [
3
+ "text/",
4
+ "application/json",
5
+ "application/xml",
6
+ "application/javascript",
7
+ "application/typescript",
8
+ "application/yaml",
9
+ "application/x-yaml",
10
+ "application/toml"
11
+ ];
12
+ function isTextMimeType(mimeType) {
13
+ return TEXT_MIME_PREFIXES.some(
14
+ (prefix) => mimeType === prefix || mimeType.startsWith(prefix)
15
+ );
16
+ }
17
+ async function attachmentToPart(att) {
18
+ if (att.type === "image") {
19
+ if (att.fetchData) {
20
+ try {
21
+ const buffer = await att.fetchData();
22
+ const mimeType = att.mimeType ?? "image/png";
23
+ return {
24
+ type: "file",
25
+ data: `data:${mimeType};base64,${buffer.toString("base64")}`,
26
+ mediaType: mimeType,
27
+ filename: att.name
28
+ };
29
+ } catch (error) {
30
+ console.error("toAiMessages: failed to fetch image data", error);
31
+ return null;
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+ if (att.type === "file" && att.mimeType && isTextMimeType(att.mimeType)) {
37
+ if (att.fetchData) {
38
+ try {
39
+ const buffer = await att.fetchData();
40
+ return {
41
+ type: "file",
42
+ data: `data:${att.mimeType};base64,${buffer.toString("base64")}`,
43
+ filename: att.name,
44
+ mediaType: att.mimeType
45
+ };
46
+ } catch (error) {
47
+ console.error("toAiMessages: failed to fetch file data", error);
48
+ return null;
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ return null;
54
+ }
55
+ async function toAiMessages(messages, options) {
56
+ const includeNames = options?.includeNames ?? false;
57
+ const transformMessage = options?.transformMessage;
58
+ const onUnsupported = options?.onUnsupportedAttachment ?? ((att) => {
59
+ console.warn(
60
+ `toAiMessages: unsupported attachment type "${att.type}"${att.name ? ` (${att.name})` : ""} \u2014 skipped`
61
+ );
62
+ });
63
+ const sorted = [...messages].sort(
64
+ (a, b) => (a.metadata.dateSent?.getTime() ?? 0) - (b.metadata.dateSent?.getTime() ?? 0)
65
+ );
66
+ const filtered = sorted.filter((msg) => msg.text.trim());
67
+ const results = await Promise.all(
68
+ filtered.map(async (msg) => {
69
+ const role = msg.author.isMe ? "assistant" : "user";
70
+ let textContent = includeNames && role === "user" ? `[${msg.author.userName}]: ${msg.text}` : msg.text;
71
+ if (msg.links && msg.links.length > 0) {
72
+ const linkParts = msg.links.map((link) => {
73
+ const parts = link.fetchMessage ? [`[Embedded message: ${link.url}]`] : [link.url];
74
+ if (link.title) {
75
+ parts.push(`Title: ${link.title}`);
76
+ }
77
+ if (link.description) {
78
+ parts.push(`Description: ${link.description}`);
79
+ }
80
+ if (link.siteName) {
81
+ parts.push(`Site: ${link.siteName}`);
82
+ }
83
+ return parts.join("\n");
84
+ }).join("\n\n");
85
+ textContent += `
86
+
87
+ Links:
88
+ ${linkParts}`;
89
+ }
90
+ let aiMessage;
91
+ if (role === "user") {
92
+ const attachmentParts = [];
93
+ for (const att of msg.attachments ?? []) {
94
+ const part = await attachmentToPart(att);
95
+ if (part) {
96
+ attachmentParts.push(part);
97
+ } else if (att.type === "video" || att.type === "audio") {
98
+ onUnsupported(att, msg);
99
+ }
100
+ }
101
+ if (attachmentParts.length > 0) {
102
+ aiMessage = {
103
+ role,
104
+ content: [
105
+ { type: "text", text: textContent },
106
+ ...attachmentParts
107
+ ]
108
+ };
109
+ } else {
110
+ aiMessage = { role, content: textContent };
111
+ }
112
+ } else {
113
+ aiMessage = { role, content: textContent };
114
+ }
115
+ if (transformMessage) {
116
+ return { result: await transformMessage(aiMessage, msg), source: msg };
117
+ }
118
+ return { result: aiMessage, source: msg };
119
+ })
120
+ );
121
+ return results.filter(
122
+ (r) => r.result != null
123
+ ).map((r) => r.result);
124
+ }
125
+
126
+ export {
127
+ toAiMessages
128
+ };
@@ -354,7 +354,8 @@ function Button(options) {
354
354
  style: options.style,
355
355
  value: options.value,
356
356
  disabled: options.disabled,
357
- actionType: options.actionType
357
+ actionType: options.actionType,
358
+ callbackUrl: options.callbackUrl
358
359
  };
359
360
  }
360
361
  function LinkButton(options) {
@@ -607,6 +608,7 @@ function Modal(options) {
607
608
  return {
608
609
  type: "modal",
609
610
  callbackId: options.callbackId,
611
+ callbackUrl: options.callbackUrl,
610
612
  title: options.title,
611
613
  submitLabel: options.submitLabel,
612
614
  closeLabel: options.closeLabel,
@@ -881,6 +883,7 @@ function resolveJSXElement(element) {
881
883
  style: props.style,
882
884
  value: props.value,
883
885
  actionType: props.actionType,
886
+ callbackUrl: props.callbackUrl,
884
887
  disabled: props.disabled
885
888
  });
886
889
  }
@@ -929,6 +932,7 @@ function resolveJSXElement(element) {
929
932
  }
930
933
  return Modal({
931
934
  callbackId: props.callbackId,
935
+ callbackUrl: props.callbackUrl,
932
936
  title: props.title,
933
937
  submitLabel: props.submitLabel,
934
938
  closeLabel: props.closeLabel,