Remove Threads module from puter-js

This commit is contained in:
jelveh
2025-12-13 00:06:43 -08:00
parent 8f7a735cc0
commit f838fe4ecc
5 changed files with 0 additions and 106 deletions

View File

@@ -11,7 +11,6 @@ import type { KV, KVIncrementPath, KVPair } from './types/modules/kv.d.ts';
import type { Networking, PSocket, PTLSSocket } from './types/modules/networking.d.ts';
import type { OS } from './types/modules/os.d.ts';
import type { Perms } from './types/modules/perms.d.ts';
import type Threads from './types/modules/threads.d.ts';
import type { AlertButton, AppConnection, AppConnectionCloseEvent, CancelAwarePromise, ContextMenuItem, ContextMenuOptions, DirectoryPickerOptions, FilePickerOptions, LaunchAppOptions, MenuItem, MenubarOptions, ThemeData, UI, WindowOptions } from './types/modules/ui.d.ts';
import type Util, { UtilRPC } from './types/modules/util.d.ts';
import type { WorkerDeployment, WorkerInfo, WorkersHandler } from './types/modules/workers.d.ts';
@@ -93,7 +92,6 @@ export type {
Speech2TxtOptions,
Subdomain,
ThemeData,
Threads,
ToolSchema,
Txt2ImgOptions,
Txt2SpeechCallable,

View File

@@ -18,7 +18,6 @@ import { PTLSSocket } from './modules/networking/PTLS.js';
import { pFetch } from './modules/networking/requests.js';
import OS from './modules/OS.js';
import Perms from './modules/Perms.js';
import Threads from './modules/Threads.js';
import UI from './modules/UI.js';
import Util from './modules/Util.js';
import { WorkersHandler } from './modules/Workers.js';
@@ -170,7 +169,6 @@ const puterInit = (function () {
this.registerModule('apps', Apps);
this.registerModule('ai', AI);
this.registerModule('kv', KV);
this.registerModule('threads', Threads);
this.registerModule('perms', Perms);
this.registerModule('drivers', Drivers);
this.registerModule('debug', Debug);

View File

@@ -1,73 +0,0 @@
import { RequestError } from '../lib/RequestError.js';
export default class Threads {
constructor (puter) {
this.puter = puter;
this.authToken = puter.authToken;
this.APIOrigin = puter.APIOrigin;
}
setAuthToken (authToken) {
this.authToken = authToken;
}
setAPIOrigin (APIOrigin) {
this.APIOrigin = APIOrigin;
}
async req_ (method, route, body) {
const resp = await fetch(this.APIOrigin + route, {
method,
headers: {
Authorization: `Bearer ${this.authToken}`,
...(body ? { 'Content-Type': 'application/json' } : {}),
},
...(body ? { body: JSON.stringify(body) } : {}),
});
if ( ! resp.ok ) {
const resp_data = await resp.json();
const err = new RequestError(resp_data.message);
err.response = resp_data;
throw err;
}
return await resp.json();
}
async create (spec, parent) {
if ( typeof spec === 'string' ) spec = { text: spec };
return await this.req_('POST', '/threads/create', {
...spec,
...(parent ? { parent } : {}),
});
}
async edit (uid, spec = {}) {
if ( typeof spec === 'string' ) spec = { text: spec };
await this.req_('PUT', `/threads/edit/${ encodeURIComponent(uid)}`, {
...spec,
});
}
async delete (uid) {
await this.req_('DELETE', `/threads/${ encodeURIComponent(uid)}`);
}
async list (uid, page, options) {
return await this.req_('POST',
`/threads/list/${ encodeURIComponent(uid) }/${ page}`,
options ?? {});
}
async subscribe (uid, callback) {
puter.fs.socket.emit('thread.sub-request', { uid });
// socket.io, which we use unfortunatelly, doesn't handle
// wildcard events, so we have to just put them all here.
const events = [
'post', 'edit', 'delete', 'child-edit', 'child-delete',
];
for ( const event of events ) {
puter.fs.socket.on(`thread.${event}`, (data) => {
if ( data.subscription === uid ) callback(event, data);
});
}
}
}

View File

@@ -1,27 +0,0 @@
export interface ThreadPost {
uid?: string;
parent?: string;
text?: string;
[key: string]: unknown;
}
export interface ThreadListResult {
posts: ThreadPost[];
total?: number;
page?: number;
}
export type ThreadSubscriptionHandler = (event: string, data: Record<string, unknown>) => void;
export default class Threads {
constructor (context: { authToken?: string; APIOrigin: string });
setAuthToken (authToken: string): void;
setAPIOrigin (APIOrigin: string): void;
create (spec: string | ThreadPost, parent?: string): Promise<ThreadPost>;
edit (uid: string, spec?: string | ThreadPost): Promise<void>;
delete (uid: string): Promise<void>;
list (uid: string, page?: number, options?: Record<string, unknown>): Promise<ThreadListResult>;
subscribe (uid: string, callback: ThreadSubscriptionHandler): Promise<void>;
}

View File

@@ -10,7 +10,6 @@ import type { KV } from './modules/kv.d.ts';
import type { Networking } from './modules/networking.d.ts';
import type { OS } from './modules/os.d.ts';
import type { Perms } from './modules/perms.d.ts';
import type Threads from './modules/threads.d.ts';
import type { UI } from './modules/ui.d.ts';
import type Util from './modules/util.d.ts';
import type { WorkersHandler } from './modules/workers.d.ts';
@@ -55,7 +54,6 @@ export class Puter {
ui: UI;
hosting: Hosting;
kv: KV;
threads: Threads;
perms: Perms;
drivers: Drivers;
debug: Debug;