@tangle-network/blueprint-ui 0.5.5 → 0.5.7

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.
@@ -0,0 +1,133 @@
1
+ import { Address, Hex } from 'viem';
2
+ import { h as ServiceContextOperator, g as ServiceContextJob, b as ChainContext, e as JobResultStatus, m as SignTypedDataRequest, J as JobInputs } from './parentBridgeProtocol-BSgLXg9g.js';
3
+
4
+ type WalletSnapshot = {
5
+ readonly address: Address | null;
6
+ readonly chainId: number | null;
7
+ readonly isConnected: boolean;
8
+ };
9
+ type ServiceSnapshot = {
10
+ readonly blueprintId: string | null;
11
+ readonly serviceId: string | null;
12
+ readonly operators: readonly ServiceContextOperator[];
13
+ readonly jobs: readonly ServiceContextJob[];
14
+ readonly mode: string | null;
15
+ /** Chain context broadcast by the parent — drives `useTanglePublicClient`.
16
+ * `null` when the parent hasn't sent one (older parent or dev mode). */
17
+ readonly chain: ChainContext | null;
18
+ };
19
+ type JobInvocation = {
20
+ readonly correlationId: string;
21
+ readonly status: JobResultStatus;
22
+ readonly data?: unknown;
23
+ readonly chunks: readonly unknown[];
24
+ readonly error?: string;
25
+ readonly progress?: {
26
+ readonly percent?: number;
27
+ readonly eta_ms?: number;
28
+ };
29
+ };
30
+ type ClientEventMap = {
31
+ wallet: WalletSnapshot;
32
+ service: ServiceSnapshot;
33
+ job: JobInvocation;
34
+ };
35
+ type Listener<K extends keyof ClientEventMap> = (value: ClientEventMap[K]) => void;
36
+ type TangleIframeClientOptions = {
37
+ /**
38
+ * Origin of the parent dapp. The client posts every message with this
39
+ * exact `targetOrigin` and rejects inbound messages from any other origin.
40
+ * Pass `'*'` only in dev — production must pin to the real parent
41
+ * (`https://cloud.tangle.tools` etc.).
42
+ */
43
+ parentOrigin: string;
44
+ /**
45
+ * Stable identifier for this iframe app. The parent surfaces it in
46
+ * handshake logs + uses it for permission scoping.
47
+ */
48
+ appId: string;
49
+ /**
50
+ * Per-request timeout. Defaults to 60s — long enough for a user to
51
+ * read + approve a signing prompt in the parent. Long-running jobs
52
+ * stream progress events; the request "completes" only on terminal
53
+ * status, so the timeout protects against parents that drop replies
54
+ * entirely.
55
+ */
56
+ requestTimeoutMs?: number;
57
+ };
58
+ declare class TangleIframeClient {
59
+ private readonly options;
60
+ private wallet;
61
+ private service;
62
+ private handshakeAcked;
63
+ private handshakeWaiters;
64
+ private installed;
65
+ private handshakeRetry;
66
+ private listeners;
67
+ private pendingJobs;
68
+ constructor(options: TangleIframeClientOptions);
69
+ /** Wire the global message listener + initial handshake. Idempotent. */
70
+ install(): void;
71
+ uninstall(): void;
72
+ getWallet(): WalletSnapshot;
73
+ getService(): ServiceSnapshot;
74
+ subscribe<K extends keyof ClientEventMap>(event: K, listener: Listener<K>): () => void;
75
+ /**
76
+ * Ask the parent dapp to connect a wallet — opening its connect modal if
77
+ * none is connected. The iframe is sandboxed and cannot reach a wallet
78
+ * itself, so connection is always delegated to the parent. Resolves with the
79
+ * connected address (or `null` if the user dismissed without connecting).
80
+ *
81
+ * Uses a long timeout (the user is interacting with a modal). Already-
82
+ * connected parents resolve immediately.
83
+ */
84
+ connect(): Promise<Address | null>;
85
+ signMessage(message: string): Promise<Hex>;
86
+ sendTransaction(tx: {
87
+ to: Address;
88
+ data: Hex;
89
+ value?: bigint;
90
+ }): Promise<Hex>;
91
+ switchChain(chainId: number): Promise<number>;
92
+ /**
93
+ * EIP-712 typed-data signing. The parent renders the typed-data fields in
94
+ * its approval modal; the user audits what they're signing. Use for
95
+ * operator envelopes, off-chain attestations, anything that needs a
96
+ * signature outside the standard blueprint-job RFQ flow.
97
+ *
98
+ * Shape mirrors viem's `signTypedData` argument. Do not include the
99
+ * EIP712Domain entry in `types` — the parent injects it from `domain`.
100
+ */
101
+ signTypedData(args: {
102
+ domain: SignTypedDataRequest['domain'];
103
+ types: SignTypedDataRequest['types'];
104
+ primaryType: string;
105
+ message: Readonly<Record<string, unknown>>;
106
+ }): Promise<Hex>;
107
+ /**
108
+ * Invoke a blueprint job. Returns a Promise that resolves on terminal
109
+ * status (`success` or `error`); subscribe to the `job` event for
110
+ * intermediate streaming chunks.
111
+ *
112
+ * Streaming opt-in: pass `stream: true` if the publisher's job emits
113
+ * chunks (LLM generation, video encoding). One-shot jobs (embeddings,
114
+ * classifications) skip the streaming machinery.
115
+ */
116
+ callJob(args: {
117
+ jobIndex: number;
118
+ inputs: JobInputs;
119
+ stream?: boolean;
120
+ }): Promise<JobInvocation>;
121
+ private clearHandshakeRetry;
122
+ private postHandshake;
123
+ private postToParent;
124
+ private handleParentMessage;
125
+ private dispatchWallet;
126
+ private handleJobResult;
127
+ private updateWallet;
128
+ private updateService;
129
+ private emit;
130
+ private ensureBootstrapped;
131
+ }
132
+
133
+ export { type ClientEventMap as C, type JobInvocation as J, type ServiceSnapshot as S, TangleIframeClient as T, type WalletSnapshot as W, type TangleIframeClientOptions as a };
@@ -0,0 +1,151 @@
1
+ import { Address } from 'viem';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import * as React from 'react';
4
+ import * as class_variance_authority_types from 'class-variance-authority/types';
5
+ import { VariantProps } from 'class-variance-authority';
6
+
7
+ /**
8
+ * Blueprint Registry — defines the metadata layer for Tangle blueprints.
9
+ *
10
+ * Each blueprint exposes a set of jobs. The registry maps on-chain job IDs
11
+ * to human-readable metadata: labels, descriptions, categories, form fields,
12
+ * and pricing info. This enables the UI to render appropriate forms for each
13
+ * job without procedurally generating UI from raw ABI data.
14
+ *
15
+ * Third-party blueprints can register here to appear in the wizard.
16
+ */
17
+ type JobCategory = 'lifecycle' | 'execution' | 'batch' | 'workflow' | 'ssh' | 'management';
18
+ interface JobFieldDef {
19
+ name: string;
20
+ label: string;
21
+ type: 'text' | 'textarea' | 'number' | 'boolean' | 'select' | 'json' | 'combobox';
22
+ placeholder?: string;
23
+ required?: boolean;
24
+ defaultValue?: string | number | boolean;
25
+ options?: {
26
+ label: string;
27
+ value: string;
28
+ }[];
29
+ helperText?: string;
30
+ /** Minimum allowed value for number fields */
31
+ min?: number;
32
+ /** Maximum allowed value for number fields */
33
+ max?: number;
34
+ /** Step increment for number fields */
35
+ step?: number;
36
+ /** Solidity ABI type for encoding (e.g. 'string', 'uint64', 'bool', 'uint8') */
37
+ abiType?: string;
38
+ /** ABI param name if different from `name` (e.g. 'agent_identifier' vs 'agentIdentifier') */
39
+ abiParam?: string;
40
+ /** Field is included in ABI encoding but never shown in form (e.g. sidecar_token) */
41
+ internal?: boolean;
42
+ }
43
+ /** ABI param injected from runtime context, not user input (e.g. sidecar_url, sandbox_id) */
44
+ interface AbiContextParam {
45
+ abiName: string;
46
+ abiType: string;
47
+ }
48
+ interface JobDefinition {
49
+ id: number;
50
+ name: string;
51
+ label: string;
52
+ description: string;
53
+ category: JobCategory;
54
+ icon: string;
55
+ pricingMultiplier: number;
56
+ /** Fields the user needs to fill for this job */
57
+ fields: JobFieldDef[];
58
+ /** Whether this job requires an existing sandbox to target */
59
+ requiresSandbox: boolean;
60
+ /** Optional warning shown before submission */
61
+ warning?: string;
62
+ /** ABI params prepended from runtime context (e.g. sidecar_url for sandbox jobs) */
63
+ contextParams?: AbiContextParam[];
64
+ /** Override for jobs with complex ABI encoding (e.g. nested structs) */
65
+ customEncoder?: (values: Record<string, unknown>, context?: Record<string, unknown>) => `0x${string}`;
66
+ }
67
+ interface BlueprintDefinition {
68
+ id: string;
69
+ name: string;
70
+ version: string;
71
+ description: string;
72
+ icon: string;
73
+ color: string;
74
+ /** Contract address per chain ID — resolved at runtime */
75
+ contracts: Record<number, Address>;
76
+ /** Supported job definitions */
77
+ jobs: JobDefinition[];
78
+ /** Category ordering for the UI */
79
+ categories: {
80
+ key: JobCategory;
81
+ label: string;
82
+ icon: string;
83
+ }[];
84
+ }
85
+ declare function registerBlueprint(bp: BlueprintDefinition): void;
86
+ declare function getBlueprint(id: string): BlueprintDefinition | undefined;
87
+ declare function getAllBlueprints(): BlueprintDefinition[];
88
+ declare function getBlueprintJobs(blueprintId: string, category?: JobCategory): JobDefinition[];
89
+ declare function getJobById(blueprintId: string, jobId: number): JobDefinition | undefined;
90
+
91
+ declare const buttonVariants: (props?: ({
92
+ variant?: "default" | "link" | "success" | "secondary" | "destructive" | "outline" | "ghost" | null | undefined;
93
+ size?: "default" | "sm" | "lg" | "icon" | "icon-sm" | null | undefined;
94
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
95
+ declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<'button'> & VariantProps<typeof buttonVariants> & {
96
+ asChild?: boolean;
97
+ }): react_jsx_runtime.JSX.Element;
98
+
99
+ type Action = {
100
+ label: string;
101
+ href?: string;
102
+ onClick?: () => void;
103
+ variant?: React.ComponentProps<typeof Button>['variant'];
104
+ disabled?: boolean;
105
+ };
106
+ type BlueprintHostHeroProps = {
107
+ title: string;
108
+ tagline?: string;
109
+ description?: string;
110
+ badges?: string[];
111
+ actions?: Action[];
112
+ children?: React.ReactNode;
113
+ className?: string;
114
+ };
115
+ declare function BlueprintHostHero({ title, tagline, description, badges, actions, children, className, }: BlueprintHostHeroProps): react_jsx_runtime.JSX.Element;
116
+
117
+ type BlueprintHostPanelProps = {
118
+ title: string;
119
+ children: React.ReactNode;
120
+ className?: string;
121
+ };
122
+ declare function BlueprintHostPanel({ title, children, className, }: BlueprintHostPanelProps): react_jsx_runtime.JSX.Element;
123
+
124
+ type RegistrationMode = 'cargo-tangle' | 'cast';
125
+ interface RegistrationCommandOptions {
126
+ blueprintId: bigint;
127
+ rpcAddress: string;
128
+ ecdsaPublicKey: string;
129
+ rpcUrl: string;
130
+ registrationInputs?: string;
131
+ mode?: RegistrationMode;
132
+ /** Contract address for cast mode (defaults to TANGLE_CORE placeholder). */
133
+ servicesAddress?: string;
134
+ }
135
+ interface RegistrationCommandResult {
136
+ /** The copy-paste command for the operator to run on their VPS. */
137
+ command: string;
138
+ /** A human-readable label for the command type. */
139
+ label: string;
140
+ /** The blueprint id as a plain number (for display). */
141
+ blueprintIdNumber: number;
142
+ }
143
+ /**
144
+ * Builds the operator registration command string for the given blueprint.
145
+ * Two modes:
146
+ * - `cargo-tangle` (default) — the canonical `cargo tangle blueprint register` flow.
147
+ * - `cast` — raw `cast send` for operators who manage their own keys.
148
+ */
149
+ declare function useRegistrationCommand(options: RegistrationCommandOptions): RegistrationCommandResult;
150
+
151
+ export { type AbiContextParam as A, type BlueprintDefinition as B, type JobDefinition as J, type RegistrationCommandOptions as R, BlueprintHostHero as a, type BlueprintHostHeroProps as b, BlueprintHostPanel as c, type BlueprintHostPanelProps as d, type JobCategory as e, type JobFieldDef as f, getAllBlueprints as g, getBlueprint as h, getBlueprintJobs as i, getJobById as j, Button as k, buttonVariants as l, registerBlueprint as r, useRegistrationCommand as u };
@@ -0,0 +1,134 @@
1
+ export { T as TANGLE_CLOUD_ORIGINS_DEFAULT, d as detectTangleCloudParentOrigin } from '../detectParentOrigin-BYruoIdc.js';
2
+ import * as wagmi from 'wagmi';
3
+ import { CreateConnectorFn } from 'wagmi';
4
+ import { Address } from 'viem';
5
+ export { A as AccountChanged, C as CallJobRequest, a as ChainChanged, b as ChainContext, H as HandshakeAck, c as HandshakeRequest, I as IframeRequest, J as JobInputs, d as JobResultEvent, e as JobResultStatus, N as NO_WALLET_ADDRESS, P as ParentMessage, R as ReadAccountRequest, f as ReadAccountResult, S as ServiceContextBroadcast, g as ServiceContextJob, h as ServiceContextOperator, i as SignMessageRequest, j as SignMessageResult, k as SignTransactionRequest, l as SignTransactionResult, m as SignTypedDataRequest, n as SignTypedDataResult, o as SwitchChainRequest, p as SwitchChainResult, T as TANGLE_IFRAME_PROTOCOL_PREFIX, q as TANGLE_IFRAME_PROTOCOL_VERSION, r as makeCorrelationId } from '../parentBridgeProtocol-BSgLXg9g.js';
6
+
7
+ interface TangleBlueprintConnectorsOptions {
8
+ /** App id reported to the parent dapp on handshake (when embedded). */
9
+ appId: string;
10
+ /**
11
+ * Connectors used when running STANDALONE (the app's own domain) — e.g.
12
+ * `[injected(), walletConnect({ projectId })]`. Ignored when embedded.
13
+ */
14
+ standalone: CreateConnectorFn[];
15
+ /** Extra trusted parent origins (staging / preview deploys). */
16
+ extraOrigins?: readonly string[];
17
+ /** Override the bridged-request timeout (ms). */
18
+ requestTimeoutMs?: number;
19
+ }
20
+ /**
21
+ * One connector list, two deployment modes — so a blueprint app can ship a
22
+ * single build that runs both standalone and embedded in Tangle Cloud:
23
+ *
24
+ * - **Embedded** (a trusted Tangle Cloud parent is detected): the
25
+ * parent-bridge connector is the *only* connector. The sandboxed iframe
26
+ * can't inject a wallet extension, so it inherits / drives the parent's
27
+ * wallet over the postMessage bridge — surfacing injected/WalletConnect
28
+ * here would just dead-end.
29
+ * - **Standalone** (no trusted parent): the app's own `standalone`
30
+ * connectors, exactly as a normal dapp.
31
+ *
32
+ * The choice is made at runtime from the embedding context, so the same
33
+ * artifact works in both places with no build flags.
34
+ *
35
+ * createConfig({
36
+ * chains,
37
+ * transports,
38
+ * connectors: tangleBlueprintConnectors({
39
+ * appId: 'trading-arena',
40
+ * standalone: [injected(), walletConnect({ projectId })],
41
+ * }),
42
+ * })
43
+ */
44
+ declare function tangleBlueprintConnectors(options: TangleBlueprintConnectorsOptions): CreateConnectorFn[];
45
+
46
+ type EventName = 'accountsChanged' | 'chainChanged' | 'connect' | 'disconnect' | 'message';
47
+ type Listener = (...args: unknown[]) => void;
48
+ type ParentBridgeOptions = {
49
+ /**
50
+ * Origin of the parent dapp that hosts this iframe. The provider posts to
51
+ * `window.parent` with this exact origin and rejects inbound messages from
52
+ * any other origin. Pass `'*'` only in development; production must pin to
53
+ * the real parent (`https://cloud.tangle.tools` or its develop equivalent).
54
+ */
55
+ parentOrigin: string;
56
+ /**
57
+ * Stable identifier for this iframe app. The parent includes this in the
58
+ * handshake ack so dev tooling can correlate logs across the two windows.
59
+ */
60
+ appId: string;
61
+ /**
62
+ * Optional ms timeout for each bridged request. Defaults to 60 seconds —
63
+ * long enough for a user to read + approve a signing prompt in the parent.
64
+ */
65
+ requestTimeoutMs?: number;
66
+ };
67
+ /**
68
+ * Detect iframe execution context. When this returns `false` the bridge
69
+ * connector should not be installed and the host app should fall back to its
70
+ * normal wallet config (ConnectKit + injected/walletConnect).
71
+ *
72
+ * `window.parent !== window` is the most reliable signal that works across
73
+ * sandbox-iframe contexts where direct property access to parent throws.
74
+ */
75
+ declare function isRunningInIframe(): boolean;
76
+ /**
77
+ * EIP-1193 provider backed by the Tangle Cloud iframe protocol. One instance
78
+ * lives per iframe app; the wagmi connector owns the singleton.
79
+ */
80
+ declare class ParentBridgeProvider {
81
+ private readonly options;
82
+ private listeners;
83
+ private pending;
84
+ private cachedAccount;
85
+ private cachedChainId;
86
+ private handshakeAcked;
87
+ private handshakeWaiters;
88
+ private installed;
89
+ constructor(options: ParentBridgeOptions);
90
+ /**
91
+ * Wire up the global message listener and send the initial handshake.
92
+ * Idempotent — safe to call repeatedly during reconnect attempts.
93
+ */
94
+ install(): void;
95
+ uninstall(): void;
96
+ request(req: {
97
+ method: string;
98
+ params?: unknown[];
99
+ }): Promise<unknown>;
100
+ on(event: EventName, listener: Listener): void;
101
+ removeListener(event: EventName, listener: Listener): void;
102
+ private postToParent;
103
+ private handleParentMessage;
104
+ private sendReadAccount;
105
+ /**
106
+ * Ask the parent to connect a wallet (opening its modal if needed) and wait
107
+ * for the result. Long timeout — the user is interacting with the modal.
108
+ */
109
+ private requestConnect;
110
+ private requestSignMessage;
111
+ private requestSignTransaction;
112
+ private requestSwitchChain;
113
+ private dispatch;
114
+ /**
115
+ * Resolves wallet-shape responses (`{ ok, data | error }`). Job results
116
+ * use a different envelope (`{ status, data?, chunk?, error? }`) and are
117
+ * routed through a separate listener registered by `useCallJob` / the SDK
118
+ * — the provider doesn't double-handle them.
119
+ */
120
+ private resolvePending;
121
+ private ensureBootstrapped;
122
+ private updateAccount;
123
+ private updateChainId;
124
+ private emit;
125
+ /** Visible for tests + the connector's `getAccounts()` shortcut. */
126
+ getCachedAccount(): Address | null;
127
+ /** Visible for tests + the connector's `getChainId()` shortcut. */
128
+ getCachedChainId(): number | null;
129
+ }
130
+
131
+ type ParentBridgeConnectorOptions = ParentBridgeOptions;
132
+ declare function parentBridgeConnector(options: ParentBridgeConnectorOptions): wagmi.CreateConnectorFn<ParentBridgeProvider, Record<string, unknown>, Record<string, unknown>>;
133
+
134
+ export { type ParentBridgeConnectorOptions, type ParentBridgeOptions, ParentBridgeProvider, type TangleBlueprintConnectorsOptions, isRunningInIframe, parentBridgeConnector, tangleBlueprintConnectors };