@agentforge-io/connectors-higgsfield 0.0.0-stage → 1.0.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/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @agentforge-io/connectors-higgsfield
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
+ Connects a user's own Higgsfield account over OAuth and talks to `https://mcp.higgsfield.ai/mcp`.
4
+ Agent tools are read-only; image generation is meant to be driven by a host service (owner/admin flow)
5
+ using `HiggsfieldApi`, never by a customer-facing agent.
6
+
7
+ ## Quickstart
8
+
9
+ 1. Serve a client metadata document over https (200, `application/json`, stable URL with a path, no secrets):
10
+ `higgsfieldClientMetadata({ clientId: <that URL>, clientName, clientUri, redirectUris: [<platform>/connectors/oauth/callback] })`.
11
+ 2. `higgsfieldConnector({ clientId: <that URL> })` and register it. There is NO client secret:
12
+ the host must not treat an empty secret as "unconfigured" for this connector (requires core >= 4.18.0).
13
+ 3. Connect from the Directory. Scopes: `openid email offline_access`; `resource=https://mcp.higgsfield.ai/mcp`
14
+ is sent on authorize, exchange and refresh. Redirect URIs must match the document exactly.
15
+
16
+ ## Agent tools (read-only, default permission `approval`)
17
+
18
+ | Tool | Does |
19
+ |---|---|
20
+ | `higgsfield_get_balance` | Credits + plan. |
21
+ | `higgsfield_get_job` | Status (queued, in_progress, completed, failed, nsfw, ip_detected) and result URLs of one job. |
22
+
23
+ Nothing exposed to agents spends credits.
24
+
25
+ ## Library surface (for host services)
26
+
27
+ - `HiggsfieldMcpClient`: initialize + `notifications/initialized` handshake, `mcp-session-id`, JSON and SSE
28
+ responses, timeout. 401 -> `HiggsfieldApiError` `auth_required` (no retry). 429/5xx/network/timeout are retried
29
+ only for read-only calls. A call flagged `spending` is sent once; if it fails after possibly reaching the server
30
+ (timeout, network, 5xx) the error has `providerCode: 'outcome_unknown'`: check the account/jobs before trying again.
31
+ Errors never contain the token or URLs (URLs are replaced by `<url>`).
32
+ - `HiggsfieldApi`: `balance`, `mediaImportUrl`, `removeBackground`, `estimateImageCost`, `generateImage`, `jobsWait`
33
+ (timeout clamped to 15 s). `confirmedPaid: true` sends `use_unlim: false`; omit it otherwise.
34
+ `generateImage` and `removeBackground` are treated as spending.
35
+ - Catalog rules (`rules.ts`, `CATALOG_RULES_VERSION`): 2048x2048 1:1 PNG alpha master, 85% frame fill; modes
36
+ `cutout` (no prompt) and `studio` (fixed prompt per angle, model `flux_2` variant `pro`, reference role
37
+ `image_references`; `marketing_studio_2_image` is ad-styled and not used); `assertCatalogRequest` refuses unknown
38
+ modes/angles and a missing photo (`PHOTO_REQUIRED`). Prompts never interpolate user text.
39
+
40
+ - Image skills (`skills.ts`, `SKILLS_RULES_VERSION`): six server-side art-direction recipes (`product-cart` is the
41
+ alpha master; the rest are finished scenes). All use `flux_2` `pro` 2k with the real photo as `image_references`
42
+ (the only model id verified for this package). Prompts are assembled from the skill + a validated `BrandPalette`
43
+ + an optional sanitized note placed BEFORE the hard rules (no text/logos/prices rendered, packaging label
44
+ verbatim, product identity kept). `generateAspect` is always one of `FLUX2_ASPECTS` (1:1, 4:3, 3:4, 16:9, 9:16, checked against the live model
45
+ catalog 2026-12-01); the 4:5 outputs (`ugc-model`, `cleanfly`) are generated at 3:4 and center-cropped by the host.
46
+
47
+ ## Verified vs assumed
48
+
49
+ Verified (2026-11-23, from documentation/metadata): OAuth endpoints, scopes, `resource`, CIMD, tool names, and the
50
+ envelopes of `balance` (`{credits, subscription_plan_type}`) and `estimate_image_cost`
51
+ (`{cost:{credits,credits_exact}, quote_ref}`).
52
+
53
+ NOT verified against a real grant. Parsed tolerantly; anything else throws `unexpected_response`:
54
+ - `media_import_url`: media id in `media_id` | `id` | `media.id` | `results[0].(media_id|id)`.
55
+ - `remove_background`: a `job_id` (also in `job`/`jobs[]`/`results[]`) and/or a `media_id`; whether it costs credits and
56
+ where `use_unlim` goes (we put it inside `params`).
57
+ - `generate_image`: job ids in `job_id` | `id` | `job_ids[]` | `jobs[]` | `results[]`; the `variant` parameter name for
58
+ flux_2 `pro`; whether `quote_ref` can be passed back.
59
+ - `jobs_wait`: `all_terminal` boolean plus a `jobs[]` (or `results[]`) list with `job_id`|`id`, `status`, and result URLs
60
+ in `results`/`result`/`result_urls`/`urls` (strings or `{url|raw_url|result_url}`).
61
+ - Whether third-party (CIMD) clients see the same tool list as first-party clients.
62
+
63
+ ## Gotchas
64
+
65
+ - Higgsfield turns off dynamic client registration on 2027-01-01; CIMD is the only path.
66
+ - Refresh tokens rotate: core >= 4.18.0 serializes refreshes per stored token. Multi-instance deployments still need a DB lock.
package/dist/api.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { type HiggsfieldMcpClient } from './mcp';
2
+ export interface Balance {
3
+ credits: number;
4
+ subscription_plan_type: string;
5
+ }
6
+ export interface CostEstimate {
7
+ credits: number;
8
+ creditsExact: number | undefined;
9
+ quoteRef: string | undefined;
10
+ }
11
+ export type JobStatus = 'queued' | 'in_progress' | 'completed' | 'failed' | 'nsfw' | 'ip_detected' | (string & {});
12
+ export declare const TERMINAL_JOB_STATUSES: readonly ["completed", "failed", "nsfw", "ip_detected"];
13
+ export interface JobRef {
14
+ index: number;
15
+ job_id: string;
16
+ }
17
+ export interface JobState {
18
+ index: number | undefined;
19
+ jobId: string;
20
+ status: JobStatus;
21
+ resultUrls: string[];
22
+ }
23
+ export interface JobsWaitResult {
24
+ allTerminal: boolean;
25
+ jobs: JobState[];
26
+ }
27
+ export interface MediaRef {
28
+ value: string;
29
+ role: string;
30
+ }
31
+ export interface GenerateImageParams {
32
+ model: string;
33
+ prompt: string;
34
+ aspect_ratio: string;
35
+ medias?: MediaRef[];
36
+ [extra: string]: unknown;
37
+ }
38
+ export declare class HiggsfieldApi {
39
+ private readonly mcp;
40
+ constructor(mcp: HiggsfieldMcpClient);
41
+ /** Verified envelope: { credits, subscription_plan_type }. */
42
+ balance(): Promise<Balance>;
43
+ /** Returns a confirmed media_id (envelope parsed tolerantly). */
44
+ mediaImportUrl(url: string): Promise<{
45
+ mediaId: string;
46
+ }>;
47
+ /**
48
+ * Treated as spending (its cost is not published). Result may be a job or a media id.
49
+ * The tool's params schema is closed: only media_id and media_type are accepted.
50
+ */
51
+ removeBackground(mediaId: string): Promise<{
52
+ jobId?: string;
53
+ mediaId?: string;
54
+ }>;
55
+ /** Verified envelope: { cost: { credits, credits_exact }, quote_ref }. Free call. */
56
+ estimateImageCost(params: GenerateImageParams): Promise<CostEstimate>;
57
+ /** SPENDING. Never retried; ambiguous failures surface as providerCode 'outcome_unknown'. */
58
+ generateImage(params: GenerateImageParams, opts?: {
59
+ confirmedPaid?: boolean;
60
+ }): Promise<{
61
+ jobIds: string[];
62
+ }>;
63
+ /** Polls for up to timeoutSeconds (clamped to 1..15). Free, read-only. */
64
+ jobsWait(jobs: JobRef[], timeoutSeconds?: number): Promise<JobsWaitResult>;
65
+ }
package/dist/api.js ADDED
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HiggsfieldApi = exports.TERMINAL_JOB_STATUSES = void 0;
4
+ const mcp_1 = require("./mcp");
5
+ exports.TERMINAL_JOB_STATUSES = ['completed', 'failed', 'nsfw', 'ip_detected'];
6
+ function unexpected(tool, what) {
7
+ throw new mcp_1.HiggsfieldApiError(200, 'unexpected_response', `${tool}: ${what}`);
8
+ }
9
+ function isObj(v) {
10
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
11
+ }
12
+ function str(v) {
13
+ if (typeof v === 'string' && v)
14
+ return v;
15
+ if (typeof v === 'number')
16
+ return String(v);
17
+ return undefined;
18
+ }
19
+ function firstId(o, keys) {
20
+ if (!isObj(o))
21
+ return undefined;
22
+ for (const k of keys) {
23
+ const v = str(o[k]);
24
+ if (v)
25
+ return v;
26
+ }
27
+ return undefined;
28
+ }
29
+ /** Tolerant: id on the object, nested under `media`/`job`, or first element of a list. */
30
+ function findId(o, keys, listKeys, nestKeys = []) {
31
+ const direct = firstId(o, keys);
32
+ if (direct)
33
+ return direct;
34
+ if (!isObj(o))
35
+ return undefined;
36
+ for (const k of nestKeys) {
37
+ const n = firstId(o[k], keys);
38
+ if (n)
39
+ return n;
40
+ }
41
+ for (const k of listKeys) {
42
+ const l = o[k];
43
+ if (Array.isArray(l) && l.length) {
44
+ const e = firstId(l[0], keys);
45
+ if (e)
46
+ return e;
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ function findIds(o, keys, listKeys) {
52
+ const out = [];
53
+ if (!isObj(o))
54
+ return out;
55
+ const single = firstId(o, keys);
56
+ if (single)
57
+ out.push(single);
58
+ for (const k of listKeys) {
59
+ const l = o[k];
60
+ if (!Array.isArray(l))
61
+ continue;
62
+ for (const e of l) {
63
+ const id = typeof e === 'string' ? e : firstId(e, keys);
64
+ if (id)
65
+ out.push(id);
66
+ }
67
+ }
68
+ return [...new Set(out)];
69
+ }
70
+ function urlsOf(v) {
71
+ const out = [];
72
+ const push = (e) => {
73
+ if (typeof e === 'string' && /^https?:\/\//.test(e))
74
+ out.push(e);
75
+ else if (isObj(e)) {
76
+ const u = str(e.url) ?? str(e.raw_url) ?? str(e.result_url);
77
+ if (u && /^https?:\/\//.test(u))
78
+ out.push(u);
79
+ }
80
+ };
81
+ if (Array.isArray(v))
82
+ v.forEach(push);
83
+ else
84
+ push(v);
85
+ return out;
86
+ }
87
+ class HiggsfieldApi {
88
+ constructor(mcp) {
89
+ this.mcp = mcp;
90
+ }
91
+ /** Verified envelope: { credits, subscription_plan_type }. */
92
+ async balance() {
93
+ const r = await this.mcp.callTool('balance', {});
94
+ if (!isObj(r) || typeof r.credits !== 'number')
95
+ unexpected('balance', 'missing numeric credits');
96
+ return {
97
+ credits: r.credits,
98
+ subscription_plan_type: typeof r.subscription_plan_type === 'string' ? r.subscription_plan_type : 'unknown',
99
+ };
100
+ }
101
+ /** Returns a confirmed media_id (envelope parsed tolerantly). */
102
+ async mediaImportUrl(url) {
103
+ const r = await this.mcp.callTool('media_import_url', { type: 'image', url });
104
+ const mediaId = findId(r, ['media_id', 'id'], ['results', 'medias', 'media'], ['media']);
105
+ if (!mediaId)
106
+ unexpected('media_import_url', 'no media id in response');
107
+ return { mediaId };
108
+ }
109
+ /**
110
+ * Treated as spending (its cost is not published). Result may be a job or a media id.
111
+ * The tool's params schema is closed: only media_id and media_type are accepted.
112
+ */
113
+ async removeBackground(mediaId) {
114
+ const params = { media_id: mediaId, media_type: 'image' };
115
+ const r = await this.mcp.callTool('remove_background', { params }, { spending: true });
116
+ const jobId = findId(r, ['job_id'], ['jobs', 'results'], ['job']);
117
+ const outMedia = findId(r, ['media_id'], ['medias', 'results'], ['media']);
118
+ if (!jobId && !outMedia)
119
+ unexpected('remove_background', 'neither a job id nor a media id in response');
120
+ return { ...(jobId ? { jobId } : {}), ...(outMedia ? { mediaId: outMedia } : {}) };
121
+ }
122
+ /** Verified envelope: { cost: { credits, credits_exact }, quote_ref }. Free call. */
123
+ async estimateImageCost(params) {
124
+ const r = await this.mcp.callTool('estimate_image_cost', { params });
125
+ if (!isObj(r) || !isObj(r.cost) || typeof r.cost.credits !== 'number') {
126
+ unexpected('estimate_image_cost', 'missing cost.credits');
127
+ }
128
+ return {
129
+ credits: r.cost.credits,
130
+ creditsExact: typeof r.cost.credits_exact === 'number' ? r.cost.credits_exact : undefined,
131
+ quoteRef: typeof r.quote_ref === 'string' ? r.quote_ref : undefined,
132
+ };
133
+ }
134
+ /** SPENDING. Never retried; ambiguous failures surface as providerCode 'outcome_unknown'. */
135
+ async generateImage(params, opts = {}) {
136
+ const p = opts.confirmedPaid ? { ...params, use_unlim: false } : params;
137
+ const r = await this.mcp.callTool('generate_image', { params: p }, { spending: true });
138
+ const jobIds = findIds(r, ['job_id', 'id'], ['job_ids', 'jobs', 'results']);
139
+ if (!jobIds.length)
140
+ unexpected('generate_image', 'no job id in response');
141
+ return { jobIds };
142
+ }
143
+ /** Polls for up to timeoutSeconds (clamped to 1..15). Free, read-only. */
144
+ async jobsWait(jobs, timeoutSeconds = 15) {
145
+ const t = Math.min(15, Math.max(1, Math.floor(timeoutSeconds)));
146
+ const r = await this.mcp.callTool('jobs_wait', { jobs, timeout_seconds: t });
147
+ if (!isObj(r) || typeof r.all_terminal !== 'boolean')
148
+ unexpected('jobs_wait', 'missing all_terminal');
149
+ const list = Array.isArray(r.jobs) ? r.jobs : Array.isArray(r.results) ? r.results : undefined;
150
+ if (!list)
151
+ unexpected('jobs_wait', 'missing per-job list');
152
+ const states = list.map((j) => {
153
+ if (!isObj(j))
154
+ return unexpected('jobs_wait', 'job entry is not an object');
155
+ const jobId = firstId(j, ['job_id', 'id']);
156
+ const status = str(j.status);
157
+ if (!jobId || !status)
158
+ return unexpected('jobs_wait', 'job entry without id or status');
159
+ const urls = [...urlsOf(j.result_url), ...urlsOf(j.results), ...urlsOf(j.result), ...urlsOf(j.result_urls), ...urlsOf(j.urls)];
160
+ return {
161
+ index: typeof j.index === 'number' ? j.index : undefined,
162
+ jobId,
163
+ status,
164
+ resultUrls: [...new Set(urls)],
165
+ };
166
+ });
167
+ return { allTerminal: r.all_terminal, jobs: states };
168
+ }
169
+ }
170
+ exports.HiggsfieldApi = HiggsfieldApi;
@@ -0,0 +1,19 @@
1
+ export interface HiggsfieldClientMetadataInput {
2
+ /** The URL this document is served from; it IS the OAuth client_id. */
3
+ clientId: string;
4
+ clientName: string;
5
+ clientUri: string;
6
+ logoUri?: string;
7
+ redirectUris: string[];
8
+ }
9
+ export interface HiggsfieldClientMetadata {
10
+ client_id: string;
11
+ client_name: string;
12
+ client_uri: string;
13
+ logo_uri?: string;
14
+ redirect_uris: string[];
15
+ grant_types: ['authorization_code', 'refresh_token'];
16
+ response_types: ['code'];
17
+ token_endpoint_auth_method: 'none';
18
+ }
19
+ export declare function higgsfieldClientMetadata(input: HiggsfieldClientMetadataInput): HiggsfieldClientMetadata;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.higgsfieldClientMetadata = higgsfieldClientMetadata;
4
+ function fail(what, why) {
5
+ throw new Error(`Invalid client metadata: ${what} ${why}`);
6
+ }
7
+ function parseHttps(what, value) {
8
+ let u;
9
+ try {
10
+ u = new URL(value);
11
+ }
12
+ catch {
13
+ return fail(what, 'is not a valid URL');
14
+ }
15
+ if (u.protocol !== 'https:')
16
+ fail(what, 'must be https');
17
+ if (u.username || u.password)
18
+ fail(what, 'must not contain credentials');
19
+ if (u.hash || value.includes('#'))
20
+ fail(what, 'must not contain a fragment');
21
+ return u;
22
+ }
23
+ function higgsfieldClientMetadata(input) {
24
+ const id = parseHttps('clientId', input.clientId);
25
+ if (id.pathname === '/')
26
+ fail('clientId', 'must have a path');
27
+ // The URL parser normalizes dot segments away, so inspect the raw string.
28
+ const rawPath = input.clientId.replace(/^https:\/\/[^/?]*/i, '').split('?')[0];
29
+ if (rawPath.split('/').some((s) => /^(\.|%2e){1,2}$/i.test(s))) {
30
+ fail('clientId', 'must not contain dot segments');
31
+ }
32
+ if (!input.clientName.trim())
33
+ fail('clientName', 'is required');
34
+ parseHttps('clientUri', input.clientUri);
35
+ if (input.logoUri)
36
+ parseHttps('logoUri', input.logoUri);
37
+ if (!input.redirectUris.length)
38
+ fail('redirectUris', 'must not be empty');
39
+ for (const r of input.redirectUris) {
40
+ const u = (() => {
41
+ try {
42
+ return new URL(r);
43
+ }
44
+ catch {
45
+ return fail('redirectUri', 'is not a valid URL');
46
+ }
47
+ })();
48
+ const loopback = u.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(u.hostname);
49
+ if (u.protocol !== 'https:' && !loopback)
50
+ fail('redirectUri', 'must be https (or http loopback)');
51
+ if (u.hash || r.includes('#'))
52
+ fail('redirectUri', 'must not contain a fragment');
53
+ if (u.username || u.password)
54
+ fail('redirectUri', 'must not contain credentials');
55
+ }
56
+ return {
57
+ client_id: input.clientId,
58
+ client_name: input.clientName,
59
+ client_uri: input.clientUri,
60
+ ...(input.logoUri ? { logo_uri: input.logoUri } : {}),
61
+ redirect_uris: [...input.redirectUris],
62
+ grant_types: ['authorization_code', 'refresh_token'],
63
+ response_types: ['code'],
64
+ token_endpoint_auth_method: 'none',
65
+ };
66
+ }
@@ -0,0 +1,11 @@
1
+ import type { ConnectorDefinition } from '@agentforge-io/core';
2
+ export declare const HIGGSFIELD_MCP_URL = "https://mcp.higgsfield.ai/mcp";
3
+ export interface HiggsfieldConnectorOptions {
4
+ /**
5
+ * URL of the public client-metadata (CIMD) document. Higgsfield identifies
6
+ * third-party clients by this URL instead of a registered id + secret.
7
+ */
8
+ clientId: string;
9
+ iconUrl?: string;
10
+ }
11
+ export declare function higgsfieldConnector(opts: HiggsfieldConnectorOptions): ConnectorDefinition;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HIGGSFIELD_MCP_URL = void 0;
4
+ exports.higgsfieldConnector = higgsfieldConnector;
5
+ const get_balance_1 = require("./tools/get-balance");
6
+ const get_job_1 = require("./tools/get-job");
7
+ exports.HIGGSFIELD_MCP_URL = 'https://mcp.higgsfield.ai/mcp';
8
+ function higgsfieldConnector(opts) {
9
+ return {
10
+ id: 'higgsfield',
11
+ name: 'Higgsfield',
12
+ description: 'Reads the credit balance and generation job status of the connected Higgsfield account. ' +
13
+ 'Image generation itself runs through the platform photo-studio flow, not agent tools.',
14
+ category: 'Media',
15
+ iconUrl: opts.iconUrl,
16
+ oauth: {
17
+ authorizeUrl: 'https://higgsfield.ai/_clerk/oauth/authorize',
18
+ tokenUrl: 'https://higgsfield.ai/_clerk/oauth/token',
19
+ clientId: opts.clientId,
20
+ // Public client: there is no secret. Hosts must not gate "configured" on it.
21
+ clientSecret: '',
22
+ scopes: ['openid', 'email', 'offline_access'],
23
+ usePkce: true,
24
+ tokenAuth: 'none',
25
+ // RFC 8707: the token must be audience-bound to the MCP resource.
26
+ authorizeExtras: { resource: exports.HIGGSFIELD_MCP_URL },
27
+ tokenExtras: { resource: exports.HIGGSFIELD_MCP_URL },
28
+ },
29
+ tools: [get_balance_1.higgsfieldGetBalanceTool, get_job_1.higgsfieldGetJobTool],
30
+ defaultToolPermissions: [
31
+ { name: 'higgsfield_get_balance', mode: 'approval' },
32
+ { name: 'higgsfield_get_job', mode: 'approval' },
33
+ ],
34
+ };
35
+ }
@@ -0,0 +1,8 @@
1
+ export { higgsfieldConnector, HIGGSFIELD_MCP_URL, type HiggsfieldConnectorOptions } from './connector';
2
+ export { higgsfieldClientMetadata, type HiggsfieldClientMetadata, type HiggsfieldClientMetadataInput, } from './client-metadata';
3
+ export { HiggsfieldMcpClient, HiggsfieldApiError, type McpClientOptions, type CallToolOptions } from './mcp';
4
+ export { HiggsfieldApi, TERMINAL_JOB_STATUSES, type Balance, type CostEstimate, type GenerateImageParams, type JobRef, type JobState, type JobStatus, type JobsWaitResult, type MediaRef, } from './api';
5
+ export * from './rules';
6
+ export { higgsfieldGetBalanceTool } from './tools/get-balance';
7
+ export { higgsfieldGetJobTool } from './tools/get-job';
8
+ export * from './skills';
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.higgsfieldGetJobTool = exports.higgsfieldGetBalanceTool = exports.TERMINAL_JOB_STATUSES = exports.HiggsfieldApi = exports.HiggsfieldApiError = exports.HiggsfieldMcpClient = exports.higgsfieldClientMetadata = exports.HIGGSFIELD_MCP_URL = exports.higgsfieldConnector = void 0;
18
+ var connector_1 = require("./connector");
19
+ Object.defineProperty(exports, "higgsfieldConnector", { enumerable: true, get: function () { return connector_1.higgsfieldConnector; } });
20
+ Object.defineProperty(exports, "HIGGSFIELD_MCP_URL", { enumerable: true, get: function () { return connector_1.HIGGSFIELD_MCP_URL; } });
21
+ var client_metadata_1 = require("./client-metadata");
22
+ Object.defineProperty(exports, "higgsfieldClientMetadata", { enumerable: true, get: function () { return client_metadata_1.higgsfieldClientMetadata; } });
23
+ var mcp_1 = require("./mcp");
24
+ Object.defineProperty(exports, "HiggsfieldMcpClient", { enumerable: true, get: function () { return mcp_1.HiggsfieldMcpClient; } });
25
+ Object.defineProperty(exports, "HiggsfieldApiError", { enumerable: true, get: function () { return mcp_1.HiggsfieldApiError; } });
26
+ var api_1 = require("./api");
27
+ Object.defineProperty(exports, "HiggsfieldApi", { enumerable: true, get: function () { return api_1.HiggsfieldApi; } });
28
+ Object.defineProperty(exports, "TERMINAL_JOB_STATUSES", { enumerable: true, get: function () { return api_1.TERMINAL_JOB_STATUSES; } });
29
+ __exportStar(require("./rules"), exports);
30
+ var get_balance_1 = require("./tools/get-balance");
31
+ Object.defineProperty(exports, "higgsfieldGetBalanceTool", { enumerable: true, get: function () { return get_balance_1.higgsfieldGetBalanceTool; } });
32
+ var get_job_1 = require("./tools/get-job");
33
+ Object.defineProperty(exports, "higgsfieldGetJobTool", { enumerable: true, get: function () { return get_job_1.higgsfieldGetJobTool; } });
34
+ __exportStar(require("./skills"), exports);
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ export declare const HIGGSFIELD_MCP_ENDPOINT = "https://mcp.higgsfield.ai/mcp";
2
+ export declare class HiggsfieldApiError extends Error {
3
+ readonly status: number;
4
+ /** Stable identifier: 'auth_required', 'rate_limited', 'timeout', 'network_error',
5
+ * 'outcome_unknown', 'unexpected_response', 'tool_error', or a JSON-RPC code. */
6
+ readonly providerCode: string;
7
+ constructor(status: number,
8
+ /** Stable identifier: 'auth_required', 'rate_limited', 'timeout', 'network_error',
9
+ * 'outcome_unknown', 'unexpected_response', 'tool_error', or a JSON-RPC code. */
10
+ providerCode: string, message: string);
11
+ }
12
+ export interface McpClientOptions {
13
+ accessToken: string;
14
+ /** Optional session id when the caller already negotiated one. */
15
+ sessionId?: string;
16
+ endpoint?: string;
17
+ fetchImpl?: typeof fetch;
18
+ timeoutMs?: number;
19
+ /** Extra attempts for read-only calls on 429/5xx/network/timeout. */
20
+ maxRetries?: number;
21
+ sleep?: (ms: number) => Promise<void>;
22
+ }
23
+ export interface CallToolOptions {
24
+ /**
25
+ * A call that can consume credits. Never retried; once the request may have
26
+ * reached the server, any ambiguous failure becomes 'outcome_unknown'.
27
+ */
28
+ spending?: boolean;
29
+ }
30
+ export declare class HiggsfieldMcpClient {
31
+ private readonly opts;
32
+ private sessionId?;
33
+ private initialized;
34
+ private nextId;
35
+ private readonly fetchImpl;
36
+ private readonly endpoint;
37
+ private readonly timeoutMs;
38
+ private readonly maxRetries;
39
+ private readonly sleep;
40
+ constructor(opts: McpClientOptions);
41
+ /** Calls a tool and returns structuredContent, else the JSON in the text content. */
42
+ callTool(name: string, args: Record<string, unknown>, callOpts?: CallToolOptions): Promise<unknown>;
43
+ private ensureInitialized;
44
+ private rpc;
45
+ private post;
46
+ }