getagenthook 0.1.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 +201 -0
- package/README.md +30 -0
- package/dist/args.js +61 -0
- package/dist/cli.js +65 -0
- package/dist/commands/balance.js +24 -0
- package/dist/commands/history.js +35 -0
- package/dist/commands/list.js +49 -0
- package/dist/commands/login.js +82 -0
- package/dist/commands/run.js +121 -0
- package/dist/commands/tools.js +52 -0
- package/dist/config.js +78 -0
- package/dist/http.js +80 -0
- package/dist/main.js +10 -0
- package/dist/render.js +13 -0
- package/dist/schema-snapshot.js +59 -0
- package/dist/schemas.js +96 -0
- package/dist/types.js +8 -0
- package/dist/validate.js +149 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# agenthook
|
|
2
|
+
|
|
3
|
+
CLI for the AgentHook hosted media-generation API. Built for agents:
|
|
4
|
+
progress goes to stderr, output URLs go to stdout, exit codes are meaningful.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm i -g getagenthook # or: npx getagenthook <command>
|
|
8
|
+
|
|
9
|
+
agenthook login --key <your-api-key>
|
|
10
|
+
agenthook tools
|
|
11
|
+
agenthook run make_video --prompt "A barista holds a latte and says: try our new oat flat white" --quality pro --aspect-ratio 9:16 --captions
|
|
12
|
+
agenthook run make_image --prompt "studio shot of a ceramic mug" --count 2
|
|
13
|
+
agenthook run caption_video --video-url https://…/video.mp4 --style tiktok
|
|
14
|
+
agenthook list --search "flat white"
|
|
15
|
+
agenthook balance
|
|
16
|
+
agenthook history
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Credentials live at `~/.agenthook/credentials.json` (chmod 600).
|
|
20
|
+
- API base: `--api-url` flag > `AGENTHOOK_API_URL` env > stored value >
|
|
21
|
+
`https://localhost:3000`; all requests hit `<base>/api/v1/…`.
|
|
22
|
+
- Reference images (`--ref`, repeatable) require `--owns-references`: you attest
|
|
23
|
+
you own, or have the rights to use, the likeness of every person appearing in
|
|
24
|
+
the referenced images.
|
|
25
|
+
- Everything deterministically checkable is validated locally against the
|
|
26
|
+
schemas served by `GET /v1/tools` (cached 1h) **before** any run is
|
|
27
|
+
submitted: consent, prompt length caps, enum values, ranges, and
|
|
28
|
+
`nano-banana-2` (edit-only) without references.
|
|
29
|
+
|
|
30
|
+
Develop: `npm run build` (emits `dist/`), `npx vitest run`, `npx tsc --noEmit`.
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Tiny argv parser — no dependency needed for six commands.
|
|
3
|
+
// Supports: --flag value, --flag=value, boolean flags, repeatable flags
|
|
4
|
+
// ("array" type), numeric coercion, and unknown-flag rejection.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseArgs = parseArgs;
|
|
7
|
+
function parseArgs(argv, spec) {
|
|
8
|
+
const out = { positionals: [], flags: {}, errors: [] };
|
|
9
|
+
for (let i = 0; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (!arg.startsWith("--")) {
|
|
12
|
+
out.positionals.push(arg);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
let name = arg.slice(2);
|
|
16
|
+
let inline;
|
|
17
|
+
const eq = name.indexOf("=");
|
|
18
|
+
if (eq !== -1) {
|
|
19
|
+
inline = name.slice(eq + 1);
|
|
20
|
+
name = name.slice(0, eq);
|
|
21
|
+
}
|
|
22
|
+
const type = spec[name];
|
|
23
|
+
if (!type) {
|
|
24
|
+
out.errors.push(`unknown flag --${name}`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (type === "boolean") {
|
|
28
|
+
if (inline !== undefined)
|
|
29
|
+
out.errors.push(`--${name} does not take a value`);
|
|
30
|
+
else
|
|
31
|
+
out.flags[name] = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
let value = inline;
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
const next = argv[i + 1];
|
|
37
|
+
if (next === undefined || next.startsWith("--")) {
|
|
38
|
+
out.errors.push(`--${name} requires a value`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
value = next;
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
44
|
+
if (type === "number") {
|
|
45
|
+
const n = Number(value);
|
|
46
|
+
if (!Number.isFinite(n))
|
|
47
|
+
out.errors.push(`--${name} expects a number, got "${value}"`);
|
|
48
|
+
else
|
|
49
|
+
out.flags[name] = n;
|
|
50
|
+
}
|
|
51
|
+
else if (type === "array") {
|
|
52
|
+
const prev = out.flags[name] ?? [];
|
|
53
|
+
prev.push(value);
|
|
54
|
+
out.flags[name] = prev;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
out.flags[name] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCli = runCli;
|
|
4
|
+
const balance_1 = require("./commands/balance");
|
|
5
|
+
const history_1 = require("./commands/history");
|
|
6
|
+
const list_1 = require("./commands/list");
|
|
7
|
+
const login_1 = require("./commands/login");
|
|
8
|
+
const run_1 = require("./commands/run");
|
|
9
|
+
const tools_1 = require("./commands/tools");
|
|
10
|
+
const http_1 = require("./http");
|
|
11
|
+
const USAGE = `agenthook — hosted media generation for agents
|
|
12
|
+
|
|
13
|
+
Usage: agenthook <command> [flags]
|
|
14
|
+
|
|
15
|
+
Commands:
|
|
16
|
+
login [--key <key>] store your API key (chmod 600)
|
|
17
|
+
tools list tools + parameters (from GET /v1/tools)
|
|
18
|
+
run <tool> [flags] submit a run, poll every 5s, print output URL(s)
|
|
19
|
+
list [--tool t] [--status s] [--search q] your past generations
|
|
20
|
+
balance credit balance
|
|
21
|
+
history credit ledger
|
|
22
|
+
|
|
23
|
+
Run flags:
|
|
24
|
+
--prompt <text> --ref <url> (repeatable) --owns-references --model <m>
|
|
25
|
+
--quality <standard|pro> --duration <s> --aspect-ratio <r> --no-audio
|
|
26
|
+
--captions --caption-style <movie|tiktok> --enhance-prompt
|
|
27
|
+
--video-url <url> --style <movie|tiktok> --count <n> --resolution <1k|2k|4k>
|
|
28
|
+
|
|
29
|
+
Every command accepts --api-url <url> (or AGENTHOOK_API_URL; default https://getagenthook.com).`;
|
|
30
|
+
async function runCli(argv) {
|
|
31
|
+
const [cmd, ...rest] = argv;
|
|
32
|
+
try {
|
|
33
|
+
switch (cmd) {
|
|
34
|
+
case "login":
|
|
35
|
+
return await (0, login_1.login)(rest);
|
|
36
|
+
case "tools":
|
|
37
|
+
return await (0, tools_1.tools)(rest);
|
|
38
|
+
case "run":
|
|
39
|
+
return await (0, run_1.run)(rest);
|
|
40
|
+
case "list":
|
|
41
|
+
return await (0, list_1.list)(rest);
|
|
42
|
+
case "balance":
|
|
43
|
+
return await (0, balance_1.balance)(rest);
|
|
44
|
+
case "history":
|
|
45
|
+
return await (0, history_1.history)(rest);
|
|
46
|
+
case undefined:
|
|
47
|
+
case "help":
|
|
48
|
+
case "--help":
|
|
49
|
+
case "-h":
|
|
50
|
+
console.log(USAGE);
|
|
51
|
+
return cmd === undefined ? 1 : 0;
|
|
52
|
+
default:
|
|
53
|
+
console.error(`Unknown command "${cmd}".\n\n${USAGE}`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (e instanceof http_1.ApiError) {
|
|
59
|
+
console.error((0, http_1.describeApiError)(e));
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.balance = balance;
|
|
4
|
+
const args_1 = require("../args");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
async function balance(argv) {
|
|
8
|
+
const { flags, errors } = (0, args_1.parseArgs)(argv, { "api-url": "string" });
|
|
9
|
+
if (errors.length) {
|
|
10
|
+
errors.forEach((e) => console.error(e));
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
const key = (0, config_1.storedApiKey)();
|
|
14
|
+
if (!key) {
|
|
15
|
+
console.error("Not logged in — run `agenthook login` first.");
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
const me = await (0, http_1.api)((0, config_1.resolveApiUrl)(flags["api-url"]), "/me", { key });
|
|
19
|
+
console.log(`User: ${me.user_id}`);
|
|
20
|
+
console.log(`Balance: ${me.balance} credits`);
|
|
21
|
+
if (me.suspended)
|
|
22
|
+
console.error("Account suspended — new runs are refused.");
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.history = history;
|
|
4
|
+
const args_1 = require("../args");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
const render_1 = require("../render");
|
|
8
|
+
async function history(argv) {
|
|
9
|
+
const { flags, errors } = (0, args_1.parseArgs)(argv, { "api-url": "string" });
|
|
10
|
+
if (errors.length) {
|
|
11
|
+
errors.forEach((e) => console.error(e));
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
const key = (0, config_1.storedApiKey)();
|
|
15
|
+
if (!key) {
|
|
16
|
+
console.error("Not logged in — run `agenthook login` first.");
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
const apiUrl = (0, config_1.resolveApiUrl)(flags["api-url"]);
|
|
20
|
+
const res = await (0, http_1.api)(apiUrl, "/credits/history", { key });
|
|
21
|
+
if (res.entries.length === 0) {
|
|
22
|
+
console.log("No credit activity yet.");
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const rows = res.entries.map((e) => [
|
|
26
|
+
e.created_at,
|
|
27
|
+
e.reason,
|
|
28
|
+
e.delta > 0 ? `+${e.delta}` : String(e.delta),
|
|
29
|
+
e.run_id ?? "-",
|
|
30
|
+
]);
|
|
31
|
+
console.log((0, render_1.table)(["CREATED", "REASON", "DELTA", "RUN"], rows));
|
|
32
|
+
}
|
|
33
|
+
console.log(`Balance: ${res.balance} credits`);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.list = list;
|
|
4
|
+
const args_1 = require("../args");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
const render_1 = require("../render");
|
|
8
|
+
async function list(argv) {
|
|
9
|
+
const { flags, errors } = (0, args_1.parseArgs)(argv, {
|
|
10
|
+
"api-url": "string",
|
|
11
|
+
tool: "string",
|
|
12
|
+
status: "string",
|
|
13
|
+
search: "string",
|
|
14
|
+
});
|
|
15
|
+
if (errors.length) {
|
|
16
|
+
errors.forEach((e) => console.error(e));
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
const apiUrl = (0, config_1.resolveApiUrl)(flags["api-url"]);
|
|
20
|
+
const key = (0, config_1.storedApiKey)();
|
|
21
|
+
if (!key) {
|
|
22
|
+
console.error("Not logged in — run `agenthook login` first.");
|
|
23
|
+
return 1;
|
|
24
|
+
}
|
|
25
|
+
const res = await (0, http_1.api)(apiUrl, "/generations", {
|
|
26
|
+
key,
|
|
27
|
+
query: {
|
|
28
|
+
tool: flags["tool"],
|
|
29
|
+
status: flags["status"],
|
|
30
|
+
q: flags["search"],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (res.runs.length === 0) {
|
|
34
|
+
console.log("No generations found.");
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
const rows = res.runs.map((r) => [
|
|
38
|
+
r.id,
|
|
39
|
+
r.tool,
|
|
40
|
+
r.status,
|
|
41
|
+
r.created_at,
|
|
42
|
+
String(r.credits_charged),
|
|
43
|
+
r.output[0] ?? (r.error ? (0, render_1.truncate)(r.error, 40) : (0, render_1.truncate)(r.prompt ?? "", 40)),
|
|
44
|
+
]);
|
|
45
|
+
console.log((0, render_1.table)(["ID", "TOOL", "STATUS", "CREATED", "CREDITS", "OUTPUT"], rows));
|
|
46
|
+
if (res.next_cursor)
|
|
47
|
+
console.error("(more results available — narrow with --tool/--status/--search)");
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.login = login;
|
|
37
|
+
const readline = __importStar(require("node:readline/promises"));
|
|
38
|
+
const args_1 = require("../args");
|
|
39
|
+
const config_1 = require("../config");
|
|
40
|
+
const http_1 = require("../http");
|
|
41
|
+
async function login(argv) {
|
|
42
|
+
const { flags, errors } = (0, args_1.parseArgs)(argv, { key: "string", "api-url": "string" });
|
|
43
|
+
if (errors.length) {
|
|
44
|
+
errors.forEach((e) => console.error(e));
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
let key = flags["key"];
|
|
48
|
+
if (!key) {
|
|
49
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
50
|
+
key = (await rl.question("API key: ")).trim();
|
|
51
|
+
rl.close();
|
|
52
|
+
}
|
|
53
|
+
if (!key) {
|
|
54
|
+
console.error("No API key provided.");
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
const apiUrlFlag = flags["api-url"];
|
|
58
|
+
const apiUrl = (0, config_1.resolveApiUrl)(apiUrlFlag);
|
|
59
|
+
const creds = {
|
|
60
|
+
...(0, config_1.loadCredentials)(),
|
|
61
|
+
api_key: key,
|
|
62
|
+
...(apiUrlFlag ? { api_url: apiUrl } : {}),
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
const me = await (0, http_1.api)(apiUrl, "/me", { key });
|
|
66
|
+
const p = (0, config_1.saveCredentials)(creds);
|
|
67
|
+
console.log(`Logged in as ${me.user_id} (balance: ${me.balance} credits).`);
|
|
68
|
+
console.log(`Credentials saved to ${p}`);
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
if (e instanceof http_1.ApiError && (e.status === 401 || e.status === 403)) {
|
|
73
|
+
console.error(`That API key was rejected by ${apiUrl} — nothing saved.`);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
// API unreachable: save anyway (key may be fine), but say so.
|
|
77
|
+
const p = (0, config_1.saveCredentials)(creds);
|
|
78
|
+
console.error(`Could not verify the key against ${apiUrl} (${e.message}).`);
|
|
79
|
+
console.error(`Saved to ${p} anyway — verify later with \`agenthook balance\`.`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = run;
|
|
4
|
+
const args_1 = require("../args");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
const schemas_1 = require("../schemas");
|
|
8
|
+
const validate_1 = require("../validate");
|
|
9
|
+
const RUN_FLAGS = {
|
|
10
|
+
"api-url": "string",
|
|
11
|
+
prompt: "string",
|
|
12
|
+
ref: "array",
|
|
13
|
+
"owns-references": "boolean",
|
|
14
|
+
model: "string",
|
|
15
|
+
quality: "string",
|
|
16
|
+
duration: "number",
|
|
17
|
+
"aspect-ratio": "string",
|
|
18
|
+
"no-audio": "boolean",
|
|
19
|
+
captions: "boolean",
|
|
20
|
+
"caption-style": "string",
|
|
21
|
+
"enhance-prompt": "boolean",
|
|
22
|
+
"video-url": "string",
|
|
23
|
+
style: "string",
|
|
24
|
+
count: "number",
|
|
25
|
+
resolution: "string",
|
|
26
|
+
language: "string",
|
|
27
|
+
};
|
|
28
|
+
// Poll cadence: 5s (spec); overridable for tests. Every watcher gets a
|
|
29
|
+
// give-up (donor rule): a wall-clock deadline + bounded consecutive misses.
|
|
30
|
+
const pollIntervalMs = () => Number(process.env.AGENTHOOK_POLL_MS || 5000);
|
|
31
|
+
const POLL_DEADLINE_MS = 60 * 60 * 1000; // the server sweep fails stuck runs at 45min; we outlast it
|
|
32
|
+
const MAX_POLL_MISSES = 5;
|
|
33
|
+
async function run(argv) {
|
|
34
|
+
const { positionals, flags, errors } = (0, args_1.parseArgs)(argv, RUN_FLAGS);
|
|
35
|
+
if (errors.length) {
|
|
36
|
+
errors.forEach((e) => console.error(e));
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
const tool = positionals[0];
|
|
40
|
+
if (!tool) {
|
|
41
|
+
console.error("Usage: agenthook run <tool> [flags] — see `agenthook tools`");
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
const apiUrl = (0, config_1.resolveApiUrl)(flags["api-url"]);
|
|
45
|
+
const key = (0, config_1.storedApiKey)();
|
|
46
|
+
if (!key) {
|
|
47
|
+
console.error("Not logged in — run `agenthook login` first.");
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
// Deterministic pre-validation BEFORE any network call (spec §3) — schemas
|
|
51
|
+
// resolve locally in every case: cached /v1/tools fetch if one exists,
|
|
52
|
+
// otherwise the bundled snapshot (fresh install, offline). The server
|
|
53
|
+
// re-validates authoritatively on submit.
|
|
54
|
+
const schemas = (0, schemas_1.getLocalToolSchemas)(apiUrl);
|
|
55
|
+
const input = (0, validate_1.buildToolInput)(flags);
|
|
56
|
+
const problems = (0, validate_1.preValidate)(tool, input, schemas);
|
|
57
|
+
if (problems.length) {
|
|
58
|
+
problems.forEach((p) => console.error(p));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
// Submit.
|
|
62
|
+
let created;
|
|
63
|
+
try {
|
|
64
|
+
created = await (0, http_1.api)(apiUrl, `/tools/${encodeURIComponent(tool)}/run`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
key,
|
|
67
|
+
body: input,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof http_1.ApiError) {
|
|
72
|
+
console.error((0, http_1.describeApiError)(e));
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
console.error(`Run ${created.run_id} submitted (${created.credits_charged} credits). Polling…`);
|
|
78
|
+
// Poll until terminal. Progress goes to stderr; output URLs alone go to
|
|
79
|
+
// stdout so agents/scripts can capture them cleanly.
|
|
80
|
+
const deadline = Date.now() + POLL_DEADLINE_MS;
|
|
81
|
+
let lastStatus = created.status;
|
|
82
|
+
let misses = 0;
|
|
83
|
+
while (Date.now() < deadline) {
|
|
84
|
+
await sleep(pollIntervalMs());
|
|
85
|
+
let runRow;
|
|
86
|
+
try {
|
|
87
|
+
runRow = await (0, http_1.api)(apiUrl, `/runs/${encodeURIComponent(created.run_id)}`, { key });
|
|
88
|
+
misses = 0;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
if (e instanceof http_1.ApiError && e.status === 404) {
|
|
92
|
+
console.error(`Run ${created.run_id} no longer exists (404).`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
misses++;
|
|
96
|
+
if (misses >= MAX_POLL_MISSES) {
|
|
97
|
+
console.error(`Lost contact with the API (${MAX_POLL_MISSES} consecutive failures: ${e.message}).\n` +
|
|
98
|
+
`The run may still finish — check later with: agenthook list`);
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (runRow.status !== lastStatus) {
|
|
104
|
+
console.error(`Status: ${runRow.status}`);
|
|
105
|
+
lastStatus = runRow.status;
|
|
106
|
+
}
|
|
107
|
+
if (runRow.status === "completed") {
|
|
108
|
+
for (const url of runRow.output)
|
|
109
|
+
console.log(url);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
if (runRow.status === "failed") {
|
|
113
|
+
console.error(`Run failed: ${runRow.error ?? "unknown error"} (credits are refunded automatically)`);
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
console.error(`Run ${created.run_id} did not finish within ${POLL_DEADLINE_MS / 60_000} minutes — ` +
|
|
118
|
+
`giving up on polling. Check later with: agenthook list`);
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tools = tools;
|
|
4
|
+
const args_1 = require("../args");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const schemas_1 = require("../schemas");
|
|
7
|
+
const validate_1 = require("../validate");
|
|
8
|
+
async function tools(argv) {
|
|
9
|
+
const { flags, errors } = (0, args_1.parseArgs)(argv, { "api-url": "string" });
|
|
10
|
+
if (errors.length) {
|
|
11
|
+
errors.forEach((e) => console.error(e));
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
const apiUrl = (0, config_1.resolveApiUrl)(flags["api-url"]);
|
|
15
|
+
// Always fetch fresh (and warm the cache `run` pre-validates from).
|
|
16
|
+
const schemas = await (0, schemas_1.getToolSchemas)(apiUrl, (0, config_1.storedApiKey)(), { fresh: true });
|
|
17
|
+
for (const tool of schemas) {
|
|
18
|
+
console.log(`${tool.name} — ${tool.description}`);
|
|
19
|
+
for (const [name, spec] of Object.entries(tool.params)) {
|
|
20
|
+
console.log(` ${renderParam(name, spec)}`);
|
|
21
|
+
}
|
|
22
|
+
console.log("");
|
|
23
|
+
}
|
|
24
|
+
console.log(`Run one with: agenthook run <tool> --prompt "..." [flags]`);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
function renderParam(name, spec) {
|
|
28
|
+
const flagName = validate_1.FLAG_FOR[name] ?? `--${name.replace(/_/g, "-")}`;
|
|
29
|
+
const hint = spec.type === "boolean"
|
|
30
|
+
? ""
|
|
31
|
+
: spec.enum
|
|
32
|
+
? ` <${spec.enum.join("|")}>`
|
|
33
|
+
: spec.type === "array"
|
|
34
|
+
? " <url>"
|
|
35
|
+
: spec.type === "number"
|
|
36
|
+
? " <n>"
|
|
37
|
+
: " <text>";
|
|
38
|
+
const attrs = [];
|
|
39
|
+
if (spec.required)
|
|
40
|
+
attrs.push("required");
|
|
41
|
+
if (name === "audio")
|
|
42
|
+
attrs.push("passing it disables audio (default on)");
|
|
43
|
+
else if (spec.default !== undefined)
|
|
44
|
+
attrs.push(`default ${JSON.stringify(spec.default)}`);
|
|
45
|
+
if (spec.type === "array")
|
|
46
|
+
attrs.push(`repeatable${spec.max !== undefined ? `, up to ${spec.max}` : ""}`);
|
|
47
|
+
if (spec.maxLength !== undefined)
|
|
48
|
+
attrs.push(`max ${spec.maxLength} chars`);
|
|
49
|
+
if (spec.description)
|
|
50
|
+
attrs.push(spec.description);
|
|
51
|
+
return `${(flagName + hint).padEnd(34)}${attrs.join("; ")}`;
|
|
52
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_API_URL = exports.BASE_PATH = void 0;
|
|
37
|
+
exports.configDir = configDir;
|
|
38
|
+
exports.credentialsPath = credentialsPath;
|
|
39
|
+
exports.loadCredentials = loadCredentials;
|
|
40
|
+
exports.saveCredentials = saveCredentials;
|
|
41
|
+
exports.resolveApiUrl = resolveApiUrl;
|
|
42
|
+
exports.storedApiKey = storedApiKey;
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const os = __importStar(require("node:os"));
|
|
45
|
+
const path = __importStar(require("node:path"));
|
|
46
|
+
exports.BASE_PATH = "/api/v1";
|
|
47
|
+
exports.DEFAULT_API_URL = "https://getagenthook.com";
|
|
48
|
+
/** Config home — overridable for tests via AGENTHOOK_CONFIG_DIR. */
|
|
49
|
+
function configDir() {
|
|
50
|
+
return process.env.AGENTHOOK_CONFIG_DIR || path.join(os.homedir(), ".agenthook");
|
|
51
|
+
}
|
|
52
|
+
function credentialsPath() {
|
|
53
|
+
return path.join(configDir(), "credentials.json");
|
|
54
|
+
}
|
|
55
|
+
function loadCredentials() {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(fs.readFileSync(credentialsPath(), "utf8"));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Writes credentials with owner-only permissions (dir 700, file 600). */
|
|
64
|
+
function saveCredentials(creds) {
|
|
65
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
66
|
+
const p = credentialsPath();
|
|
67
|
+
fs.writeFileSync(p, JSON.stringify(creds, null, 2) + "\n", { mode: 0o600 });
|
|
68
|
+
fs.chmodSync(p, 0o600); // writeFileSync's mode is ignored when the file already exists
|
|
69
|
+
return p;
|
|
70
|
+
}
|
|
71
|
+
/** Resolution order: --api-url flag > AGENTHOOK_API_URL > stored > default. */
|
|
72
|
+
function resolveApiUrl(flagValue) {
|
|
73
|
+
const url = flagValue || process.env.AGENTHOOK_API_URL || loadCredentials().api_url || exports.DEFAULT_API_URL;
|
|
74
|
+
return url.replace(/\/+$/, "");
|
|
75
|
+
}
|
|
76
|
+
function storedApiKey() {
|
|
77
|
+
return loadCredentials().api_key;
|
|
78
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiError = exports.DEFAULT_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.timeoutSignal = timeoutSignal;
|
|
5
|
+
exports.api = api;
|
|
6
|
+
exports.describeApiError = describeApiError;
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
// Timeout policy mirrors the frozen packages/core/net.ts (DEFAULT_TIMEOUT_MS +
|
|
9
|
+
// AbortSignal.timeout). Duplicated here because the published CLI cannot
|
|
10
|
+
// runtime-import workspace TypeScript; test/parity.test.ts pins the value.
|
|
11
|
+
exports.DEFAULT_TIMEOUT_MS = 30_000;
|
|
12
|
+
function timeoutSignal(ms = exports.DEFAULT_TIMEOUT_MS) {
|
|
13
|
+
return AbortSignal.timeout(ms);
|
|
14
|
+
}
|
|
15
|
+
class ApiError extends Error {
|
|
16
|
+
status;
|
|
17
|
+
code;
|
|
18
|
+
details;
|
|
19
|
+
retryAfter;
|
|
20
|
+
constructor(message, status, // 0 = network/timeout, no HTTP response
|
|
21
|
+
code, details, retryAfter) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.status = status;
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.details = details;
|
|
26
|
+
this.retryAfter = retryAfter;
|
|
27
|
+
this.name = "ApiError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ApiError = ApiError;
|
|
31
|
+
/** Bounded JSON request against <apiUrl>/api/v1<pathname>. Checks res.ok
|
|
32
|
+
* before res.json() (donor rule) and normalizes every failure to ApiError. */
|
|
33
|
+
async function api(apiUrl, pathname, opts = {}) {
|
|
34
|
+
const url = new URL(apiUrl + config_1.BASE_PATH + pathname);
|
|
35
|
+
for (const [k, v] of Object.entries(opts.query ?? {})) {
|
|
36
|
+
if (v !== undefined && v !== "")
|
|
37
|
+
url.searchParams.set(k, v);
|
|
38
|
+
}
|
|
39
|
+
const headers = {};
|
|
40
|
+
if (opts.key)
|
|
41
|
+
headers.authorization = `Bearer ${opts.key}`;
|
|
42
|
+
if (opts.body !== undefined)
|
|
43
|
+
headers["content-type"] = "application/json";
|
|
44
|
+
let res;
|
|
45
|
+
try {
|
|
46
|
+
res = await fetch(url, {
|
|
47
|
+
method: opts.method ?? "GET",
|
|
48
|
+
headers,
|
|
49
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
50
|
+
signal: timeoutSignal(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
throw new ApiError(`request to ${url.host} failed: ${e.message}`, 0);
|
|
55
|
+
}
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
let body;
|
|
58
|
+
try {
|
|
59
|
+
body = (await res.json());
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// non-JSON error body — fall through to the status line
|
|
63
|
+
}
|
|
64
|
+
throw new ApiError(body?.error ?? `HTTP ${res.status} ${res.statusText}`, res.status, body?.code, body?.details, body?.retry_after);
|
|
65
|
+
}
|
|
66
|
+
return (await res.json());
|
|
67
|
+
}
|
|
68
|
+
/** Human rendering for ApiError — validation details, login/429 hints. */
|
|
69
|
+
function describeApiError(e) {
|
|
70
|
+
const lines = [e.message];
|
|
71
|
+
for (const d of e.details ?? [])
|
|
72
|
+
lines.push(` ${d.path}: ${d.message}`);
|
|
73
|
+
if (e.status === 401)
|
|
74
|
+
lines.push(" Run `agenthook login` with a valid API key.");
|
|
75
|
+
if (e.status === 402)
|
|
76
|
+
lines.push(" Not enough credits — check `agenthook balance`.");
|
|
77
|
+
if (e.status === 429)
|
|
78
|
+
lines.push(` Rate limited — retry in ${e.retryAfter ?? "a few"}s.`);
|
|
79
|
+
return lines.join("\n");
|
|
80
|
+
}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const cli_1 = require("./cli");
|
|
5
|
+
(0, cli_1.runCli)(process.argv.slice(2)).then((code) => {
|
|
6
|
+
process.exitCode = code;
|
|
7
|
+
}, (err) => {
|
|
8
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
});
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.table = table;
|
|
4
|
+
exports.truncate = truncate;
|
|
5
|
+
/** Plain-text table: padded columns, two-space gutter. */
|
|
6
|
+
function table(headers, rows) {
|
|
7
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
|
|
8
|
+
const line = (cells) => cells.map((c, i) => (c ?? "").padEnd(widths[i])).join(" ").trimEnd();
|
|
9
|
+
return [line(headers), ...rows.map(line)].join("\n");
|
|
10
|
+
}
|
|
11
|
+
function truncate(s, max) {
|
|
12
|
+
return s.length <= max ? s : s.slice(0, max - 1) + "…";
|
|
13
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TOOLS_SNAPSHOT = void 0;
|
|
4
|
+
exports.TOOLS_SNAPSHOT = [
|
|
5
|
+
{
|
|
6
|
+
name: "make_video",
|
|
7
|
+
description: "Generate a video (talking-head parity via Seedance native audio) from a prompt and optional reference images.",
|
|
8
|
+
params: {
|
|
9
|
+
prompt: { type: "string", required: true, maxLength: 4000 },
|
|
10
|
+
reference_images: { type: "array", items: { type: "string" }, max: 14 },
|
|
11
|
+
owns_references: {
|
|
12
|
+
type: "boolean",
|
|
13
|
+
description: "Required true when reference_images are attached (likeness consent).",
|
|
14
|
+
},
|
|
15
|
+
model: { type: "string", enum: ["seedance-2", "kling-3"], default: "seedance-2" },
|
|
16
|
+
quality: { type: "string", enum: ["standard", "pro"], default: "standard" },
|
|
17
|
+
duration: { type: "number", default: 5, min: 1 },
|
|
18
|
+
aspect_ratio: {
|
|
19
|
+
type: "string",
|
|
20
|
+
enum: ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"],
|
|
21
|
+
default: "9:16",
|
|
22
|
+
},
|
|
23
|
+
audio: { type: "boolean", default: true },
|
|
24
|
+
captions: { type: "boolean", default: false },
|
|
25
|
+
caption_style: { type: "string", enum: ["movie", "tiktok"], default: "tiktok" },
|
|
26
|
+
enhance_prompt: { type: "boolean", default: false },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "make_image",
|
|
31
|
+
description: "Generate or edit an image. With reference_images routes to Nano Banana 2 (RunPod); without, to GPT Image 2 (PiAPI).",
|
|
32
|
+
params: {
|
|
33
|
+
prompt: { type: "string", required: true },
|
|
34
|
+
reference_images: { type: "array", items: { type: "string" }, max: 14 },
|
|
35
|
+
owns_references: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
description: "Required true when reference_images are attached (likeness consent).",
|
|
38
|
+
},
|
|
39
|
+
model: { type: "string", enum: ["auto", "nano-banana-2", "gpt-image-2"], default: "auto" },
|
|
40
|
+
aspect_ratio: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "21:9"],
|
|
43
|
+
default: "9:16",
|
|
44
|
+
},
|
|
45
|
+
resolution: { type: "string", enum: ["1k", "2k", "4k"], default: "1k" },
|
|
46
|
+
count: { type: "number", default: 1, min: 1, max: 4 },
|
|
47
|
+
enhance_prompt: { type: "boolean", default: false },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "caption_video",
|
|
52
|
+
description: "Burn styled subtitles into an existing video.",
|
|
53
|
+
params: {
|
|
54
|
+
video_url: { type: "string", required: true },
|
|
55
|
+
style: { type: "string", enum: ["movie", "tiktok"], default: "movie" },
|
|
56
|
+
language: { type: "string", default: "auto" },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.TOOLS_CACHE_TTL_MS = void 0;
|
|
37
|
+
exports.toolsCachePath = toolsCachePath;
|
|
38
|
+
exports.getLocalToolSchemas = getLocalToolSchemas;
|
|
39
|
+
exports.getToolSchemas = getToolSchemas;
|
|
40
|
+
// Tool-schema source for deterministic pre-validation: GET /v1/tools is the
|
|
41
|
+
// single live schema source (the `tools` command fetches + caches it), and
|
|
42
|
+
// `run` validates against a purely LOCAL resolution — fetched cache if
|
|
43
|
+
// present, else the bundled snapshot — so pre-validation never makes a
|
|
44
|
+
// network call, including on a fresh install (spec §3).
|
|
45
|
+
const fs = __importStar(require("node:fs"));
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
const config_1 = require("./config");
|
|
48
|
+
const http_1 = require("./http");
|
|
49
|
+
const schema_snapshot_1 = require("./schema-snapshot");
|
|
50
|
+
exports.TOOLS_CACHE_TTL_MS = 60 * 60 * 1000; // 1h — schemas change on deploy, not per run
|
|
51
|
+
function toolsCachePath() {
|
|
52
|
+
return path.join((0, config_1.configDir)(), "tools-cache.json");
|
|
53
|
+
}
|
|
54
|
+
function readCache() {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(fs.readFileSync(toolsCachePath(), "utf8"));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function writeCache(cache) {
|
|
63
|
+
fs.mkdirSync((0, config_1.configDir)(), { recursive: true, mode: 0o700 });
|
|
64
|
+
fs.writeFileSync(toolsCachePath(), JSON.stringify(cache, null, 2) + "\n");
|
|
65
|
+
}
|
|
66
|
+
/** Local-only schema resolution for `run` pre-validation — NEVER touches the
|
|
67
|
+
* network (spec §3: block locally before any network call, first invocation
|
|
68
|
+
* included). Order: any cached fetch of this api-url (fresh or stale — schemas
|
|
69
|
+
* change on deploy, not per run) → the bundled snapshot. The server re-checks
|
|
70
|
+
* everything authoritatively, so a stale local view only changes where a bad
|
|
71
|
+
* request is rejected, never whether. */
|
|
72
|
+
function getLocalToolSchemas(apiUrl) {
|
|
73
|
+
return readCache()[apiUrl]?.tools ?? schema_snapshot_1.TOOLS_SNAPSHOT;
|
|
74
|
+
}
|
|
75
|
+
/** Cached-first schema load. `fresh: true` (the `tools` command) always
|
|
76
|
+
* refetches; otherwise a fresh cache entry short-circuits the network, and a
|
|
77
|
+
* stale one is the fallback when the API is unreachable (the server re-checks
|
|
78
|
+
* everything authoritatively anyway). */
|
|
79
|
+
async function getToolSchemas(apiUrl, key, opts = {}) {
|
|
80
|
+
const cache = readCache();
|
|
81
|
+
const hit = cache[apiUrl];
|
|
82
|
+
if (!opts.fresh && hit && Date.now() - Date.parse(hit.fetched_at) < exports.TOOLS_CACHE_TTL_MS) {
|
|
83
|
+
return hit.tools;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const res = await (0, http_1.api)(apiUrl, "/tools", { key });
|
|
87
|
+
cache[apiUrl] = { fetched_at: new Date().toISOString(), tools: res.tools };
|
|
88
|
+
writeCache(cache);
|
|
89
|
+
return res.tools;
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
if (hit)
|
|
93
|
+
return hit.tools;
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Wire-contract types, mirroring the frozen packages/core/contract.ts.
|
|
3
|
+
//
|
|
4
|
+
// The CLI publishes standalone to npm and therefore cannot runtime-import
|
|
5
|
+
// workspace TypeScript, so these are type-only mirrors of the HTTP contract.
|
|
6
|
+
// test/parity.test.ts imports core (test-only, relative path) and pins the
|
|
7
|
+
// values that could drift.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FLAG_FOR = exports.OWNS_REFERENCES_CONSENT = exports.PROMPT_CAPS = void 0;
|
|
4
|
+
exports.buildToolInput = buildToolInput;
|
|
5
|
+
exports.preValidate = preValidate;
|
|
6
|
+
// Per-model prompt caps, mirroring packages/core/models.ts promptMax (frozen).
|
|
7
|
+
// GET /v1/tools only exposes the default model's cap on the prompt param, so
|
|
8
|
+
// the CLI keeps this map to pre-validate explicitly forced models.
|
|
9
|
+
// test/parity.test.ts pins these to core's registry.
|
|
10
|
+
exports.PROMPT_CAPS = {
|
|
11
|
+
"seedance-2": 4000,
|
|
12
|
+
"kling-3": 2500,
|
|
13
|
+
};
|
|
14
|
+
exports.OWNS_REFERENCES_CONSENT = "By passing --owns-references you attest that you own, or have the rights to use, " +
|
|
15
|
+
"the likeness of every person appearing in the referenced images.";
|
|
16
|
+
/** CLI flag spelling for each API param — for readable error messages.
|
|
17
|
+
* test/parity.test.ts asserts every param served by /v1/tools has an entry. */
|
|
18
|
+
exports.FLAG_FOR = {
|
|
19
|
+
prompt: "--prompt",
|
|
20
|
+
reference_images: "--ref",
|
|
21
|
+
owns_references: "--owns-references",
|
|
22
|
+
model: "--model",
|
|
23
|
+
quality: "--quality",
|
|
24
|
+
duration: "--duration",
|
|
25
|
+
aspect_ratio: "--aspect-ratio",
|
|
26
|
+
audio: "--no-audio",
|
|
27
|
+
captions: "--captions",
|
|
28
|
+
caption_style: "--caption-style",
|
|
29
|
+
enhance_prompt: "--enhance-prompt",
|
|
30
|
+
video_url: "--video-url",
|
|
31
|
+
style: "--style",
|
|
32
|
+
count: "--count",
|
|
33
|
+
resolution: "--resolution",
|
|
34
|
+
language: "--language",
|
|
35
|
+
};
|
|
36
|
+
/** Map parsed CLI flags onto the tool-input body the API expects. Only flags
|
|
37
|
+
* the user actually passed are included, so server defaults stay in charge. */
|
|
38
|
+
function buildToolInput(flags) {
|
|
39
|
+
const input = {};
|
|
40
|
+
const direct = [
|
|
41
|
+
["prompt", "prompt"],
|
|
42
|
+
["model", "model"],
|
|
43
|
+
["quality", "quality"],
|
|
44
|
+
["duration", "duration"],
|
|
45
|
+
["aspect-ratio", "aspect_ratio"],
|
|
46
|
+
["caption-style", "caption_style"],
|
|
47
|
+
["video-url", "video_url"],
|
|
48
|
+
["style", "style"],
|
|
49
|
+
["count", "count"],
|
|
50
|
+
["resolution", "resolution"],
|
|
51
|
+
["language", "language"],
|
|
52
|
+
];
|
|
53
|
+
for (const [flag, param] of direct) {
|
|
54
|
+
if (flags[flag] !== undefined)
|
|
55
|
+
input[param] = flags[flag];
|
|
56
|
+
}
|
|
57
|
+
const refs = flags["ref"];
|
|
58
|
+
if (refs?.length)
|
|
59
|
+
input.reference_images = refs;
|
|
60
|
+
if (flags["owns-references"])
|
|
61
|
+
input.owns_references = true;
|
|
62
|
+
if (flags["no-audio"])
|
|
63
|
+
input.audio = false;
|
|
64
|
+
if (flags["captions"])
|
|
65
|
+
input.captions = true;
|
|
66
|
+
if (flags["enhance-prompt"])
|
|
67
|
+
input.enhance_prompt = true;
|
|
68
|
+
return input;
|
|
69
|
+
}
|
|
70
|
+
const flag = (param) => exports.FLAG_FOR[param] ?? param;
|
|
71
|
+
/** Returns human-readable problems (empty array = locally valid). */
|
|
72
|
+
function preValidate(tool, input, schemas) {
|
|
73
|
+
const schema = schemas.find((s) => s.name === tool);
|
|
74
|
+
if (!schema) {
|
|
75
|
+
return [`Unknown tool "${tool}". Available tools: ${schemas.map((s) => s.name).join(", ")}`];
|
|
76
|
+
}
|
|
77
|
+
const errors = [];
|
|
78
|
+
// Flags that don't belong to this tool (e.g. --video-url on make_image).
|
|
79
|
+
for (const key of Object.keys(input)) {
|
|
80
|
+
if (!(key in schema.params))
|
|
81
|
+
errors.push(`${flag(key)} does not apply to ${tool}`);
|
|
82
|
+
}
|
|
83
|
+
// Required params.
|
|
84
|
+
for (const [name, spec] of Object.entries(schema.params)) {
|
|
85
|
+
if (spec.required && input[name] === undefined) {
|
|
86
|
+
errors.push(`${tool} requires ${flag(name)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Enum values, numeric ranges, array caps.
|
|
90
|
+
for (const [name, spec] of Object.entries(schema.params)) {
|
|
91
|
+
const value = input[name];
|
|
92
|
+
if (value === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
if (spec.enum && typeof value === "string" && !spec.enum.includes(value)) {
|
|
95
|
+
errors.push(`Invalid value "${value}" for ${flag(name)} — valid: ${spec.enum.join(", ")}`);
|
|
96
|
+
}
|
|
97
|
+
if (spec.type === "number" && typeof value === "number") {
|
|
98
|
+
if (!Number.isInteger(value))
|
|
99
|
+
errors.push(`${flag(name)} must be a whole number`);
|
|
100
|
+
if (spec.min !== undefined && value < spec.min)
|
|
101
|
+
errors.push(`${flag(name)} must be at least ${spec.min}`);
|
|
102
|
+
if (spec.max !== undefined && value > spec.max)
|
|
103
|
+
errors.push(`${flag(name)} must be at most ${spec.max}`);
|
|
104
|
+
}
|
|
105
|
+
if (spec.type === "array" && Array.isArray(value) && spec.max !== undefined && value.length > spec.max) {
|
|
106
|
+
errors.push(`At most ${spec.max} ${flag(name)} values are allowed (got ${value.length})`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const refs = input.reference_images;
|
|
110
|
+
const hasRefs = !!refs?.length;
|
|
111
|
+
// Likeness consent — refs require the explicit attestation.
|
|
112
|
+
if (hasRefs && input.owns_references !== true) {
|
|
113
|
+
errors.push("Reference images require the --owns-references attestation.\n" +
|
|
114
|
+
` ${exports.OWNS_REFERENCES_CONSENT}\n` +
|
|
115
|
+
" Fix: re-run the same command with --owns-references.");
|
|
116
|
+
}
|
|
117
|
+
// URL shape for refs and video input.
|
|
118
|
+
for (const r of refs ?? []) {
|
|
119
|
+
if (!isUrl(r))
|
|
120
|
+
errors.push(`--ref "${r}" is not a valid URL`);
|
|
121
|
+
}
|
|
122
|
+
if (typeof input.video_url === "string" && !isUrl(input.video_url)) {
|
|
123
|
+
errors.push(`--video-url "${input.video_url}" is not a valid URL`);
|
|
124
|
+
}
|
|
125
|
+
// Prompt cap for the effective model (explicit --model or the schema default).
|
|
126
|
+
if (typeof input.prompt === "string") {
|
|
127
|
+
const model = input.model ?? schema.params.model?.default;
|
|
128
|
+
const cap = (model !== undefined ? exports.PROMPT_CAPS[model] : undefined) ?? schema.params.prompt?.maxLength;
|
|
129
|
+
if (cap && input.prompt.length > cap) {
|
|
130
|
+
errors.push(`--prompt is ${input.prompt.length} characters; the ${model ?? tool} cap is ${cap}. Shorten the prompt.`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// NB2 (RunPod) is an edit endpoint — never callable without a reference.
|
|
134
|
+
if (tool === "make_image" && input.model === "nano-banana-2" && !hasRefs) {
|
|
135
|
+
errors.push("nano-banana-2 is an edit model and needs at least one reference image.\n" +
|
|
136
|
+
" Fix: add --ref <url> (with --owns-references), or drop --model to auto-route " +
|
|
137
|
+
"text-to-image to gpt-image-2.");
|
|
138
|
+
}
|
|
139
|
+
return errors;
|
|
140
|
+
}
|
|
141
|
+
function isUrl(s) {
|
|
142
|
+
try {
|
|
143
|
+
new URL(s);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "getagenthook",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for the AgentHook hosted media-generation API — generate video, images, and captions from your terminal or agent.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://getagenthook.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/AvivK5498/agenthook.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"ai",
|
|
13
|
+
"video-generation",
|
|
14
|
+
"image-generation",
|
|
15
|
+
"captions",
|
|
16
|
+
"agents",
|
|
17
|
+
"cli"
|
|
18
|
+
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"agenthook": "./dist/main.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"prepack": "npm run build",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.10.2",
|
|
36
|
+
"typescript": "^5.6.3",
|
|
37
|
+
"vitest": "^2.1.8"
|
|
38
|
+
}
|
|
39
|
+
}
|