@sesamespace/sesame 0.2.4 → 0.2.5
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.js +23 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,18 @@
|
|
|
12
12
|
* That's it. The plugin handles WebSocket connection, authentication,
|
|
13
13
|
* heartbeats, reconnection, and message routing automatically.
|
|
14
14
|
*/
|
|
15
|
+
// Plugin version (injected from package.json at build time, fallback to static)
|
|
16
|
+
const PLUGIN_VERSION = "0.2.5";
|
|
17
|
+
/** Standard headers for Sesame API calls */
|
|
18
|
+
function sesameHeaders(apiKey, json = true) {
|
|
19
|
+
const h = {
|
|
20
|
+
Authorization: `Bearer ${apiKey}`,
|
|
21
|
+
"X-Sesame-Plugin-Version": PLUGIN_VERSION,
|
|
22
|
+
};
|
|
23
|
+
if (json)
|
|
24
|
+
h["Content-Type"] = "application/json";
|
|
25
|
+
return h;
|
|
26
|
+
}
|
|
15
27
|
// Runtime state
|
|
16
28
|
let pluginRuntime = null;
|
|
17
29
|
// Connection state per account
|
|
@@ -94,7 +106,7 @@ const sesameChannelPlugin = {
|
|
|
94
106
|
probeAccount: async ({ account, timeoutMs }) => {
|
|
95
107
|
try {
|
|
96
108
|
const response = await fetch(`${account.apiUrl}/api/v1/agents/me/manifest`, {
|
|
97
|
-
headers:
|
|
109
|
+
headers: sesameHeaders(account.apiKey, false),
|
|
98
110
|
signal: AbortSignal.timeout(timeoutMs ?? 5000),
|
|
99
111
|
});
|
|
100
112
|
if (response.ok) {
|
|
@@ -158,10 +170,7 @@ const sesameChannelPlugin = {
|
|
|
158
170
|
log.info?.(`[sesame] outbound.sendText: streaming already sent to ${channelId}, doing final edit`);
|
|
159
171
|
const editRes = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}/messages/${delivered.messageId}`, {
|
|
160
172
|
method: "PATCH",
|
|
161
|
-
headers:
|
|
162
|
-
"Content-Type": "application/json",
|
|
163
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
164
|
-
},
|
|
173
|
+
headers: sesameHeaders(account.apiKey),
|
|
165
174
|
body: JSON.stringify({ content: text }),
|
|
166
175
|
});
|
|
167
176
|
if (!editRes.ok) {
|
|
@@ -175,10 +184,7 @@ const sesameChannelPlugin = {
|
|
|
175
184
|
}
|
|
176
185
|
const response = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}/messages`, {
|
|
177
186
|
method: "POST",
|
|
178
|
-
headers:
|
|
179
|
-
"Content-Type": "application/json",
|
|
180
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
181
|
-
},
|
|
187
|
+
headers: sesameHeaders(account.apiKey),
|
|
182
188
|
body: JSON.stringify({ content: text, kind: "text", intent: "chat" }),
|
|
183
189
|
});
|
|
184
190
|
if (!response.ok) {
|
|
@@ -234,10 +240,7 @@ const sesameChannelPlugin = {
|
|
|
234
240
|
// 1. Get presigned upload URL from Sesame Drive
|
|
235
241
|
const uploadRes = await fetch(`${account.apiUrl}/api/v1/drive/files/upload-url`, {
|
|
236
242
|
method: "POST",
|
|
237
|
-
headers:
|
|
238
|
-
"Content-Type": "application/json",
|
|
239
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
240
|
-
},
|
|
243
|
+
headers: sesameHeaders(account.apiKey),
|
|
241
244
|
body: JSON.stringify({ fileName, contentType, size: fileBuffer.length }),
|
|
242
245
|
});
|
|
243
246
|
if (!uploadRes.ok)
|
|
@@ -255,10 +258,7 @@ const sesameChannelPlugin = {
|
|
|
255
258
|
// 3. Register file in Drive
|
|
256
259
|
const regRes = await fetch(`${account.apiUrl}/api/v1/drive/files`, {
|
|
257
260
|
method: "POST",
|
|
258
|
-
headers:
|
|
259
|
-
"Content-Type": "application/json",
|
|
260
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
261
|
-
},
|
|
261
|
+
headers: sesameHeaders(account.apiKey),
|
|
262
262
|
body: JSON.stringify({ fileId, s3Key, fileName, contentType, size: fileBuffer.length }),
|
|
263
263
|
});
|
|
264
264
|
if (!regRes.ok)
|
|
@@ -266,10 +266,7 @@ const sesameChannelPlugin = {
|
|
|
266
266
|
// 4. Send message with attachment
|
|
267
267
|
const msgRes = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}/messages`, {
|
|
268
268
|
method: "POST",
|
|
269
|
-
headers:
|
|
270
|
-
"Content-Type": "application/json",
|
|
271
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
272
|
-
},
|
|
269
|
+
headers: sesameHeaders(account.apiKey),
|
|
273
270
|
body: JSON.stringify({
|
|
274
271
|
content: caption || fileName,
|
|
275
272
|
kind: "text",
|
|
@@ -335,7 +332,7 @@ const sesameChannelPlugin = {
|
|
|
335
332
|
async function fetchWakeContext(account, agentId, ctx) {
|
|
336
333
|
const log = getLogger();
|
|
337
334
|
try {
|
|
338
|
-
const response = await fetch(`${account.apiUrl}/api/v1/agents/${agentId}/wake`, { headers:
|
|
335
|
+
const response = await fetch(`${account.apiUrl}/api/v1/agents/${agentId}/wake`, { headers: sesameHeaders(account.apiKey, false) });
|
|
339
336
|
if (!response.ok) {
|
|
340
337
|
log.warn?.(`[sesame] Wake endpoint returned ${response.status}`);
|
|
341
338
|
return;
|
|
@@ -437,7 +434,7 @@ async function connect(account, ctx) {
|
|
|
437
434
|
try {
|
|
438
435
|
// Fetch manifest: resolve agent ID + cache channel metadata
|
|
439
436
|
try {
|
|
440
|
-
const res = await fetch(`${account.apiUrl}/api/v1/agents/me/manifest`, { headers:
|
|
437
|
+
const res = await fetch(`${account.apiUrl}/api/v1/agents/me/manifest`, { headers: sesameHeaders(account.apiKey, false) });
|
|
441
438
|
if (res.ok) {
|
|
442
439
|
const manifest = (await res.json());
|
|
443
440
|
const mData = manifest.data ?? manifest;
|
|
@@ -670,7 +667,7 @@ async function handleMessage(message, account, state, ctx) {
|
|
|
670
667
|
if (!channelInfo) {
|
|
671
668
|
// Channel not in cache — fetch from API
|
|
672
669
|
try {
|
|
673
|
-
const chRes = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}`, { headers:
|
|
670
|
+
const chRes = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}`, { headers: sesameHeaders(account.apiKey, false) });
|
|
674
671
|
if (chRes.ok) {
|
|
675
672
|
const chData = (await chRes.json());
|
|
676
673
|
const ch = chData.data ?? chData;
|
|
@@ -784,10 +781,7 @@ async function handleMessage(message, account, state, ctx) {
|
|
|
784
781
|
}
|
|
785
782
|
const res = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}/messages`, {
|
|
786
783
|
method: "POST",
|
|
787
|
-
headers:
|
|
788
|
-
"Content-Type": "application/json",
|
|
789
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
790
|
-
},
|
|
784
|
+
headers: sesameHeaders(account.apiKey),
|
|
791
785
|
body: JSON.stringify({ content: text, kind: "text", intent: "chat" }),
|
|
792
786
|
});
|
|
793
787
|
if (!res.ok) {
|
|
@@ -805,10 +799,7 @@ async function handleMessage(message, account, state, ctx) {
|
|
|
805
799
|
const editMessage = async (msgId, text) => {
|
|
806
800
|
const res = await fetch(`${account.apiUrl}/api/v1/channels/${channelId}/messages/${msgId}`, {
|
|
807
801
|
method: "PATCH",
|
|
808
|
-
headers:
|
|
809
|
-
"Content-Type": "application/json",
|
|
810
|
-
Authorization: `Bearer ${account.apiKey}`,
|
|
811
|
-
},
|
|
802
|
+
headers: sesameHeaders(account.apiKey),
|
|
812
803
|
body: JSON.stringify({ content: text }),
|
|
813
804
|
});
|
|
814
805
|
if (!res.ok) {
|