@ergoblockchain/sage-widget 0.1.0 → 0.2.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 +111 -5
- package/dist/index.cjs +203 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.js +199 -4
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +677 -11
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -3
- package/dist/react.d.ts +10 -3
- package/dist/react.js +678 -13
- package/dist/react.js.map +1 -1
- package/dist/types-yv1THHVz.d.cts +229 -0
- package/dist/types-yv1THHVz.d.ts +229 -0
- package/dist/vanilla.cjs +720 -6
- package/dist/vanilla.cjs.map +1 -1
- package/dist/vanilla.d.cts +20 -3
- package/dist/vanilla.d.ts +20 -3
- package/dist/vanilla.js +720 -7
- package/dist/vanilla.js.map +1 -1
- package/package.json +3 -2
- package/dist/types-uzMz6_mP.d.cts +0 -77
- package/dist/types-uzMz6_mP.d.ts +0 -77
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the Sage activity feed and paid chat flow.
|
|
3
|
+
*
|
|
4
|
+
* The source of truth is the API at https://www.ergoblockchain.org/api/sage/activity;
|
|
5
|
+
* this file re-states the schema so consumers don't have to depend on the
|
|
6
|
+
* server-side fetcher.
|
|
7
|
+
*/
|
|
8
|
+
type SageActivityType = "settlement" | "issuance" | "transfer";
|
|
9
|
+
interface SageActivityEvent {
|
|
10
|
+
/** 64-char hex transaction id. */
|
|
11
|
+
txId: string;
|
|
12
|
+
/** Block height at inclusion. */
|
|
13
|
+
blockHeight: number;
|
|
14
|
+
/** Block timestamp (ms epoch). */
|
|
15
|
+
timestamp: number;
|
|
16
|
+
/** Heuristic classification of the tx. */
|
|
17
|
+
type: SageActivityType;
|
|
18
|
+
/** nanoERG flowing into the seller wallet from this tx (sum of outputs). */
|
|
19
|
+
inflowNanoErg: number;
|
|
20
|
+
/**
|
|
21
|
+
* For settlements: value of the redeemed Note (= what the buyer paid).
|
|
22
|
+
* For other event types: undefined.
|
|
23
|
+
*
|
|
24
|
+
* Use this — not `inflowNanoErg` — when displaying "amount paid for a
|
|
25
|
+
* settled query". `inflowNanoErg` includes change boxes in test setups
|
|
26
|
+
* where the buyer and seller share an address.
|
|
27
|
+
*/
|
|
28
|
+
paymentNanoErg?: number;
|
|
29
|
+
/** First input box that carries Note-shape registers, if any. */
|
|
30
|
+
noteBoxId?: string;
|
|
31
|
+
}
|
|
32
|
+
interface SageActivityResponse {
|
|
33
|
+
ok: boolean;
|
|
34
|
+
network: "testnet" | "mainnet";
|
|
35
|
+
/** Sage seller wallet address. */
|
|
36
|
+
receiver: string;
|
|
37
|
+
/** Total number of txs ever touching the wallet, per the explorer. */
|
|
38
|
+
total: number;
|
|
39
|
+
events: SageActivityEvent[];
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration accepted by every entry point (React component +
|
|
44
|
+
* vanilla mount fn). Defaults below are sensible for the canonical
|
|
45
|
+
* ergoblockchain.org deployment.
|
|
46
|
+
*/
|
|
47
|
+
interface SageWidgetOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Base URL of the Sage host. Override if you run your own Sage
|
|
50
|
+
* deployment behind a custom domain. Default: ergoblockchain.org.
|
|
51
|
+
*/
|
|
52
|
+
apiBase?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Number of events to display (max 25). Default: 5.
|
|
55
|
+
*/
|
|
56
|
+
limit?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Polling interval in ms. Default: 60000 (60s). Set to 0 to disable
|
|
59
|
+
* polling — the widget will fetch once on mount and never refresh.
|
|
60
|
+
*/
|
|
61
|
+
refreshMs?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Optional callback fired every time a fresh response arrives. Useful
|
|
64
|
+
* for analytics or for triggering host-side animations on new
|
|
65
|
+
* settlements.
|
|
66
|
+
*/
|
|
67
|
+
onUpdate?: (response: SageActivityResponse) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Optional callback fired on fetch errors. Default: console.warn.
|
|
70
|
+
*/
|
|
71
|
+
onError?: (error: unknown) => void;
|
|
72
|
+
}
|
|
73
|
+
type SageChatRole = "user" | "assistant";
|
|
74
|
+
interface SageChatMessage {
|
|
75
|
+
role: SageChatRole;
|
|
76
|
+
content: string;
|
|
77
|
+
}
|
|
78
|
+
interface SageTenantConfig {
|
|
79
|
+
/** Stable tenant id for analytics, logs, or future multi-tenant routing. */
|
|
80
|
+
id?: string;
|
|
81
|
+
/** Human-facing label shown in the default widgets. */
|
|
82
|
+
label?: string;
|
|
83
|
+
/** Extra headers attached to Sage API requests. */
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
}
|
|
86
|
+
interface SageQuote {
|
|
87
|
+
quoteId: string;
|
|
88
|
+
taskHash: string;
|
|
89
|
+
price: string;
|
|
90
|
+
issuedAt?: string;
|
|
91
|
+
expiresAt: string;
|
|
92
|
+
receiverAddress: string;
|
|
93
|
+
reserveBoxId: string;
|
|
94
|
+
deadline: `+${number} blocks`;
|
|
95
|
+
}
|
|
96
|
+
type SagePremiumReason = "explicit_command" | "code_request" | "long_answer" | "deep_research" | "multi_turn_followup";
|
|
97
|
+
interface SageQuoteResponse {
|
|
98
|
+
premium: boolean;
|
|
99
|
+
reason?: SagePremiumReason;
|
|
100
|
+
rationale?: string;
|
|
101
|
+
quote?: SageQuote;
|
|
102
|
+
}
|
|
103
|
+
interface SageVerifyPaymentResponse {
|
|
104
|
+
ok: true;
|
|
105
|
+
paymentToken: string;
|
|
106
|
+
receiptId: string;
|
|
107
|
+
receiptUrl: string;
|
|
108
|
+
receiptApiUrl: string;
|
|
109
|
+
settlementTxId?: string | null;
|
|
110
|
+
accordSettlementId?: string;
|
|
111
|
+
receiptStorage?: {
|
|
112
|
+
ok: boolean;
|
|
113
|
+
skipped?: boolean;
|
|
114
|
+
reason?: string;
|
|
115
|
+
path?: string;
|
|
116
|
+
aliases?: string[];
|
|
117
|
+
error?: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
interface SagePremiumPaymentRequired {
|
|
121
|
+
error: "premium_payment_required";
|
|
122
|
+
reason?: SagePremiumReason;
|
|
123
|
+
rationale?: string;
|
|
124
|
+
}
|
|
125
|
+
type SageChatTier = "free" | "premium";
|
|
126
|
+
type SageChatStreamEvent = {
|
|
127
|
+
type: "tier";
|
|
128
|
+
tier: SageChatTier;
|
|
129
|
+
model?: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: "delta";
|
|
132
|
+
text: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: "done";
|
|
135
|
+
stopReason?: string;
|
|
136
|
+
inputTokens?: number;
|
|
137
|
+
outputTokens?: number;
|
|
138
|
+
} | {
|
|
139
|
+
type: "error";
|
|
140
|
+
message: string;
|
|
141
|
+
};
|
|
142
|
+
interface SageChatStreamResult {
|
|
143
|
+
ok: boolean;
|
|
144
|
+
status: number;
|
|
145
|
+
text: string;
|
|
146
|
+
tier?: SageChatTier;
|
|
147
|
+
paymentRequired?: SagePremiumPaymentRequired;
|
|
148
|
+
error?: string;
|
|
149
|
+
}
|
|
150
|
+
interface SageReceiptBundle {
|
|
151
|
+
ok: true;
|
|
152
|
+
type: "sage.receipt_bundle.v1";
|
|
153
|
+
version: "v1";
|
|
154
|
+
id: string;
|
|
155
|
+
status: "settled_on_chain" | "verified_pending_redemption";
|
|
156
|
+
completeness: "full_receipt_bundle" | "full" | "chain_proof_only";
|
|
157
|
+
public_receipt_url: string;
|
|
158
|
+
api_receipt_url: string;
|
|
159
|
+
explorer_url: string | null;
|
|
160
|
+
accord?: {
|
|
161
|
+
agreement_hash?: string | null;
|
|
162
|
+
verification_receipt_hash?: string | null;
|
|
163
|
+
settlement_receipt_hash?: string | null;
|
|
164
|
+
agreement_json?: unknown;
|
|
165
|
+
verification_receipt_json?: unknown;
|
|
166
|
+
settlement_receipt_json?: unknown;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
interface SagePaymentWidgetOptions {
|
|
170
|
+
/**
|
|
171
|
+
* Base URL of the Sage host. Default: ergoblockchain.org.
|
|
172
|
+
*/
|
|
173
|
+
apiBase?: string;
|
|
174
|
+
/**
|
|
175
|
+
* Optional tenant metadata. Current public Sage ignores tenant routing,
|
|
176
|
+
* but the widget keeps this shape stable for multi-tenant deployments.
|
|
177
|
+
*/
|
|
178
|
+
tenant?: SageTenantConfig;
|
|
179
|
+
/** Initial chat messages, useful for preloaded context. */
|
|
180
|
+
initialMessages?: SageChatMessage[];
|
|
181
|
+
/** Placeholder text for the default input. */
|
|
182
|
+
placeholder?: string;
|
|
183
|
+
/** Widget heading. React also accepts this through component props. */
|
|
184
|
+
title?: string;
|
|
185
|
+
/** Optional host-specific payment copy and links. */
|
|
186
|
+
paymentInstructions?: SagePaymentInstructions;
|
|
187
|
+
/** Called whenever a message is appended by the widget. */
|
|
188
|
+
onMessage?: (message: SageChatMessage, messages: SageChatMessage[]) => void;
|
|
189
|
+
/** Called after Sage returns a premium quote. */
|
|
190
|
+
onQuote?: (quote: SageQuoteResponse) => void;
|
|
191
|
+
/** Called after a payment verifies and Sage returns a receipt link. */
|
|
192
|
+
onReceipt?: (receipt: SageVerifyPaymentResponse) => void;
|
|
193
|
+
/** Called after the widget fetches the full machine-readable receipt bundle. */
|
|
194
|
+
onReceiptBundle?: (receipt: SageReceiptBundle) => void;
|
|
195
|
+
/** Called when the chat stream reports free vs premium tier. */
|
|
196
|
+
onTier?: (tier: SageChatTier) => void;
|
|
197
|
+
/** Called when the widget phase changes. */
|
|
198
|
+
onPhase?: (phase: SagePaymentPhase) => void;
|
|
199
|
+
/** Called with a compact state snapshot after important widget events. */
|
|
200
|
+
onStatus?: (status: SagePaymentWidgetStatus) => void;
|
|
201
|
+
/** Optional callback fired on fetch or stream errors. */
|
|
202
|
+
onError?: (error: unknown) => void;
|
|
203
|
+
}
|
|
204
|
+
type SagePaymentPhase = "idle" | "quoting" | "payment_required" | "verifying" | "streaming" | "error";
|
|
205
|
+
interface SagePaymentInstructions {
|
|
206
|
+
/** Short copy displayed above the Note box input. */
|
|
207
|
+
helperText?: string;
|
|
208
|
+
/** Optional link to host payment/wallet instructions. */
|
|
209
|
+
walletUrl?: string;
|
|
210
|
+
/** Optional custom label for the Note box input. */
|
|
211
|
+
noteBoxLabel?: string;
|
|
212
|
+
}
|
|
213
|
+
interface SagePaymentWidgetStatus {
|
|
214
|
+
phase: SagePaymentPhase;
|
|
215
|
+
tier: SageChatTier | null;
|
|
216
|
+
quote: SageQuoteResponse["quote"] | null;
|
|
217
|
+
receipt: SageVerifyPaymentResponse | null;
|
|
218
|
+
receiptBundle: SageReceiptBundle | null;
|
|
219
|
+
error: string | null;
|
|
220
|
+
/** Latest chat transcript known to the widget. */
|
|
221
|
+
messages: SageChatMessage[];
|
|
222
|
+
/** Question currently tied to the active quote/payment cycle. */
|
|
223
|
+
activeQuestion: string | null;
|
|
224
|
+
}
|
|
225
|
+
declare const DEFAULT_API_BASE = "https://www.ergoblockchain.org";
|
|
226
|
+
declare const DEFAULT_LIMIT = 5;
|
|
227
|
+
declare const DEFAULT_REFRESH_MS = 60000;
|
|
228
|
+
|
|
229
|
+
export { DEFAULT_API_BASE as D, type SageActivityEvent as S, DEFAULT_LIMIT as a, DEFAULT_REFRESH_MS as b, type SageActivityResponse as c, type SageActivityType as d, type SageChatMessage as e, type SageChatRole as f, type SageChatStreamEvent as g, type SageChatStreamResult as h, type SageChatTier as i, type SagePaymentInstructions as j, type SagePaymentPhase as k, type SagePaymentWidgetOptions as l, type SagePaymentWidgetStatus as m, type SagePremiumPaymentRequired as n, type SagePremiumReason as o, type SageQuote as p, type SageQuoteResponse as q, type SageReceiptBundle as r, type SageTenantConfig as s, type SageVerifyPaymentResponse as t, type SageWidgetOptions as u };
|