@relayfile/sdk 0.10.12 → 0.10.13
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RelayFileClient } from "./client.js";
|
|
2
2
|
import type { ConnectionProvider } from "./connection.js";
|
|
3
3
|
import type { FileSemantics } from "./types.js";
|
|
4
|
+
import type { WriteEvent } from "@relayfile/core";
|
|
4
5
|
export interface AdapterWebhookMetadata {
|
|
5
6
|
deliveryId?: string;
|
|
6
7
|
delivery_id?: string;
|
|
@@ -48,6 +49,15 @@ export interface SyncResult {
|
|
|
48
49
|
error: string;
|
|
49
50
|
}>;
|
|
50
51
|
}
|
|
52
|
+
export interface RelayBindingView {
|
|
53
|
+
text: string;
|
|
54
|
+
author?: string;
|
|
55
|
+
skip?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface RelayBinding {
|
|
58
|
+
present?(event: WriteEvent): RelayBindingView | null;
|
|
59
|
+
replyPathFor?(sourcePath: string): string | null;
|
|
60
|
+
}
|
|
51
61
|
export declare abstract class IntegrationAdapter {
|
|
52
62
|
protected readonly client: RelayFileClient;
|
|
53
63
|
protected readonly provider: ConnectionProvider;
|
|
@@ -59,5 +69,8 @@ export declare abstract class IntegrationAdapter {
|
|
|
59
69
|
abstract computeSemantics(objectType: string, objectId: string, payload: Record<string, unknown>): FileSemantics;
|
|
60
70
|
supportedEvents?(): string[];
|
|
61
71
|
writeBack?(workspaceId: string, path: string, content: string): Promise<unknown>;
|
|
72
|
+
relayBinding?: RelayBinding;
|
|
62
73
|
sync?(workspaceId: string, options?: SyncOptions): Promise<SyncResult>;
|
|
63
74
|
}
|
|
75
|
+
export declare function genericPresent(event: WriteEvent, adapter: IntegrationAdapter): RelayBindingView;
|
|
76
|
+
export declare function genericReplyPathFor(sourcePath: string): string | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const DEFAULT_PRESENT_TEXT_LIMIT = 500;
|
|
1
2
|
export class IntegrationAdapter {
|
|
2
3
|
client;
|
|
3
4
|
provider;
|
|
@@ -5,4 +6,80 @@ export class IntegrationAdapter {
|
|
|
5
6
|
this.client = client;
|
|
6
7
|
this.provider = provider;
|
|
7
8
|
}
|
|
9
|
+
relayBinding;
|
|
10
|
+
}
|
|
11
|
+
export function genericPresent(event, adapter) {
|
|
12
|
+
const provider = providerFromPath(event.path) || adapter.name;
|
|
13
|
+
const { objectType, objectId } = objectIdentityFromPath(event.path);
|
|
14
|
+
const payload = isRecord(event.value) ? event.value : {};
|
|
15
|
+
let semantics = {};
|
|
16
|
+
try {
|
|
17
|
+
semantics = adapter.computeSemantics(objectType, objectId, payload) ?? {};
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
semantics = {};
|
|
21
|
+
}
|
|
22
|
+
const summary = summarizeForRelayBinding(event, semantics, payload);
|
|
23
|
+
return {
|
|
24
|
+
text: truncateText(summary, DEFAULT_PRESENT_TEXT_LIMIT),
|
|
25
|
+
author: event.actor?.id || provider
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function genericReplyPathFor(sourcePath) {
|
|
29
|
+
const normalized = sourcePath.trim().replace(/\/+$/, "");
|
|
30
|
+
if (!normalized || !normalized.startsWith("/")) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return `${normalized}/replies/draft.json`;
|
|
34
|
+
}
|
|
35
|
+
function summarizeForRelayBinding(event, semantics, payload) {
|
|
36
|
+
const semanticLines = [
|
|
37
|
+
firstNonEmpty("status", semantics.properties?.["provider.status"], semantics.properties?.status),
|
|
38
|
+
firstNonEmpty("updated", semantics.properties?.["provider.updated_at"], semantics.properties?.updatedAt),
|
|
39
|
+
firstNonEmpty("title", semantics.properties?.title, semantics.properties?.name, semantics.properties?.subject)
|
|
40
|
+
].filter((line) => line !== undefined);
|
|
41
|
+
const relationCount = semantics.relations?.length ?? 0;
|
|
42
|
+
const commentCount = semantics.comments?.length ?? 0;
|
|
43
|
+
const permissionCount = semantics.permissions?.length ?? 0;
|
|
44
|
+
const counts = [
|
|
45
|
+
relationCount ? `${relationCount} relation${relationCount === 1 ? "" : "s"}` : undefined,
|
|
46
|
+
commentCount ? `${commentCount} comment${commentCount === 1 ? "" : "s"}` : undefined,
|
|
47
|
+
permissionCount ? `${permissionCount} permission${permissionCount === 1 ? "" : "s"}` : undefined
|
|
48
|
+
].filter((entry) => entry !== undefined);
|
|
49
|
+
const payloadPreview = Object.keys(payload).length > 0
|
|
50
|
+
? `payload: ${JSON.stringify(payload)}`
|
|
51
|
+
: undefined;
|
|
52
|
+
return [
|
|
53
|
+
`${event.operation} ${event.path}`,
|
|
54
|
+
counts.length > 0 ? counts.join(", ") : undefined,
|
|
55
|
+
...semanticLines,
|
|
56
|
+
payloadPreview
|
|
57
|
+
].filter((line) => line !== undefined && line.trim() !== "").join("\n");
|
|
58
|
+
}
|
|
59
|
+
function firstNonEmpty(label, ...values) {
|
|
60
|
+
const value = values.find((candidate) => candidate && candidate.trim() !== "");
|
|
61
|
+
return value ? `${label}: ${value}` : undefined;
|
|
62
|
+
}
|
|
63
|
+
function truncateText(value, limit) {
|
|
64
|
+
if (value.length <= limit) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
return value.slice(0, limit);
|
|
68
|
+
}
|
|
69
|
+
function providerFromPath(path) {
|
|
70
|
+
return normalizePath(path)[0] ?? "";
|
|
71
|
+
}
|
|
72
|
+
function objectIdentityFromPath(path) {
|
|
73
|
+
const segments = normalizePath(path);
|
|
74
|
+
const filename = segments[segments.length - 1] ?? "";
|
|
75
|
+
return {
|
|
76
|
+
objectType: segments[1] ?? "unknown",
|
|
77
|
+
objectId: filename.replace(/\.[^.]+$/, "")
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function normalizePath(path) {
|
|
81
|
+
return path.split("/").filter(Boolean);
|
|
82
|
+
}
|
|
83
|
+
function isRecord(value) {
|
|
84
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relayfile/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"description": "TypeScript SDK for relayfile — real-time filesystem for humans and agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@relayfile/core": "0.10.
|
|
62
|
+
"@relayfile/core": "0.10.13",
|
|
63
63
|
"ignore": "^7.0.5",
|
|
64
64
|
"tar": "^7.5.10"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@relayfile/mount-darwin-arm64": "0.10.
|
|
68
|
-
"@relayfile/mount-darwin-x64": "0.10.
|
|
69
|
-
"@relayfile/mount-linux-arm64": "0.10.
|
|
70
|
-
"@relayfile/mount-linux-x64": "0.10.
|
|
67
|
+
"@relayfile/mount-darwin-arm64": "0.10.13",
|
|
68
|
+
"@relayfile/mount-darwin-x64": "0.10.13",
|
|
69
|
+
"@relayfile/mount-linux-arm64": "0.10.13",
|
|
70
|
+
"@relayfile/mount-linux-x64": "0.10.13"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"typescript": "^5.7.3",
|