From f838fe4ecc6edb14238dd00385870a2b0aefa800 Mon Sep 17 00:00:00 2001 From: jelveh Date: Sat, 13 Dec 2025 00:06:43 -0800 Subject: [PATCH] Remove Threads module from puter-js --- src/puter-js/index.d.ts | 2 - src/puter-js/src/index.js | 2 - src/puter-js/src/modules/Threads.js | 73 ------------------------- src/puter-js/types/modules/threads.d.ts | 27 --------- src/puter-js/types/puter.d.ts | 2 - 5 files changed, 106 deletions(-) delete mode 100644 src/puter-js/src/modules/Threads.js delete mode 100644 src/puter-js/types/modules/threads.d.ts diff --git a/src/puter-js/index.d.ts b/src/puter-js/index.d.ts index a1f80150..e5609952 100644 --- a/src/puter-js/index.d.ts +++ b/src/puter-js/index.d.ts @@ -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, diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index 96e3fd40..efdcf106 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -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); diff --git a/src/puter-js/src/modules/Threads.js b/src/puter-js/src/modules/Threads.js deleted file mode 100644 index a8af2e99..00000000 --- a/src/puter-js/src/modules/Threads.js +++ /dev/null @@ -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); - }); - } - } -} diff --git a/src/puter-js/types/modules/threads.d.ts b/src/puter-js/types/modules/threads.d.ts deleted file mode 100644 index 517197b7..00000000 --- a/src/puter-js/types/modules/threads.d.ts +++ /dev/null @@ -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) => 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; - edit (uid: string, spec?: string | ThreadPost): Promise; - delete (uid: string): Promise; - list (uid: string, page?: number, options?: Record): Promise; - subscribe (uid: string, callback: ThreadSubscriptionHandler): Promise; -} diff --git a/src/puter-js/types/puter.d.ts b/src/puter-js/types/puter.d.ts index 631fce84..5e008952 100644 --- a/src/puter-js/types/puter.d.ts +++ b/src/puter-js/types/puter.d.ts @@ -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;