@clawchatsai/connector 0.1.32 → 0.1.33
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/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// ClawChats server is involved. Spec: clawchats repo, specs/sharing-and-artifacts.md.
|
|
6
6
|
//
|
|
7
7
|
// <dataDir>/share-storage.json derived S3 credentials + public URL (0600; never sent to the browser)
|
|
8
|
-
// <dataDir>/shares.json [{id, url, title, type, mode, createdAt, expiresAt}] (no keys)
|
|
8
|
+
// <dataDir>/shares.json [{id, url, title, type, mode, createdAt, expiresAt, source?}] (no keys)
|
|
9
9
|
import crypto from 'node:crypto';
|
|
10
10
|
import fs from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
@@ -21,6 +21,16 @@ const TYPES = new Set(['html', 'svg', 'markdown', 'mermaid', 'csv', 'code', 'cha
|
|
|
21
21
|
const SWEEP_MS = 60 * 60 * 1000;
|
|
22
22
|
const objectKey = id => `shares/${id}.html`;
|
|
23
23
|
|
|
24
|
+
// Where a share came from, so ClawChats can list a chat's or a file's links next to it:
|
|
25
|
+
// {kind: 'chat'|'artifact'|'file', chatId?, name?, path?}. Unknown kinds and fields are dropped.
|
|
26
|
+
const SOURCE_KINDS = new Set(['chat', 'artifact', 'file']);
|
|
27
|
+
export function cleanSource(src) {
|
|
28
|
+
if (!src || typeof src !== 'object' || !SOURCE_KINDS.has(src.kind)) return undefined;
|
|
29
|
+
const out = { kind: src.kind };
|
|
30
|
+
for (const k of ['chatId', 'name', 'path']) if (typeof src[k] === 'string' && src[k]) out[k] = src[k].slice(0, 500);
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export function validEnvelope(e) {
|
|
25
35
|
const b64u = s => typeof s === 'string' && /^[A-Za-z0-9_-]+$/.test(s);
|
|
26
36
|
if (!e || typeof e !== 'object' || e.v !== 1 || e.alg !== 'A256GCM' || !b64u(e.iv) || !b64u(e.ct)) return false;
|
|
@@ -94,11 +104,11 @@ export function createShareHandlers({ dataDir, fetchImpl = globalThis.fetch, set
|
|
|
94
104
|
return send(res, 200, { ok: true });
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
// POST /api/extras/shares {envelope, expiresAt?, title, type} → {share}
|
|
107
|
+
// POST /api/extras/shares {envelope, expiresAt?, title, type, source?} → {share}
|
|
98
108
|
async function handleCreate(req, res) {
|
|
99
109
|
const cfg = readStorage();
|
|
100
110
|
if (!cfg) return sendError(res, 409, 'Connect your Cloudflare storage first');
|
|
101
|
-
const { envelope, expiresAt, title, type } = await parseBody(req);
|
|
111
|
+
const { envelope, expiresAt, title, type, source } = await parseBody(req);
|
|
102
112
|
if (!validEnvelope(envelope)) return sendError(res, 400, 'Missing or malformed encrypted envelope');
|
|
103
113
|
if (!TYPES.has(type)) return sendError(res, 400, 'Unsupported artifact type');
|
|
104
114
|
let expires = null;
|
|
@@ -122,6 +132,7 @@ export function createShareHandlers({ dataDir, fetchImpl = globalThis.fetch, set
|
|
|
122
132
|
mode: envelope.kdf ? 'password' : 'link',
|
|
123
133
|
createdAt: new Date().toISOString(),
|
|
124
134
|
expiresAt: expires,
|
|
135
|
+
...(cleanSource(source) ? { source: cleanSource(source) } : {}),
|
|
125
136
|
};
|
|
126
137
|
writePrivate(indexFile, [share, ...readIndex()]);
|
|
127
138
|
sweep().catch(() => {});
|
|
@@ -4,7 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { Readable } from 'node:stream';
|
|
7
|
-
import { createShareHandlers, validEnvelope } from './shares.js';
|
|
7
|
+
import { createShareHandlers, validEnvelope, cleanSource } from './shares.js';
|
|
8
8
|
import { buildSharePage } from '../share/viewer-page.js';
|
|
9
9
|
import { decryptShare, needsPassword } from '../share/viewer-decrypt.js';
|
|
10
10
|
|
|
@@ -151,3 +151,14 @@ test('whole-chat shares are accepted and uploaded like artifacts', async () => {
|
|
|
151
151
|
assert.equal(r.body.share.type, 'chat');
|
|
152
152
|
assert.ok(ops[0].body.includes('function chatPage'), 'the share page can render chats');
|
|
153
153
|
});
|
|
154
|
+
|
|
155
|
+
test('create records where the share came from, keeping only known fields', async () => {
|
|
156
|
+
const { h } = setup();
|
|
157
|
+
const r = await call(h.handleCreate, { envelope: ENV, title: 'A chat', type: 'chat', source: { kind: 'chat', chatId: 'agent:main:x', extra: 'dropped' } });
|
|
158
|
+
assert.deepEqual(r.body.share.source, { kind: 'chat', chatId: 'agent:main:x' });
|
|
159
|
+
assert.deepEqual((await call(h.handleList)).body.shares[0].source, { kind: 'chat', chatId: 'agent:main:x' });
|
|
160
|
+
const plain = await call(h.handleCreate, { envelope: ENV, type: 'html', source: { kind: 'nope' } });
|
|
161
|
+
assert.equal('source' in plain.body.share, false);
|
|
162
|
+
assert.equal(cleanSource({ kind: 'file', path: 'a'.repeat(900), name: 5 }).path.length, 500);
|
|
163
|
+
assert.equal(cleanSource({ kind: 'file', name: 5 }).name, undefined);
|
|
164
|
+
});
|