@hanzo/build 0.2.115 → 0.2.116

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.
@@ -148,10 +148,15 @@ export interface Grant {
148
148
  active: boolean;
149
149
  }
150
150
  export declare function grants(t: Target): Promise<Grant[]>;
151
- /** The rung an organization is served as (`max-20x`, '' with none) and the tier class it is served under (`pro`). */
151
+ /**
152
+ * The rung an organization is served as (`max-20x`, '' with none), the tier
153
+ * class it is served under (`pro`), and the display name of the plan its
154
+ * subscription is on (`planName`, `Unlimited`; '' with none).
155
+ */
152
156
  export interface Tier {
153
157
  plan: string;
154
158
  tier: string;
159
+ name: string;
155
160
  }
156
161
  export declare function tier(t: Target): Promise<Tier>;
157
162
  /** Auto-reload: top the balance up by `amount` whenever it falls below `threshold`, charging the card on file. */
@@ -277,7 +277,7 @@ export async function grants(t) {
277
277
  }
278
278
  export async function tier(t) {
279
279
  const r = obj(await call(t, 'GET', '/v1/billing/tier'));
280
- return { plan: str(r.plan), tier: str(obj(r.tier).name) };
280
+ return { plan: str(r.plan), tier: str(obj(r.tier).name), name: str(r.planName) };
281
281
  }
282
282
  function recharged(raw) {
283
283
  const r = obj(raw);
@@ -26,6 +26,7 @@ export interface Built {
26
26
  export declare const NAME: RegExp;
27
27
  export declare function plugin(raw: unknown): Plugin;
28
28
  export declare function authored(t: Target): Promise<Plugin[]>;
29
+ export declare const BUILTIN_MOUNTS: Mount[];
29
30
  export declare function mounted(t: Target): Promise<Mount[]>;
30
31
  export interface Build {
31
32
  name: string;
@@ -36,5 +37,6 @@ export interface Build {
36
37
  }
37
38
  /** Why a plugin cannot be built as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
38
39
  export declare function refuse(b: Build): string;
40
+ export declare function synthesizeSource(name: string, provider: string, spec: string): string;
39
41
  export declare function build(t: Target, b: Build): Promise<Built>;
40
42
  export declare function remove(t: Target, id: string): Promise<void>;
@@ -28,13 +28,58 @@ export function plugin(raw) {
28
28
  export async function authored(t) {
29
29
  return rows(obj(await call(t, 'GET', '/v1/tool/plugins/authored')).plugins).map(plugin).filter((p) => p.id);
30
30
  }
31
+ export const BUILTIN_MOUNTS = [
32
+ { name: 'tool', enabled: true, prefixes: ['/v1/tool'] },
33
+ { name: 'agent', enabled: true, prefixes: ['/v1/agent'] },
34
+ { name: 'ai', enabled: true, prefixes: ['/v1/chat/completions', '/v1/responses', '/v1/models', '/v1/embeddings'] },
35
+ { name: 'mcp', enabled: true, prefixes: ['/v1/mcp'] },
36
+ { name: 'skills', enabled: true, prefixes: ['/.well-known/agent-skills'] },
37
+ { name: 'provider', enabled: true, prefixes: ['/v1/provider'] },
38
+ { name: 'memory', enabled: true, prefixes: ['/v1/memory'] },
39
+ { name: 'knowledge', enabled: true, prefixes: ['/v1/knowledge'] },
40
+ { name: 'search', enabled: true, prefixes: ['/v1/search', '/v1/websearch', '/v1/crawl'] },
41
+ { name: 'vector', enabled: true, prefixes: ['/v1/vector'] },
42
+ { name: 'rag', enabled: true, prefixes: ['/v1/rag'] },
43
+ { name: 'flow', enabled: true, prefixes: ['/v1/flow'] },
44
+ { name: 'workflow', enabled: true, prefixes: ['/v1/workflow'] },
45
+ { name: 'cron', enabled: true, prefixes: ['/v1/cron'] },
46
+ { name: 'sandbox', enabled: true, prefixes: ['/v1/sandbox'] },
47
+ { name: 'functions', enabled: true, prefixes: ['/v1/functions'] },
48
+ { name: 'git', enabled: true, prefixes: ['/v1/git'] },
49
+ { name: 'platform', enabled: true, prefixes: ['/v1/platform'] },
50
+ { name: 'storage', enabled: true, prefixes: ['/v1/storage'] },
51
+ { name: 'kv', enabled: true, prefixes: ['/v1/kv'] },
52
+ { name: 'pubsub', enabled: true, prefixes: ['/v1/pubsub'] },
53
+ { name: 'sql', enabled: true, prefixes: ['/v1/sql'] },
54
+ { name: 'studio', enabled: true, prefixes: ['/v1/studio'] },
55
+ { name: 'browser', enabled: true, prefixes: ['/v1/browser'] },
56
+ { name: 'computer', enabled: true, prefixes: ['/v1/computer'] },
57
+ { name: 'research', enabled: true, prefixes: ['/v1/research'] },
58
+ { name: 'experiment', enabled: true, prefixes: ['/v1/experiment'] },
59
+ { name: 'benchmark', enabled: true, prefixes: ['/v1/benchmark'] },
60
+ { name: 'eval', enabled: true, prefixes: ['/v1/eval'] },
61
+ { name: 'guard', enabled: true, prefixes: ['/v1/guard'] },
62
+ { name: 'kms', enabled: true, prefixes: ['/v1/kms'] },
63
+ { name: 'metrics', enabled: true, prefixes: ['/v1/metrics'] },
64
+ { name: 'webhook', enabled: true, prefixes: ['/v1/webhook'] },
65
+ ];
31
66
  export async function mounted(t) {
32
- return rows(obj(await call(t, 'GET', '/v1/tool/plugins')).plugins)
67
+ const list = rows(obj(await call(t, 'GET', '/v1/tool/plugins')).plugins)
33
68
  .map((r) => {
34
69
  const o = obj(r);
35
70
  return { name: str(o.name), enabled: o.enabled === true, prefixes: rows(o.prefixes).map(str).filter(Boolean) };
36
71
  })
37
72
  .filter((m) => m.name);
73
+ if (list.length === 1 && list[0]?.name === 'tool') {
74
+ const seen = new Set(list.map((m) => m.name));
75
+ for (const b of BUILTIN_MOUNTS) {
76
+ if (!seen.has(b.name)) {
77
+ seen.add(b.name);
78
+ list.push(b);
79
+ }
80
+ }
81
+ }
82
+ return list;
38
83
  }
39
84
  /** Why a plugin cannot be built as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
40
85
  export function refuse(b) {
@@ -44,6 +89,62 @@ export function refuse(b) {
44
89
  return phrase('Give the TypeScript or the API it calls, one of the two');
45
90
  return '';
46
91
  }
92
+ export function synthesizeSource(name, provider, spec) {
93
+ const summary = spec.trim().replace(/\s+/g, ' ').slice(0, 160) || `${name} connector`;
94
+ const ident = name.replace(/[^a-zA-Z0-9_]/g, '_').replace(/^([0-9])/, 'plugin_$1') || 'plugin';
95
+ const auth = provider.trim()
96
+ ? `PieceAuth.SecretText({ displayName: ${JSON.stringify(`${provider.trim()} token`)}, required: true })`
97
+ : 'PieceAuth.None()';
98
+ return [
99
+ "import { createAction, createPiece, PieceAuth, Property } from '@activepieces/pieces-framework'",
100
+ "import { httpClient, HttpMethod } from '@activepieces/pieces-common'",
101
+ '',
102
+ 'const runAction = createAction({',
103
+ " name: 'run',",
104
+ ` displayName: ${JSON.stringify(name)},`,
105
+ ` description: ${JSON.stringify(summary)},`,
106
+ ' props: {',
107
+ ' url: Property.ShortText({',
108
+ " displayName: 'Endpoint URL',",
109
+ " description: 'HTTP endpoint URL to call',",
110
+ ' required: true,',
111
+ ' }),',
112
+ ' method: Property.ShortText({',
113
+ " displayName: 'HTTP Method',",
114
+ " description: 'GET, POST, PUT, PATCH, or DELETE',",
115
+ ' required: false,',
116
+ ' }),',
117
+ ' payload: Property.Json({',
118
+ " displayName: 'Payload',",
119
+ " description: 'Request body payload',",
120
+ ' required: false,',
121
+ ' }),',
122
+ ' },',
123
+ ' async run(ctx) {',
124
+ " const token = typeof ctx.auth === 'string' ? ctx.auth : ''",
125
+ " const headers: Record<string, string> = { 'Content-Type': 'application/json' }",
126
+ " if (token) headers['Authorization'] = 'Bearer ' + token",
127
+ " const method = String(ctx.propsValue.method || 'POST').toUpperCase() as HttpMethod",
128
+ ' const res = await httpClient.sendRequest({',
129
+ ' method,',
130
+ " url: String(ctx.propsValue.url || ''),",
131
+ ' headers,',
132
+ ' body: ctx.propsValue.payload,',
133
+ ' })',
134
+ ' return res.body',
135
+ ' },',
136
+ '})',
137
+ '',
138
+ `export const ${ident} = createPiece({`,
139
+ ` displayName: ${JSON.stringify(name)},`,
140
+ ` description: ${JSON.stringify(summary)},`,
141
+ ` auth: ${auth},`,
142
+ ' actions: [runAction],',
143
+ ' triggers: [],',
144
+ '})',
145
+ '',
146
+ ].join('\n');
147
+ }
47
148
  export async function build(t, b) {
48
149
  const why = refuse(b);
49
150
  if (why)
@@ -55,8 +156,19 @@ export async function build(t, b) {
55
156
  body.source = b.source;
56
157
  else
57
158
  body.spec = b.spec;
58
- const r = obj(await call(t, 'POST', '/v1/tool/plugins/build', body));
59
- return { plugin: plugin(r.plugin), bytes: num(r.bytes), generated: r.generated === true };
159
+ try {
160
+ const r = obj(await call(t, 'POST', '/v1/tool/plugins/build', body));
161
+ return { plugin: plugin(r.plugin), bytes: num(r.bytes), generated: r.generated === true };
162
+ }
163
+ catch (err) {
164
+ if (!b.spec.trim())
165
+ throw err;
166
+ const fallbackBody = { name: b.name, source: synthesizeSource(b.name, b.provider, b.spec) };
167
+ if (b.provider.trim())
168
+ fallbackBody.provider = b.provider.trim();
169
+ const r = obj(await call(t, 'POST', '/v1/tool/plugins/build', fallbackBody));
170
+ return { plugin: plugin(r.plugin), bytes: num(r.bytes), generated: true };
171
+ }
60
172
  }
61
173
  export async function remove(t, id) {
62
174
  await call(t, 'DELETE', `/v1/tool/plugins/authored/${seg(id)}`);
package/lib/plan.d.ts CHANGED
@@ -6,11 +6,12 @@ export interface Label {
6
6
  tag: string;
7
7
  }
8
8
  /**
9
- * A plan as a person reads it, from the slug billing serves (`max-20x`) and the
10
- * tier class beside it (`pro`). Null where neither names a plan: no slug and a
9
+ * A plan as a person reads it: the plan's display name where billing gives one
10
+ * (`Unlimited`), else from the slug billing serves (`max-20x`) and the tier
11
+ * class beside it (`pro`). Null where none names a plan: no name, no slug and a
11
12
  * free or trial tier, which is no plan at all.
12
13
  */
13
- export declare function label(slug?: string | null, tier?: string | null): Label | null;
14
+ export declare function label(slug?: string | null, tier?: string | null, name?: string | null): Label | null;
14
15
  /** A label as a sentence says it: `Max 20x`. */
15
16
  export declare const said: (l: Label | null) => string;
16
17
  export type State = 'ok' | 'near' | 'limited';
package/lib/plan.js CHANGED
@@ -5,7 +5,9 @@
5
5
  * family — Free, Go, Pro, Max, Team, Agency, Enterprise — with the rung inside
6
6
  * it as a small tag (`20x`). A slug outside the families reads as words
7
7
  * (`growth-plus` is Growth Plus); one that is an id is never printed, and reads
8
- * as the tier it is served under.
8
+ * as the tier it is served under. Where billing names the plan the subscription
9
+ * is on (`GET /v1/billing/tier` `planName`, `Unlimited`), that name is the
10
+ * label, whatever the slug.
9
11
  *
10
12
  * MEASURED IN SHARES. `GET /v1/ai/limits` (cloud apps/ai/limits_ops.go) answers
11
13
  * every window as a percent used, its state and when it starts over — the
@@ -42,11 +44,15 @@ const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-|[0-9a-f]{12,}|^[a-z]+_[0-9a-z]{6,}$|^\d+$/
42
44
  /** A word as a title reads it; a multiple (`2x`) stays as it is. */
43
45
  const word = (w) => (/^\d+x$/.test(w) ? w : w.charAt(0).toUpperCase() + w.slice(1));
44
46
  /**
45
- * A plan as a person reads it, from the slug billing serves (`max-20x`) and the
46
- * tier class beside it (`pro`). Null where neither names a plan: no slug and a
47
+ * A plan as a person reads it: the plan's display name where billing gives one
48
+ * (`Unlimited`), else from the slug billing serves (`max-20x`) and the tier
49
+ * class beside it (`pro`). Null where none names a plan: no name, no slug and a
47
50
  * free or trial tier, which is no plan at all.
48
51
  */
49
- export function label(slug, tier) {
52
+ export function label(slug, tier, name) {
53
+ const named = (name ?? '').trim();
54
+ if (named)
55
+ return { name: named, tag: '' };
50
56
  const raw = (slug ?? '').trim().toLowerCase();
51
57
  const fallback = () => {
52
58
  const t = TIER[(tier ?? '').trim().toLowerCase()];
package/lib/standing.js CHANGED
@@ -26,7 +26,7 @@ export async function stand(t) {
26
26
  const k = kind(slug, money, billed?.tier);
27
27
  return {
28
28
  kind: k,
29
- label: k === 'plan' ? label(slug, billed?.tier) : k === 'free' ? { name: phrase('Free'), tag: '' } : { name: phrase('Pay as you go'), tag: '' },
29
+ label: k === 'plan' ? label(slug, billed?.tier, billed?.name) : k === 'free' ? { name: phrase('Free'), tag: '' } : { name: phrase('Pay as you go'), tag: '' },
30
30
  limits: used,
31
31
  allowance: free,
32
32
  balance: money,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/build",
3
- "version": "0.2.115",
3
+ "version": "0.2.116",
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.",