build: PaddedCell-style install.mjs + SDK-aligned packaging
install.mjs (--install/--build-only/--uninstall/--openclaw-profile-path), tsconfig outDir dist/fabric, package.json openclaw file dep + main. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
53
dist/fabric/src/fabric-client.js
vendored
Normal file
53
dist/fabric/src/fabric-client.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Thin Fabric REST client. One auth concept: an agent's Center API key is
|
||||
// exchanged for a normal user session (POST /auth/agent/login); the returned
|
||||
// guild access tokens are used to post messages and call channel APIs.
|
||||
export class FabricClient {
|
||||
centerApiBase;
|
||||
constructor(centerApiBase) {
|
||||
this.centerApiBase = centerApiBase;
|
||||
}
|
||||
async post(url, body, auth) {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
...(auth ? { authorization: `Bearer ${auth}` } : {}),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
throw new Error(`POST ${url} -> ${res.status} ${text}`);
|
||||
}
|
||||
return (await res.json());
|
||||
}
|
||||
// Exchange an agent API key for a Fabric user session (+ guild tokens).
|
||||
agentLogin(apiKey) {
|
||||
return this.post(`${this.centerApiBase}/auth/agent/login`, { apiKey });
|
||||
}
|
||||
// Refresh the center access token (guild tokens are re-fetched via /auth/me/guilds).
|
||||
async refresh(refreshToken) {
|
||||
return this.post(`${this.centerApiBase}/auth/refresh`, { refreshToken });
|
||||
}
|
||||
async meGuilds(accessToken) {
|
||||
const res = await fetch(`${this.centerApiBase}/auth/me/guilds`, {
|
||||
headers: { authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!res.ok)
|
||||
throw new Error(`me/guilds -> ${res.status}`);
|
||||
return (await res.json());
|
||||
}
|
||||
// ---- guild-scoped (use the per-guild access token) ----
|
||||
postMessage(guildEndpoint, guildToken, channelId, content, authorUserId) {
|
||||
return this.post(`${guildEndpoint}/api/channels/${channelId}/messages`, { content, authorUserId }, guildToken);
|
||||
}
|
||||
createChannel(guildEndpoint, guildToken, body) {
|
||||
return this.post(`${guildEndpoint}/api/channels`, body, guildToken);
|
||||
}
|
||||
closeChannel(guildEndpoint, guildToken, channelId) {
|
||||
return this.post(`${guildEndpoint}/api/channels/${channelId}/close`, {}, guildToken);
|
||||
}
|
||||
joinChannel(guildEndpoint, guildToken, channelId) {
|
||||
return this.post(`${guildEndpoint}/api/channels/${channelId}/join`, {}, guildToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user