wanzy 0.0.0-stage → 1.12.3

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/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Marchel Tech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # wanzy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official JavaScript SDK for **Wanzy.ai**. Version **1.12.2**.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install wanzy@1.12.2
9
+ ```
10
+
11
+ ## Authentication
12
+
13
+ The current Wanzy.ai API authenticates requests with the same session cookie used by the website. It does **not** currently expose a public API-key endpoint. Pass an authenticated session cookie; do not publish or commit it.
14
+
15
+ ## Usage (ESM)
16
+
17
+ ```js
18
+ import Wanzy from "wanzy";
19
+
20
+ const wanzy = new Wanzy({
21
+ baseURL: "https://marchel.tech.vrexit.web.id",
22
+ cookie: process.env.WANZY_COOKIE
23
+ });
24
+
25
+ const { chat } = await wanzy.chats.create("My project");
26
+ const result = await wanzy.chat.send({
27
+ chatId: chat.id,
28
+ message: "Buat landing page modern",
29
+ mode: "build",
30
+ onEvent(event) {
31
+ if (event.type === "token") process.stdout.write(event.text);
32
+ }
33
+ });
34
+ console.log(result.reply);
35
+ ```
36
+
37
+ ## CommonJS
38
+
39
+ ```js
40
+ const { default: Wanzy } = require("wanzy");
41
+ const client = new Wanzy({ cookie: process.env.WANZY_COOKIE });
42
+ ```
43
+
44
+ ## API
45
+
46
+ - `chats.list()`, `chats.create(title)`, `chats.get(chatId)`, `chats.delete(chatId)`
47
+ - `chat.stream({ chatId, message, mode })` — async SSE event iterator
48
+ - `chat.send({ chatId, message, mode, onEvent })` — collect stream and return final result
49
+ - `actions.install/start/stop/status(chatId)`
50
+ - `files.list(chatId)`, `files.download(chatId, path)`, `files.upload(chatId, file, filename)`
51
+ - `github.info()`, `github.connect({ token, owner, repo, branch })`, `github.disconnect()`
52
+
53
+ Modes: `fast`, `thinking`, and `build`.
54
+
55
+ The package ships both ESM and CommonJS entry points and TypeScript declarations. Publishing is automated through GitHub Actions.
package/dist/index.cjs ADDED
@@ -0,0 +1,147 @@
1
+ const DEFAULT_BASE_URL = "https://marchel.tech.vrexit.web.id";
2
+
3
+ class WanzyError extends Error {
4
+ constructor(message, status = 0, payload = null) {
5
+ super(message);
6
+ this.name = "WanzyError";
7
+ this.status = status;
8
+ this.payload = payload;
9
+ }
10
+ }
11
+
12
+ class Wanzy {
13
+ constructor(options = {}) {
14
+ if (typeof options === "string") options = { cookie: options };
15
+ this.baseURL = String(options.baseURL || DEFAULT_BASE_URL).replace(/\/+$/, "");
16
+ this.cookie = options.cookie || "";
17
+ this.fetch = options.fetch || globalThis.fetch;
18
+ this.headers = { ...(options.headers || {}) };
19
+ if (typeof this.fetch !== "function") throw new TypeError("Wanzy SDK membutuhkan fetch (Node.js 18+).");
20
+ this.chats = {
21
+ list: () => this.request("/api/wanzy/chats"),
22
+ create: (title = "New project") => this.request("/api/wanzy/chats", { method: "POST", body: { title } }),
23
+ get: (chatId) => this.request("/api/wanzy/chats?id=" + encodeURIComponent(required(chatId, "chatId"))),
24
+ delete: (chatId) => this.request("/api/wanzy/chats", { method: "DELETE", body: { chatId: required(chatId, "chatId") } })
25
+ };
26
+ this.chat = {
27
+ stream: (input) => this.stream(input),
28
+ send: async (input) => {
29
+ let result = null;
30
+ let text = "";
31
+ for await (const event of this.stream(input)) {
32
+ if (event.type === "token") text += event.text || "";
33
+ if (event.type === "done") result = { ...event, streamedText: text };
34
+ if (event.type === "error") throw new WanzyError(event.error || "Wanzy gagal memproses pesan.");
35
+ if (typeof input.onEvent === "function") input.onEvent(event);
36
+ }
37
+ if (!result) throw new WanzyError("Koneksi stream terputus sebelum event selesai.");
38
+ return result;
39
+ }
40
+ };
41
+ this.actions = {
42
+ run: (chatId, action) => this.request("/api/wanzy/action", { method: "POST", body: { chatId: required(chatId, "chatId"), action: required(action, "action") } }),
43
+ install: (chatId) => this.actions.run(chatId, "install"),
44
+ start: (chatId) => this.actions.run(chatId, "start"),
45
+ stop: (chatId) => this.actions.run(chatId, "stop"),
46
+ status: (chatId) => this.actions.run(chatId, "status")
47
+ };
48
+ this.files = {
49
+ list: (chatId) => this.request("/api/wanzy/files?chatId=" + encodeURIComponent(required(chatId, "chatId"))),
50
+ download: (chatId, path) => this.request("/api/wanzy/files?chatId=" + encodeURIComponent(required(chatId, "chatId")) + "&path=" + encodeURIComponent(required(path, "path")), { responseType: "arrayBuffer" }),
51
+ upload: (chatId, file, filename) => this.upload(chatId, file, filename)
52
+ };
53
+ this.github = {
54
+ info: () => this.request("/api/wanzy/github"),
55
+ connect: (credentials) => this.request("/api/wanzy/github", { method: "POST", body: credentials }),
56
+ disconnect: () => this.request("/api/wanzy/github", { method: "POST", body: { disconnect: true } })
57
+ };
58
+ }
59
+
60
+ async request(path, options = {}) {
61
+ const headers = { Accept: "application/json", ...this.headers, ...(options.headers || {}) };
62
+ if (this.cookie) headers.Cookie = this.cookie;
63
+ const init = { method: options.method || "GET", headers, signal: options.signal };
64
+ if (options.body !== undefined) {
65
+ headers["Content-Type"] = "application/json";
66
+ init.body = JSON.stringify(options.body);
67
+ }
68
+ const response = await this.fetch(this.baseURL + path, init);
69
+ if (options.responseType === "arrayBuffer") {
70
+ if (!response.ok) throw await responseError(response);
71
+ return response.arrayBuffer();
72
+ }
73
+ const payload = await response.json().catch(() => ({}));
74
+ if (!response.ok) throw new WanzyError(payload.error || response.statusText || "Request gagal.", response.status, payload);
75
+ return payload;
76
+ }
77
+
78
+ async *stream(input = {}) {
79
+ const chatId = required(input.chatId, "chatId");
80
+ const message = required(input.message, "message");
81
+ const headers = { Accept: "text/event-stream", "Content-Type": "application/json", ...this.headers };
82
+ if (this.cookie) headers.Cookie = this.cookie;
83
+ const response = await this.fetch(this.baseURL + "/api/wanzy/chat", {
84
+ method: "POST", headers,
85
+ body: JSON.stringify({
86
+ chatId, message,
87
+ mode: ["fast", "thinking", "build"].includes(input.mode) ? input.mode : "fast",
88
+ attachmentIds: Array.isArray(input.attachmentIds) ? input.attachmentIds : []
89
+ }),
90
+ signal: input.signal
91
+ });
92
+ if (!response.ok) throw await responseError(response);
93
+ if (!response.body) throw new WanzyError("Server tidak mengirim response stream.");
94
+ const reader = response.body.getReader();
95
+ const decoder = new TextDecoder();
96
+ let buffer = "";
97
+ try {
98
+ while (true) {
99
+ const { value, done } = await reader.read();
100
+ if (done) break;
101
+ buffer += decoder.decode(value, { stream: true }).replace(/\r\n/g, "\n");
102
+ let boundary;
103
+ while ((boundary = buffer.indexOf("\n\n")) !== -1) {
104
+ const frame = buffer.slice(0, boundary);
105
+ buffer = buffer.slice(boundary + 2);
106
+ const data = frame.split("\n").filter(line => line.startsWith("data:")).map(line => line.slice(5).trim()).join("\n");
107
+ if (!data) continue;
108
+ try { yield JSON.parse(data); } catch { /* ignore malformed SSE frame */ }
109
+ }
110
+ }
111
+ buffer += decoder.decode();
112
+ if (buffer.trim()) {
113
+ const data = buffer.split("\n").filter(line => line.startsWith("data:")).map(line => line.slice(5).trim()).join("\n");
114
+ if (data) { try { yield JSON.parse(data); } catch { /* ignore */ } }
115
+ }
116
+ } finally {
117
+ reader.releaseLock();
118
+ }
119
+ }
120
+
121
+ async upload(chatId, file, filename = file?.name || "upload.bin") {
122
+ if (!file) throw new TypeError("File wajib diisi.");
123
+ const form = new FormData();
124
+ form.append("chatId", required(chatId, "chatId"));
125
+ form.append("file", file, filename);
126
+ const headers = { ...this.headers };
127
+ if (this.cookie) headers.Cookie = this.cookie;
128
+ const response = await this.fetch(this.baseURL + "/api/wanzy/files", { method: "POST", headers, body: form });
129
+ const payload = await response.json().catch(() => ({}));
130
+ if (!response.ok) throw new WanzyError(payload.error || "Upload gagal.", response.status, payload);
131
+ return payload;
132
+ }
133
+ }
134
+
135
+ function required(value, name) {
136
+ const result = String(value || "").trim();
137
+ if (!result) throw new TypeError(name + " wajib diisi.");
138
+ return result;
139
+ }
140
+
141
+ async function responseError(response) {
142
+ const payload = await response.json().catch(() => ({}));
143
+ return new WanzyError(payload.error || response.statusText || "Request gagal.", response.status, payload);
144
+ }
145
+
146
+
147
+ module.exports = { Wanzy, WanzyError, default: Wanzy };
@@ -0,0 +1,58 @@
1
+ export type WanzyMode = "fast" | "thinking" | "build";
2
+ export interface WanzyOptions {
3
+ baseURL?: string;
4
+ /** Session cookie from an authenticated Wanzy.ai browser session. */
5
+ cookie?: string;
6
+ headers?: Record<string, string>;
7
+ fetch?: typeof fetch;
8
+ }
9
+ export interface WanzyChatInput {
10
+ chatId: string;
11
+ message: string;
12
+ mode?: WanzyMode;
13
+ attachmentIds?: string[];
14
+ signal?: AbortSignal;
15
+ onEvent?: (event: WanzyStreamEvent) => void;
16
+ }
17
+ export type WanzyStreamEvent =
18
+ | { type: "status"; text: string }
19
+ | { type: "token"; text: string }
20
+ | { type: "done"; ok: true; reply: string; previewUrl: string | null; projectId: string | null; files: unknown[]; streamedText?: string }
21
+ | { type: "error"; error: string };
22
+ export class WanzyError extends Error {
23
+ status: number;
24
+ payload: unknown;
25
+ constructor(message: string, status?: number, payload?: unknown);
26
+ }
27
+ export class Wanzy {
28
+ constructor(options?: WanzyOptions | string);
29
+ baseURL: string;
30
+ chats: {
31
+ list(): Promise<{ chats: unknown[] }>;
32
+ create(title?: string): Promise<{ chat: unknown }>;
33
+ get(chatId: string): Promise<{ chat: unknown; messages: unknown[] }>;
34
+ delete(chatId: string): Promise<{ ok: boolean }>;
35
+ };
36
+ chat: {
37
+ stream(input: WanzyChatInput): AsyncGenerator<WanzyStreamEvent>;
38
+ send(input: WanzyChatInput): Promise<Extract<WanzyStreamEvent, { type: "done" }>>;
39
+ };
40
+ actions: {
41
+ run(chatId: string, action: "install" | "start" | "stop" | "status"): Promise<Record<string, unknown>>;
42
+ install(chatId: string): Promise<Record<string, unknown>>;
43
+ start(chatId: string): Promise<Record<string, unknown>>;
44
+ stop(chatId: string): Promise<Record<string, unknown>>;
45
+ status(chatId: string): Promise<Record<string, unknown>>;
46
+ };
47
+ files: {
48
+ list(chatId: string): Promise<{ names: string[]; projectId: string | null; github: unknown }>;
49
+ download(chatId: string, path: string): Promise<ArrayBuffer>;
50
+ upload(chatId: string, file: Blob, filename?: string): Promise<Record<string, unknown>>;
51
+ };
52
+ github: {
53
+ info(): Promise<Record<string, unknown>>;
54
+ connect(credentials: { token: string; owner: string; repo: string; branch?: string }): Promise<Record<string, unknown>>;
55
+ disconnect(): Promise<Record<string, unknown>>;
56
+ };
57
+ }
58
+ export default Wanzy;
package/dist/index.js ADDED
@@ -0,0 +1,146 @@
1
+ const DEFAULT_BASE_URL = "https://marchel.tech.vrexit.web.id";
2
+
3
+ export class WanzyError extends Error {
4
+ constructor(message, status = 0, payload = null) {
5
+ super(message);
6
+ this.name = "WanzyError";
7
+ this.status = status;
8
+ this.payload = payload;
9
+ }
10
+ }
11
+
12
+ export class Wanzy {
13
+ constructor(options = {}) {
14
+ if (typeof options === "string") options = { cookie: options };
15
+ this.baseURL = String(options.baseURL || DEFAULT_BASE_URL).replace(/\/+$/, "");
16
+ this.cookie = options.cookie || "";
17
+ this.fetch = options.fetch || globalThis.fetch;
18
+ this.headers = { ...(options.headers || {}) };
19
+ if (typeof this.fetch !== "function") throw new TypeError("Wanzy SDK membutuhkan fetch (Node.js 18+).");
20
+ this.chats = {
21
+ list: () => this.request("/api/wanzy/chats"),
22
+ create: (title = "New project") => this.request("/api/wanzy/chats", { method: "POST", body: { title } }),
23
+ get: (chatId) => this.request("/api/wanzy/chats?id=" + encodeURIComponent(required(chatId, "chatId"))),
24
+ delete: (chatId) => this.request("/api/wanzy/chats", { method: "DELETE", body: { chatId: required(chatId, "chatId") } })
25
+ };
26
+ this.chat = {
27
+ stream: (input) => this.stream(input),
28
+ send: async (input) => {
29
+ let result = null;
30
+ let text = "";
31
+ for await (const event of this.stream(input)) {
32
+ if (event.type === "token") text += event.text || "";
33
+ if (event.type === "done") result = { ...event, streamedText: text };
34
+ if (event.type === "error") throw new WanzyError(event.error || "Wanzy gagal memproses pesan.");
35
+ if (typeof input.onEvent === "function") input.onEvent(event);
36
+ }
37
+ if (!result) throw new WanzyError("Koneksi stream terputus sebelum event selesai.");
38
+ return result;
39
+ }
40
+ };
41
+ this.actions = {
42
+ run: (chatId, action) => this.request("/api/wanzy/action", { method: "POST", body: { chatId: required(chatId, "chatId"), action: required(action, "action") } }),
43
+ install: (chatId) => this.actions.run(chatId, "install"),
44
+ start: (chatId) => this.actions.run(chatId, "start"),
45
+ stop: (chatId) => this.actions.run(chatId, "stop"),
46
+ status: (chatId) => this.actions.run(chatId, "status")
47
+ };
48
+ this.files = {
49
+ list: (chatId) => this.request("/api/wanzy/files?chatId=" + encodeURIComponent(required(chatId, "chatId"))),
50
+ download: (chatId, path) => this.request("/api/wanzy/files?chatId=" + encodeURIComponent(required(chatId, "chatId")) + "&path=" + encodeURIComponent(required(path, "path")), { responseType: "arrayBuffer" }),
51
+ upload: (chatId, file, filename) => this.upload(chatId, file, filename)
52
+ };
53
+ this.github = {
54
+ info: () => this.request("/api/wanzy/github"),
55
+ connect: (credentials) => this.request("/api/wanzy/github", { method: "POST", body: credentials }),
56
+ disconnect: () => this.request("/api/wanzy/github", { method: "POST", body: { disconnect: true } })
57
+ };
58
+ }
59
+
60
+ async request(path, options = {}) {
61
+ const headers = { Accept: "application/json", ...this.headers, ...(options.headers || {}) };
62
+ if (this.cookie) headers.Cookie = this.cookie;
63
+ const init = { method: options.method || "GET", headers, signal: options.signal };
64
+ if (options.body !== undefined) {
65
+ headers["Content-Type"] = "application/json";
66
+ init.body = JSON.stringify(options.body);
67
+ }
68
+ const response = await this.fetch(this.baseURL + path, init);
69
+ if (options.responseType === "arrayBuffer") {
70
+ if (!response.ok) throw await responseError(response);
71
+ return response.arrayBuffer();
72
+ }
73
+ const payload = await response.json().catch(() => ({}));
74
+ if (!response.ok) throw new WanzyError(payload.error || response.statusText || "Request gagal.", response.status, payload);
75
+ return payload;
76
+ }
77
+
78
+ async *stream(input = {}) {
79
+ const chatId = required(input.chatId, "chatId");
80
+ const message = required(input.message, "message");
81
+ const headers = { Accept: "text/event-stream", "Content-Type": "application/json", ...this.headers };
82
+ if (this.cookie) headers.Cookie = this.cookie;
83
+ const response = await this.fetch(this.baseURL + "/api/wanzy/chat", {
84
+ method: "POST", headers,
85
+ body: JSON.stringify({
86
+ chatId, message,
87
+ mode: ["fast", "thinking", "build"].includes(input.mode) ? input.mode : "fast",
88
+ attachmentIds: Array.isArray(input.attachmentIds) ? input.attachmentIds : []
89
+ }),
90
+ signal: input.signal
91
+ });
92
+ if (!response.ok) throw await responseError(response);
93
+ if (!response.body) throw new WanzyError("Server tidak mengirim response stream.");
94
+ const reader = response.body.getReader();
95
+ const decoder = new TextDecoder();
96
+ let buffer = "";
97
+ try {
98
+ while (true) {
99
+ const { value, done } = await reader.read();
100
+ if (done) break;
101
+ buffer += decoder.decode(value, { stream: true }).replace(/\r\n/g, "\n");
102
+ let boundary;
103
+ while ((boundary = buffer.indexOf("\n\n")) !== -1) {
104
+ const frame = buffer.slice(0, boundary);
105
+ buffer = buffer.slice(boundary + 2);
106
+ const data = frame.split("\n").filter(line => line.startsWith("data:")).map(line => line.slice(5).trim()).join("\n");
107
+ if (!data) continue;
108
+ try { yield JSON.parse(data); } catch { /* ignore malformed SSE frame */ }
109
+ }
110
+ }
111
+ buffer += decoder.decode();
112
+ if (buffer.trim()) {
113
+ const data = buffer.split("\n").filter(line => line.startsWith("data:")).map(line => line.slice(5).trim()).join("\n");
114
+ if (data) { try { yield JSON.parse(data); } catch { /* ignore */ } }
115
+ }
116
+ } finally {
117
+ reader.releaseLock();
118
+ }
119
+ }
120
+
121
+ async upload(chatId, file, filename = file?.name || "upload.bin") {
122
+ if (!file) throw new TypeError("File wajib diisi.");
123
+ const form = new FormData();
124
+ form.append("chatId", required(chatId, "chatId"));
125
+ form.append("file", file, filename);
126
+ const headers = { ...this.headers };
127
+ if (this.cookie) headers.Cookie = this.cookie;
128
+ const response = await this.fetch(this.baseURL + "/api/wanzy/files", { method: "POST", headers, body: form });
129
+ const payload = await response.json().catch(() => ({}));
130
+ if (!response.ok) throw new WanzyError(payload.error || "Upload gagal.", response.status, payload);
131
+ return payload;
132
+ }
133
+ }
134
+
135
+ function required(value, name) {
136
+ const result = String(value || "").trim();
137
+ if (!result) throw new TypeError(name + " wajib diisi.");
138
+ return result;
139
+ }
140
+
141
+ async function responseError(response) {
142
+ const payload = await response.json().catch(() => ({}));
143
+ return new WanzyError(payload.error || response.statusText || "Request gagal.", response.status, payload);
144
+ }
145
+
146
+ export default Wanzy;
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "wanzy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.12.3",
4
+ "description": "Official JavaScript SDK for Wanzy.ai",
5
+ "license": "MIT",
6
+ "author": "Marchel Tech",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "scripts": {
27
+ "build": "node ./scripts/build.mjs",
28
+ "prepack": "npm run build",
29
+ "test": "node --test",
30
+ "publish:local": "node ./scripts/publish.mjs"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }