lazycow 0.0.0-stage → 0.14.0

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,18 @@
1
+ Lazycow Studio
2
+ Copyright (c) 2026 kensaurus LLC
3
+
4
+ This product includes software developed by Kenji Sakuramoto
5
+ (kensaurus, https://kensaur.us) and contributors.
6
+ Original source: https://github.com/kensaurus/lazycow-studio
7
+
8
+ "Lazycow", "Lazycow Studio" and the sleepy-cow icon are trademarks of
9
+ kensaurus LLC. The Apache License 2.0 does not grant permission to use
10
+ them (section 6). See TRADEMARKS.md.
11
+
12
+ If you distribute this software or a work based on it, keep this NOTICE
13
+ file (Apache License 2.0, section 4(d)). We also ask that you keep the
14
+ line "Based on Lazycow Studio by kensaurus" with a link to
15
+ https://kensaur.us in your About screen and README.
16
+
17
+ Third-party components keep their own licences; see
18
+ THIRD_PARTY_NOTICES.md.
package/README.md CHANGED
@@ -1,3 +1,79 @@
1
- # Temporary Holding Version
1
+ # lazycow
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
+ **Lazycow Studio from the command line, from your AI agent and from your code.**
4
+
5
+ [Lazycow Studio](https://github.com/kensaurus/lazycow-studio) turns the photos and videos you never edited into short vertical reels and YouTube trip films. It runs on your own computer, and a person approves every post. This package connects to it in three ways:
6
+
7
+ | You want to… | Run |
8
+ |:--|:--|
9
+ | Install the studio (no terminal skills needed after this line) | `npx lazycow install` |
10
+ | Let Claude Code, Claude Desktop or Cursor drive it | `claude mcp add lazycow -- npx -y lazycow mcp` |
11
+ | Script it from Node | `import { createClient } from "lazycow"` |
12
+
13
+ Approving a reel stays a person's job in the studio. Agents and scripts can make, plan and post approved reels. They cannot approve.
14
+
15
+ ## Install the studio
16
+
17
+ ```
18
+ npx lazycow install
19
+ ```
20
+
21
+ It downloads this version's release zip from GitHub, checks it against the SHA-256 built into the package, unpacks it to `~/Lazycow Studio`, and starts the double-click setup. The setup installs Node, Python and ffmpeg for Lazycow only, in about 10 minutes. Options: `--dir <empty folder>`, `--yes` (take every suggestion).
22
+
23
+ Prefer to click? Download the zip from [Releases](https://github.com/kensaurus/lazycow-studio/releases), unzip it, read `README.TXT`, and double-click **Start Lazycow**.
24
+
25
+ ## Connect an AI agent (MCP)
26
+
27
+ Claude Code:
28
+
29
+ ```
30
+ claude mcp add lazycow -- npx -y lazycow mcp
31
+ ```
32
+
33
+ Claude Desktop or Cursor (`claude_desktop_config.json` / `.cursor/mcp.json`):
34
+
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "lazycow": { "command": "npx", "args": ["-y", "lazycow", "mcp"] }
39
+ }
40
+ }
41
+ ```
42
+
43
+ The server finds the studio by itself: `STUDIO_PORT` and `STUDIO_API_TOKEN` when set, else the `.env` in `LAZYCOW_DIR`, else the folder the setup recorded. So your agent config never holds a copy of the token. Tools: studio status, list and make reels, remix, plan and publish approved reels, jobs, projects, research, priced AI assist, performance. Full list: [docs/mcp.md](https://github.com/kensaurus/lazycow-studio/blob/main/docs/mcp.md).
44
+
45
+ Each tool answers with a plain sentence and the data, and the same data as `structuredContent` for programs (a list
46
+ arrives as `{ "items": [...] }`). Account secrets never leave the studio.
47
+
48
+ Listed in the official MCP Registry as `io.github.kensaurus/lazycow`.
49
+
50
+ ## Use the API from code
51
+
52
+ ```js
53
+ import { createClient } from "lazycow";
54
+
55
+ const studio = createClient(); // or createClient({ port: 4318, token: "..." })
56
+ const health = await studio.health();
57
+ const { reels } = await studio.overview();
58
+ const anything = await studio.request("GET", "/api/posts");
59
+ ```
60
+
61
+ Every route is in the studio's [OpenAPI document](https://github.com/kensaurus/lazycow-studio/blob/main/docs/openapi.yaml). Errors are `StudioError` with `status`, `path` and `body`. Types are included.
62
+
63
+ From a shell:
64
+
65
+ ```
66
+ npx lazycow status
67
+ npx lazycow api GET /api/posts
68
+ npx lazycow open
69
+ ```
70
+
71
+ ## Requirements
72
+
73
+ Node 20 or newer. The studio itself runs on Windows 10/11 and macOS 14+ (Apple silicon); Linux works from source.
74
+
75
+ ## Credits and licence
76
+
77
+ Made by **kensaurus** (Kenji Sakuramoto, [kensaur.us](https://kensaur.us)). Apache-2.0: if you redistribute it or build on it, keep the `NOTICE` file, and please keep the line "Based on Lazycow Studio by kensaurus". "Lazycow" and the sleepy-cow icon are trademarks of kensaurus LLC ([TRADEMARKS.md](https://github.com/kensaurus/lazycow-studio/blob/main/TRADEMARKS.md)).
78
+
79
+ Like it? [Support Lazycow](https://github.com/kensaurus/lazycow-studio/blob/main/SUPPORTING.md): supporters get their feature requests looked at first.
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * FILE: packages/lazycow/bin/lazycow.mjs
4
+ * PURPOSE: The `lazycow` command: connect AI agents (mcp), install the studio, open it, check it, call its API.
5
+ * Part of Lazycow Studio by kensaurus (https://kensaur.us). Apache-2.0.
6
+ */
7
+ import { readFileSync } from "node:fs";
8
+ import { spawn } from "node:child_process";
9
+
10
+ const PKG = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
11
+ const [cmd = "help", ...rest] = process.argv.slice(2);
12
+
13
+ const HELP = `lazycow ${PKG.version}: Lazycow Studio from the command line. By kensaurus, https://kensaur.us
14
+
15
+ npx lazycow install [--dir <folder>] [--yes] Download, check (SHA-256) and set up the studio
16
+ npx lazycow open Open the studio in your browser
17
+ npx lazycow status Is the studio running, and is this computer ready
18
+ npx -y lazycow mcp MCP server for Claude Code, Claude Desktop, Cursor
19
+ npx lazycow api <GET|POST> <path> [json] Call any studio API route (docs/openapi.yaml)
20
+
21
+ Connect Claude Code: claude mcp add lazycow -- npx -y lazycow mcp
22
+ Finds the studio by STUDIO_PORT / STUDIO_API_TOKEN, else LAZYCOW_DIR's .env, else the folder the setup recorded.
23
+ Approving a reel stays a person's job in the studio. Agents and scripts cannot approve.
24
+
25
+ Code: https://github.com/kensaurus/lazycow-studio (Apache-2.0, keep the NOTICE)
26
+ Support: https://github.com/kensaurus/lazycow-studio/blob/main/SUPPORTING.md`;
27
+
28
+ function flag(name) {
29
+ const i = rest.indexOf(name);
30
+ if (i < 0) return undefined;
31
+ const v = rest[i + 1];
32
+ return v && !v.startsWith("--") ? v : true;
33
+ }
34
+
35
+ function fail(err) {
36
+ process.stderr.write(`lazycow: ${err?.message || err}\n`);
37
+ process.exit(1);
38
+ }
39
+
40
+ function openUrl(url) {
41
+ const [c, a] = process.platform === "win32" ? ["cmd.exe", ["/c", "start", "", url]]
42
+ : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
43
+ spawn(c, a, { detached: true, stdio: "ignore" }).on("error", () => {}).unref();
44
+ }
45
+
46
+ try {
47
+ switch (cmd) {
48
+ case "mcp":
49
+ await import("../lib/mcp.mjs");
50
+ break;
51
+ case "install": {
52
+ const { install } = await import("../lib/install.mjs");
53
+ const dir = flag("--dir"), zip = flag("--zip");
54
+ await install({ dir: typeof dir === "string" ? dir : undefined, zip: typeof zip === "string" ? zip : undefined,
55
+ yes: !!flag("--yes"), noStart: !!flag("--no-start") });
56
+ break;
57
+ }
58
+ case "status": {
59
+ const { createClient } = await import("../lib/client.mjs");
60
+ const c = createClient();
61
+ const h = await c.health();
62
+ const ok = h && (h.ok ?? true);
63
+ process.stdout.write(`Lazycow Studio ${h?.version || "?"} is running at ${c.base}${ok ? "" : " (it reports a problem)"}\n`);
64
+ if (rest.includes("--json")) process.stdout.write(JSON.stringify(h, null, 2) + "\n");
65
+ break;
66
+ }
67
+ case "open": {
68
+ const { createClient } = await import("../lib/client.mjs");
69
+ const c = createClient();
70
+ await c.health();
71
+ openUrl(c.base + "/");
72
+ process.stdout.write(`Opened ${c.base}\n`);
73
+ break;
74
+ }
75
+ case "api": {
76
+ const [method, path, json] = rest;
77
+ if (!method || !path) fail("usage: lazycow api <GET|POST> <path> [json]");
78
+ const { createClient } = await import("../lib/client.mjs");
79
+ let body;
80
+ if (json !== undefined) { try { body = JSON.parse(json); } catch { fail("the body must be JSON"); } }
81
+ const out = await createClient().request(method, path, body);
82
+ process.stdout.write((typeof out === "string" ? out : JSON.stringify(out, null, 2)) + "\n");
83
+ break;
84
+ }
85
+ case "-v": case "--version": case "version":
86
+ process.stdout.write(PKG.version + "\n");
87
+ break;
88
+ case "-h": case "--help": case "help":
89
+ process.stdout.write(HELP + "\n");
90
+ break;
91
+ default:
92
+ fail(`unknown command "${cmd}". Try: npx lazycow help`);
93
+ }
94
+ } catch (err) {
95
+ fail(err);
96
+ }
@@ -0,0 +1,39 @@
1
+ // Types for the lazycow package. Part of Lazycow Studio by kensaurus (https://kensaur.us). Apache-2.0.
2
+
3
+ export interface ClientOptions {
4
+ /** Full base URL, e.g. "http://127.0.0.1:4317". Wins over port. */
5
+ base?: string;
6
+ /** Studio port. Default: STUDIO_PORT, else the studio's .env, else 4317. */
7
+ port?: number;
8
+ /** API token. Default: STUDIO_API_TOKEN, else the studio's .env. */
9
+ token?: string;
10
+ /** The studio folder whose .env to read. Default: LAZYCOW_DIR, else the folder the setup recorded. */
11
+ dir?: string;
12
+ /** Per-request timeout in ms. Default 120000. */
13
+ timeoutMs?: number;
14
+ /** A fetch implementation (tests, proxies). Default: global fetch. */
15
+ fetch?: typeof fetch;
16
+ }
17
+
18
+ export declare class StudioError extends Error {
19
+ status: number;
20
+ path: string;
21
+ body: unknown;
22
+ }
23
+
24
+ export interface StudioClient {
25
+ readonly base: string;
26
+ request<T = unknown>(method: string, path: `/${string}`, body?: unknown): Promise<T>;
27
+ get<T = unknown>(path: `/${string}`): Promise<T>;
28
+ post<T = unknown>(path: `/${string}`, body?: unknown): Promise<T>;
29
+ health<T = Record<string, unknown>>(): Promise<T>;
30
+ about<T = Record<string, unknown>>(): Promise<T>;
31
+ overview<T = Record<string, unknown>>(): Promise<T>;
32
+ posts<T = unknown>(): Promise<T>;
33
+ themes<T = unknown>(): Promise<T>;
34
+ projects<T = unknown>(): Promise<T>;
35
+ problems<T = unknown>(): Promise<T>;
36
+ }
37
+
38
+ export declare function createClient(opts?: ClientOptions): StudioClient;
39
+ export default createClient;
package/lib/client.mjs ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * FILE: packages/lazycow/lib/client.mjs
3
+ * PURPOSE: A small client for the Lazycow Studio HTTP API, for your own scripts, bots and dashboards.
4
+ * OVERVIEW: createClient() finds the studio on this computer (lib/env.mjs) and returns typed helpers for the common
5
+ * calls plus request() for any route in the OpenAPI document (docs/openapi.yaml in the studio). It only talks
6
+ * to the studio; the studio decides everything. Approving a reel stays a person's job in the studio.
7
+ * DEPENDENCIES: global fetch (Node >= 20)
8
+ * Part of Lazycow Studio by kensaurus (https://kensaur.us). Apache-2.0.
9
+ */
10
+ import { studioTarget } from "./env.mjs";
11
+
12
+ export class StudioError extends Error {
13
+ constructor(message, { status = 0, path = "", body } = {}) {
14
+ super(message);
15
+ this.name = "StudioError";
16
+ this.status = status;
17
+ this.path = path;
18
+ this.body = body;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * @param {{ base?: string, port?: number, token?: string, dir?: string, timeoutMs?: number, fetch?: typeof fetch }} [opts]
24
+ */
25
+ export function createClient(opts = {}) {
26
+ const { base, token } = studioTarget(opts);
27
+ const timeoutMs = opts.timeoutMs ?? 120_000;
28
+ const doFetch = opts.fetch || globalThis.fetch;
29
+ if (typeof doFetch !== "function") throw new Error("lazycow needs Node 20 or newer (global fetch).");
30
+
31
+ async function request(method, path, body) {
32
+ method = String(method || "GET").toUpperCase();
33
+ if (!String(path).startsWith("/")) throw new TypeError(`path must start with "/": ${path}`);
34
+ const headers = { accept: "application/json" };
35
+ if (token) headers.authorization = `Bearer ${token}`;
36
+ if (method !== "GET" && method !== "HEAD") {
37
+ headers.origin = base; // the studio answers a write only from its own origin
38
+ headers["content-type"] = "application/json";
39
+ }
40
+ let res;
41
+ try {
42
+ res = await doFetch(base + path, {
43
+ method, headers,
44
+ body: body === undefined || method === "GET" ? undefined : JSON.stringify(body),
45
+ signal: AbortSignal.timeout(timeoutMs),
46
+ });
47
+ } catch (err) {
48
+ const why = err?.name === "TimeoutError" ? `no answer within ${Math.round(timeoutMs / 1000)} s` : (err?.cause?.code || err?.message || "unreachable");
49
+ throw new StudioError(`Lazycow Studio is not answering at ${base} (${why}). Start it (double-click Start Lazycow, or npm run review) and try again.`, { path });
50
+ }
51
+ const text = await res.text();
52
+ let data = text;
53
+ if (/json/.test(res.headers.get("content-type") || "")) { try { data = JSON.parse(text); } catch { /* keep text */ } }
54
+ if (!res.ok) {
55
+ const why = (data && typeof data === "object" && data.error) || String(text).trim().slice(0, 300) || `HTTP ${res.status}`;
56
+ const hint = res.status === 401 ? " Set STUDIO_API_TOKEN (or pass token) to the studio's API token." : "";
57
+ throw new StudioError(`The studio said: ${why} (HTTP ${res.status} on ${method} ${path}).${hint}`, { status: res.status, path, body: data });
58
+ }
59
+ return data;
60
+ }
61
+
62
+ return {
63
+ base,
64
+ request,
65
+ get: (path) => request("GET", path),
66
+ post: (path, body = {}) => request("POST", path, body),
67
+ /** Is it running, which version, is the machine ready. */
68
+ health: () => request("GET", "/api/health"),
69
+ /** Name, version, licence, attribution and support links. */
70
+ about: () => request("GET", "/api/about"),
71
+ /** The open project's dashboard: reels, bookings, problems. */
72
+ overview: () => request("GET", "/api/overview"),
73
+ /** Booked and posted posts. */
74
+ posts: () => request("GET", "/api/posts"),
75
+ /** Story themes the studio can make reels from. */
76
+ themes: () => request("GET", "/api/themes"),
77
+ /** Projects on this computer and the open one. */
78
+ projects: () => request("GET", "/api/workspaces"),
79
+ /** Things that went wrong and need a person (missed posts, unapproved bookings). */
80
+ problems: () => request("GET", "/api/problems"),
81
+ };
82
+ }
83
+
84
+ export default createClient;
package/lib/env.mjs ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * FILE: packages/lazycow/lib/env.mjs
3
+ * PURPOSE: Find the Lazycow Studio on this computer: its folder, its port and its optional API token.
4
+ * OVERVIEW: The studio keeps STUDIO_PORT and STUDIO_API_TOKEN in the .env file in its own folder. That folder is
5
+ * LAZYCOW_DIR when set, else the one the double-click setup recorded in installed.json. Environment
6
+ * variables win over the file, so a config can still point anywhere.
7
+ * DEPENDENCIES: node:fs, node:os, node:path
8
+ * Part of Lazycow Studio by kensaurus (https://kensaur.us). Apache-2.0.
9
+ */
10
+ import { readFileSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { join } from "node:path";
13
+
14
+ /** Where the double-click setup keeps its runtimes and installed.json. */
15
+ export function setupHome() {
16
+ if (process.platform === "win32") return join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "Lazycow");
17
+ if (process.platform === "darwin") return join(homedir(), "Library", "Application Support", "Lazycow");
18
+ return join(homedir(), ".local", "share", "lazycow");
19
+ }
20
+
21
+ /** The studio folder this computer knows about, or "" when none. */
22
+ export function studioDir() {
23
+ if (process.env.LAZYCOW_DIR) return process.env.LAZYCOW_DIR;
24
+ try { return JSON.parse(readFileSync(join(setupHome(), "installed.json"), "utf8")).root || ""; } catch { return ""; }
25
+ }
26
+
27
+ function readEnv(dir) {
28
+ if (!dir) return "";
29
+ try { return readFileSync(join(dir, ".env"), "utf8"); } catch { return ""; }
30
+ }
31
+
32
+ /** One value from the studio's .env ("" when absent). */
33
+ export function envValue(text, key) {
34
+ const m = new RegExp(`^${key}\\s*=\\s*["']?([^"'\\r\\n]*)`, "m").exec(text || "");
35
+ return (m?.[1] || "").trim();
36
+ }
37
+
38
+ /** { base, port, token, dir } for the studio on this computer. Options override everything. */
39
+ export function studioTarget(opts = {}) {
40
+ const dir = opts.dir ?? studioDir();
41
+ const text = readEnv(dir);
42
+ const rawPort = String(opts.port ?? (process.env.STUDIO_PORT || envValue(text, "STUDIO_PORT")));
43
+ const port = /^\d{1,5}$/.test(rawPort) && Number(rawPort) > 0 && Number(rawPort) < 65536 ? Number(rawPort) : 4317;
44
+ const base = (opts.base || `http://127.0.0.1:${port}`).replace(/\/+$/, "");
45
+ const token = String(opts.token ?? process.env.STUDIO_API_TOKEN ?? envValue(text, "STUDIO_API_TOKEN") ?? "").trim();
46
+ return { base, port, token, dir };
47
+ }