@hanzo/build 0.2.119 → 0.2.121
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/lib/api/billing.d.ts +6 -0
- package/lib/api/billing.js +9 -0
- package/lib/api/draft.d.ts +6 -1
- package/lib/api/draft.js +12 -6
- package/lib/mind.js +3 -3
- package/package.json +1 -1
package/lib/api/billing.d.ts
CHANGED
|
@@ -134,6 +134,12 @@ export declare function invoices(t: Target): Promise<Invoice[]>;
|
|
|
134
134
|
export declare function pdf(t: Target, id: string): Promise<Blob>;
|
|
135
135
|
/** What the org can still spend from its prepaid balance, in cents. */
|
|
136
136
|
export declare function balance(t: Target): Promise<number>;
|
|
137
|
+
/**
|
|
138
|
+
* What can pay for another maker's models, whole cents: cash and the credit line, never
|
|
139
|
+
* granted credit (`GET /v1/billing/balance` `prepaid`). Null where the answer carries no
|
|
140
|
+
* such figure, so a caller does not assume it.
|
|
141
|
+
*/
|
|
142
|
+
export declare function prepaid(t: Target): Promise<number | null>;
|
|
137
143
|
/** Granted credit the org can spend, in US cents. */
|
|
138
144
|
export declare function credit(t: Target): Promise<number>;
|
|
139
145
|
/** One grant of credit, spent, lapsed and voided included: the ledger, not the spendable figure. */
|
package/lib/api/billing.js
CHANGED
|
@@ -252,6 +252,15 @@ export async function balance(t) {
|
|
|
252
252
|
const b = obj(await call(t, 'GET', '/v1/billing/balance'));
|
|
253
253
|
return num(b.available ?? b.balance);
|
|
254
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* What can pay for another maker's models, whole cents: cash and the credit line, never
|
|
257
|
+
* granted credit (`GET /v1/billing/balance` `prepaid`). Null where the answer carries no
|
|
258
|
+
* such figure, so a caller does not assume it.
|
|
259
|
+
*/
|
|
260
|
+
export async function prepaid(t) {
|
|
261
|
+
const b = obj(await call(t, 'GET', '/v1/billing/balance'));
|
|
262
|
+
return typeof b.prepaid === 'number' && Number.isFinite(b.prepaid) ? b.prepaid : null;
|
|
263
|
+
}
|
|
255
264
|
/** Granted credit the org can spend, in US cents. */
|
|
256
265
|
export async function credit(t) {
|
|
257
266
|
const raw = obj(await call(t, 'GET', '/v1/billing/credit-balance'));
|
package/lib/api/draft.d.ts
CHANGED
|
@@ -15,7 +15,12 @@ export interface Sketch {
|
|
|
15
15
|
export declare const SYSTEM: string;
|
|
16
16
|
/** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
|
|
17
17
|
export declare function parse(said: string): Sketch | null;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
|
|
20
|
+
* is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
|
|
21
|
+
*/
|
|
22
|
+
export declare const ROOM = 4000;
|
|
23
|
+
/** The line they typed, drafted; asked a second time when the first answer was not one. */
|
|
19
24
|
export declare function sketch(t: Target, line: string, signal?: AbortSignal): Promise<Sketch>;
|
|
20
25
|
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
21
26
|
export declare const saved: (s: Pick<Sketch, 'instructions' | 'opening'>) => string;
|
package/lib/api/draft.js
CHANGED
|
@@ -30,13 +30,19 @@ export function parse(said) {
|
|
|
30
30
|
return null;
|
|
31
31
|
return { name, role: word(o.role), instructions, opening: word(o.opening), emoji: word(o.emoji).slice(0, 8), figure: word(o.figure) };
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
|
|
35
|
+
* is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
|
|
36
|
+
*/
|
|
37
|
+
export const ROOM = 4000;
|
|
38
|
+
/** The line they typed, drafted; asked a second time when the first answer was not one. */
|
|
34
39
|
export async function sketch(t, line, signal) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
for (let tried = 0; tried < 2; tried++) {
|
|
41
|
+
const draft = parse(await ask(t, SYSTEM, line.trim(), signal, ROOM, ENSO));
|
|
42
|
+
if (draft)
|
|
43
|
+
return draft;
|
|
44
|
+
}
|
|
45
|
+
throw new Error('The draft did not come out. Try again.');
|
|
40
46
|
}
|
|
41
47
|
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
42
48
|
export const saved = (s) => (s.opening ? `${s.instructions.trim()}\n\nBegin a new conversation with: ${s.opening}` : s.instructions.trim());
|
package/lib/mind.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EFFORTS as EVERY } from '@hanzo/ui/chat/pure';
|
|
2
2
|
import { parseModels, thirdParty } from '@hanzo/ui/models/catalog';
|
|
3
3
|
import { useEffect, useState, useSyncExternalStore } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { prepaid as readPrepaid } from './api/billing.js';
|
|
5
5
|
import { Refusal } from './api/call.js';
|
|
6
6
|
import { ENSO, models as read } from './api/models.js';
|
|
7
7
|
import { usePick } from './pick.js';
|
|
@@ -187,14 +187,14 @@ export function sendable(free, models, cents, id) {
|
|
|
187
187
|
}
|
|
188
188
|
/** The effort as the composer reads it: the one in force, its list, and the way to change it. */
|
|
189
189
|
export const pacing = (m) => ({ value: m.effort, set: m.pace, items: EFFORTS });
|
|
190
|
-
/** The prepaid balance in cents for a signed-in target, read once; null until it is, and where
|
|
190
|
+
/** The prepaid balance in cents that can pay for another maker's models, for a signed-in target, read once; null until it is, and where the API does not say. */
|
|
191
191
|
function useBalance(t, on) {
|
|
192
192
|
const [cents, set] = useState(null);
|
|
193
193
|
useEffect(() => {
|
|
194
194
|
if (!on || !t.token())
|
|
195
195
|
return;
|
|
196
196
|
let live = true;
|
|
197
|
-
|
|
197
|
+
readPrepaid(t).then((n) => live && set(n), () => live && set(null));
|
|
198
198
|
return () => {
|
|
199
199
|
live = false;
|
|
200
200
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/build",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.121",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"description": "Hanzo Build — say what you want, watch it built, deployed and running. The builder as a component, mounted by the Hanzo app at hanzo.ai.",
|