@goodz-core/sdk 0.1.0 → 0.3.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 +350 -0
- package/dist/alive/index.d.ts +175 -0
- package/dist/alive/index.js +4 -0
- package/dist/alive/index.js.map +1 -0
- package/dist/chunk-4SU7SU7K.js +227 -0
- package/dist/chunk-4SU7SU7K.js.map +1 -0
- package/dist/chunk-7O6UN2D2.js +102 -0
- package/dist/chunk-7O6UN2D2.js.map +1 -0
- package/dist/chunk-JAVMQXJM.js +27 -0
- package/dist/chunk-JAVMQXJM.js.map +1 -0
- package/dist/chunk-K6IFJWLB.js +924 -0
- package/dist/chunk-K6IFJWLB.js.map +1 -0
- package/dist/chunk-MUZDYQ67.js +56 -0
- package/dist/chunk-MUZDYQ67.js.map +1 -0
- package/dist/chunk-OUKZ2PRD.js +37 -0
- package/dist/chunk-OUKZ2PRD.js.map +1 -0
- package/dist/commerce/index.d.ts +407 -0
- package/dist/commerce/index.js +4 -0
- package/dist/commerce/index.js.map +1 -0
- package/dist/core/index.d.ts +76 -385
- package/dist/core/index.js +5 -1
- package/dist/exchange/index.d.ts +252 -0
- package/dist/exchange/index.js +4 -0
- package/dist/exchange/index.js.map +1 -0
- package/dist/index.d.ts +34 -4
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/transport-BOlScYEv.d.ts +377 -0
- package/dist/ui/index.d.ts +56 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +43 -3
- package/dist/chunk-G7NKU6PT.js +0 -183
- package/dist/chunk-G7NKU6PT.js.map +0 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import superjson from 'superjson';
|
|
2
|
+
|
|
3
|
+
// src/transport.ts
|
|
4
|
+
var GoodZApiError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
httpStatus;
|
|
7
|
+
path;
|
|
8
|
+
zodErrors;
|
|
9
|
+
data;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts.message);
|
|
12
|
+
this.name = "GoodZApiError";
|
|
13
|
+
this.code = opts.code;
|
|
14
|
+
this.httpStatus = opts.httpStatus;
|
|
15
|
+
this.path = opts.path;
|
|
16
|
+
this.zodErrors = opts.zodErrors;
|
|
17
|
+
this.data = opts.data;
|
|
18
|
+
}
|
|
19
|
+
/** Human-readable summary including field errors if present. */
|
|
20
|
+
toDetailedString() {
|
|
21
|
+
const parts = [
|
|
22
|
+
`[GoodZApiError] ${this.code} on ${this.path}: ${this.message}`
|
|
23
|
+
];
|
|
24
|
+
if (this.zodErrors?.length) {
|
|
25
|
+
parts.push("Field errors:");
|
|
26
|
+
for (const e of this.zodErrors) {
|
|
27
|
+
parts.push(` - ${e.path.join(".")}: ${e.message} (${e.code})`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return parts.join("\n");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
async function callQuery(config, path, input) {
|
|
34
|
+
const url = `${config.baseUrl}/api/trpc/${path}`;
|
|
35
|
+
const headers = await config.getHeaders();
|
|
36
|
+
const serialized = input !== void 0 ? superjson.serialize(input) : void 0;
|
|
37
|
+
const queryUrl = serialized ? `${url}?input=${encodeURIComponent(JSON.stringify(serialized))}` : url;
|
|
38
|
+
const res = await fetch(queryUrl, {
|
|
39
|
+
method: "GET",
|
|
40
|
+
headers: {
|
|
41
|
+
...headers,
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return parseResponse(res, path);
|
|
46
|
+
}
|
|
47
|
+
async function callMutation(config, path, input) {
|
|
48
|
+
const url = `${config.baseUrl}/api/trpc/${path}`;
|
|
49
|
+
const headers = await config.getHeaders();
|
|
50
|
+
const serialized = input !== void 0 ? superjson.serialize(input) : void 0;
|
|
51
|
+
const res = await fetch(url, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: {
|
|
54
|
+
...headers,
|
|
55
|
+
"Content-Type": "application/json"
|
|
56
|
+
},
|
|
57
|
+
body: serialized ? JSON.stringify(serialized) : void 0
|
|
58
|
+
});
|
|
59
|
+
return parseResponse(res, path);
|
|
60
|
+
}
|
|
61
|
+
async function parseResponse(res, path) {
|
|
62
|
+
const text = await res.text();
|
|
63
|
+
let body;
|
|
64
|
+
try {
|
|
65
|
+
body = JSON.parse(text);
|
|
66
|
+
} catch {
|
|
67
|
+
throw new GoodZApiError({
|
|
68
|
+
message: `Invalid JSON response: ${text.slice(0, 200)}`,
|
|
69
|
+
code: "PARSE_ERROR",
|
|
70
|
+
httpStatus: res.status,
|
|
71
|
+
path
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const envelope = Array.isArray(body) ? body[0] : body;
|
|
75
|
+
if (envelope?.error) {
|
|
76
|
+
const err = envelope.error;
|
|
77
|
+
const errJson = err?.json ?? err;
|
|
78
|
+
const errData = errJson?.data ?? {};
|
|
79
|
+
throw new GoodZApiError({
|
|
80
|
+
message: errJson?.message ?? "Unknown API error",
|
|
81
|
+
code: errData?.code ?? errJson?.code ?? "UNKNOWN",
|
|
82
|
+
httpStatus: errData?.httpStatus ?? res.status,
|
|
83
|
+
path: errData?.path ?? path,
|
|
84
|
+
zodErrors: errData?.zodError?.issues,
|
|
85
|
+
data: errData
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const resultData = envelope?.result?.data;
|
|
89
|
+
if (resultData === void 0) {
|
|
90
|
+
if (res.ok) return void 0;
|
|
91
|
+
throw new GoodZApiError({
|
|
92
|
+
message: `Unexpected response shape from ${path}`,
|
|
93
|
+
code: "UNEXPECTED_RESPONSE",
|
|
94
|
+
httpStatus: res.status,
|
|
95
|
+
path
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (resultData && typeof resultData === "object" && "json" in resultData) {
|
|
99
|
+
return superjson.deserialize(resultData);
|
|
100
|
+
}
|
|
101
|
+
return resultData;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/mcp-transport.ts
|
|
105
|
+
var _mcpRequestId = 0;
|
|
106
|
+
function nextId() {
|
|
107
|
+
return ++_mcpRequestId;
|
|
108
|
+
}
|
|
109
|
+
var _sessionIds = /* @__PURE__ */ new Map();
|
|
110
|
+
async function callMcpTool(config, toolName, args) {
|
|
111
|
+
const url = `${config.baseUrl}/api/mcp`;
|
|
112
|
+
const headers = await config.getHeaders();
|
|
113
|
+
const sessionId = _sessionIds.get(config.baseUrl);
|
|
114
|
+
if (sessionId) {
|
|
115
|
+
headers["mcp-session-id"] = sessionId;
|
|
116
|
+
}
|
|
117
|
+
const body = {
|
|
118
|
+
jsonrpc: "2.0",
|
|
119
|
+
method: "tools/call",
|
|
120
|
+
params: {
|
|
121
|
+
name: toolName,
|
|
122
|
+
arguments: args ?? {}
|
|
123
|
+
},
|
|
124
|
+
id: nextId()
|
|
125
|
+
};
|
|
126
|
+
const res = await fetch(url, {
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: {
|
|
129
|
+
...headers,
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
Accept: "application/json, text/event-stream"
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify(body)
|
|
134
|
+
});
|
|
135
|
+
const newSessionId = res.headers.get("mcp-session-id");
|
|
136
|
+
if (newSessionId) {
|
|
137
|
+
_sessionIds.set(config.baseUrl, newSessionId);
|
|
138
|
+
}
|
|
139
|
+
const contentType = res.headers.get("content-type") || "";
|
|
140
|
+
if (contentType.includes("text/event-stream")) {
|
|
141
|
+
return parseSseResponse(res, toolName);
|
|
142
|
+
}
|
|
143
|
+
const text = await res.text();
|
|
144
|
+
return parseJsonRpcResponse(text, res.status, toolName);
|
|
145
|
+
}
|
|
146
|
+
function parseJsonRpcResponse(text, httpStatus, toolName) {
|
|
147
|
+
let body;
|
|
148
|
+
try {
|
|
149
|
+
body = JSON.parse(text);
|
|
150
|
+
} catch {
|
|
151
|
+
throw new GoodZApiError({
|
|
152
|
+
message: `Invalid JSON response from MCP tool ${toolName}: ${text.slice(0, 200)}`,
|
|
153
|
+
code: "PARSE_ERROR",
|
|
154
|
+
httpStatus,
|
|
155
|
+
path: toolName
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (body.error) {
|
|
159
|
+
throw new GoodZApiError({
|
|
160
|
+
message: body.error.message || "MCP tool error",
|
|
161
|
+
code: body.error.code?.toString() || "MCP_ERROR",
|
|
162
|
+
httpStatus,
|
|
163
|
+
path: toolName,
|
|
164
|
+
data: body.error.data
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return extractMcpResult(body.result, toolName, httpStatus);
|
|
168
|
+
}
|
|
169
|
+
async function parseSseResponse(res, toolName) {
|
|
170
|
+
const text = await res.text();
|
|
171
|
+
const lines = text.split("\n");
|
|
172
|
+
let lastData = null;
|
|
173
|
+
for (const line of lines) {
|
|
174
|
+
if (line.startsWith("data:")) {
|
|
175
|
+
lastData = line.slice(5).trim();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!lastData) {
|
|
179
|
+
throw new GoodZApiError({
|
|
180
|
+
message: `Empty SSE response from MCP tool ${toolName}`,
|
|
181
|
+
code: "EMPTY_RESPONSE",
|
|
182
|
+
httpStatus: res.status,
|
|
183
|
+
path: toolName
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return parseJsonRpcResponse(lastData, res.status, toolName);
|
|
187
|
+
}
|
|
188
|
+
function extractMcpResult(result, toolName, httpStatus) {
|
|
189
|
+
if (!result) {
|
|
190
|
+
throw new GoodZApiError({
|
|
191
|
+
message: `No result from MCP tool ${toolName}`,
|
|
192
|
+
code: "EMPTY_RESULT",
|
|
193
|
+
httpStatus,
|
|
194
|
+
path: toolName
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const content = result.content;
|
|
198
|
+
if (Array.isArray(content)) {
|
|
199
|
+
const textBlock = content.find((c) => c.type === "text");
|
|
200
|
+
if (textBlock?.text) {
|
|
201
|
+
if (result.isError) {
|
|
202
|
+
throw new GoodZApiError({
|
|
203
|
+
message: textBlock.text,
|
|
204
|
+
code: "MCP_TOOL_ERROR",
|
|
205
|
+
httpStatus,
|
|
206
|
+
path: toolName
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
return JSON.parse(textBlock.text);
|
|
211
|
+
} catch {
|
|
212
|
+
return textBlock.text;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
function createMcpTransportConfig(baseUrl, getHeaders) {
|
|
219
|
+
return {
|
|
220
|
+
baseUrl: baseUrl.replace(/\/$/, ""),
|
|
221
|
+
getHeaders
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { GoodZApiError, callMcpTool, callMutation, callQuery, createMcpTransportConfig };
|
|
226
|
+
//# sourceMappingURL=chunk-4SU7SU7K.js.map
|
|
227
|
+
//# sourceMappingURL=chunk-4SU7SU7K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport.ts","../src/mcp-transport.ts"],"names":[],"mappings":";;;AAmBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvB,IAAA;AAAA,EACA,UAAA;AAAA,EACA,IAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EAEhB,YAAY,IAAA,EAOT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,aAAa,IAAA,CAAK,UAAA;AACvB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AAAA,EACnB;AAAA;AA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AAA,UACnB,IAAA,EAAM,gBAAA;AAAA,UACN,UAAA;AAAA,UACA,IAAA,EAAM;AAAA,SACP,CAAA;AAAA,MACH;AAGA,MAAA,IAAI;AACF,QAAA,OAAO,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,IAAI,CAAA;AAAA,MAClC,CAAA,CAAA,MAAQ;AAEN,QAAA,OAAO,SAAA,CAAU,IAAA;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AAGA,EAAA,OAAO,MAAA;AACT;AAOO,SAAS,wBAAA,CACd,SACA,UAAA,EACiB;AACjB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAAA,IAClC;AAAA,GACF;AACF","file":"chunk-4SU7SU7K.js","sourcesContent":["/**\n * @goodz-core/sdk — HTTP Transport Layer\n *\n * Speaks the tRPC v11 HTTP wire protocol directly using fetch.\n * Handles superjson serialization, batching, and error parsing.\n *\n * Wire format reference:\n * - Queries: GET /api/trpc/{procedure}?input={superjson-encoded}\n * - Mutations: POST /api/trpc/{procedure} body: {superjson-encoded}\n * - Batch: GET /api/trpc/{p1},{p2}?input={0: ..., 1: ...}\n *\n * @internal\n */\n\nimport superjson from \"superjson\";\nimport type { GoodZApiFieldError } from \"./types\";\n\n// ─── Error class ─────────────────────────────────────────────\n\nexport class GoodZApiError extends Error {\n public readonly code: string;\n public readonly httpStatus: number;\n public readonly path: string;\n public readonly zodErrors?: GoodZApiFieldError[];\n public readonly data?: unknown;\n\n constructor(opts: {\n message: string;\n code: string;\n httpStatus: number;\n path: string;\n zodErrors?: GoodZApiFieldError[];\n data?: unknown;\n }) {\n super(opts.message);\n this.name = \"GoodZApiError\";\n this.code = opts.code;\n this.httpStatus = opts.httpStatus;\n this.path = opts.path;\n this.zodErrors = opts.zodErrors;\n this.data = opts.data;\n }\n\n /** Human-readable summary including field errors if present. */\n toDetailedString(): string {\n const parts = [\n `[GoodZApiError] ${this.code} on ${this.path}: ${this.message}`,\n ];\n if (this.zodErrors?.length) {\n parts.push(\"Field errors:\");\n for (const e of this.zodErrors) {\n parts.push(` - ${e.path.join(\".\")}: ${e.message} (${e.code})`);\n }\n }\n return parts.join(\"\\n\");\n }\n}\n\n// ─── Transport config ────────────────────────────────────────\n\nexport interface TransportConfig {\n baseUrl: string;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n}\n\n// ─── Core transport functions ────────────────────────────────\n\n/**\n * Call a tRPC query (GET request).\n * Uses POST with method override for compatibility with Commerce/Exchange\n * server-to-server patterns (some proxies strip GET bodies).\n */\nexport async function callQuery<TInput, TOutput>(\n config: TransportConfig,\n path: string,\n input?: TInput,\n): Promise<TOutput> {\n const url = `${config.baseUrl}/api/trpc/${path}`;\n const headers = await config.getHeaders();\n\n // Use GET with query params for queries (standard tRPC)\n const serialized = input !== undefined ? superjson.serialize(input) : undefined;\n const queryUrl = serialized\n ? `${url}?input=${encodeURIComponent(JSON.stringify(serialized))}`\n : url;\n\n const res = await fetch(queryUrl, {\n method: \"GET\",\n headers: {\n ...headers,\n \"Content-Type\": \"application/json\",\n },\n });\n\n return parseResponse<TOutput>(res, path);\n}\n\n/**\n * Call a tRPC mutation (POST request).\n */\nexport async function callMutation<TInput, TOutput>(\n config: TransportConfig,\n path: string,\n input?: TInput,\n): Promise<TOutput> {\n const url = `${config.baseUrl}/api/trpc/${path}`;\n const headers = await config.getHeaders();\n\n const serialized = input !== undefined ? superjson.serialize(input) : undefined;\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: {\n ...headers,\n \"Content-Type\": \"application/json\",\n },\n body: serialized ? JSON.stringify(serialized) : undefined,\n });\n\n return parseResponse<TOutput>(res, path);\n}\n\n// ─── Response parser ─────────────────────────────────────────\n\nasync function parseResponse<T>(res: Response, path: string): Promise<T> {\n const text = await res.text();\n let body: any;\n\n try {\n body = JSON.parse(text);\n } catch {\n throw new GoodZApiError({\n message: `Invalid JSON response: ${text.slice(0, 200)}`,\n code: \"PARSE_ERROR\",\n httpStatus: res.status,\n path,\n });\n }\n\n // tRPC wraps responses in { result: { data: ... } }\n // Batch responses are arrays: [{ result: { data: ... } }]\n const envelope = Array.isArray(body) ? body[0] : body;\n\n // Check for tRPC error envelope\n if (envelope?.error) {\n const err = envelope.error;\n const errJson = err?.json ?? err;\n const errData = errJson?.data ?? {};\n\n throw new GoodZApiError({\n message: errJson?.message ?? \"Unknown API error\",\n code: errData?.code ?? errJson?.code ?? \"UNKNOWN\",\n httpStatus: errData?.httpStatus ?? res.status,\n path: errData?.path ?? path,\n zodErrors: errData?.zodError?.issues,\n data: errData,\n });\n }\n\n // Success path: extract and deserialize the data\n const resultData = envelope?.result?.data;\n if (resultData === undefined) {\n // Some queries return null/undefined legitimately\n if (res.ok) return undefined as T;\n\n throw new GoodZApiError({\n message: `Unexpected response shape from ${path}`,\n code: \"UNEXPECTED_RESPONSE\",\n httpStatus: res.status,\n path,\n });\n }\n\n // superjson wraps data in { json: ..., meta?: ... }\n // Check if it's a superjson envelope\n if (resultData && typeof resultData === \"object\" && \"json\" in resultData) {\n return superjson.deserialize(resultData) as T;\n }\n\n // Plain JSON (shouldn't happen with superjson transformer, but be safe)\n return resultData as T;\n}\n","/**\n * @goodz-core/sdk — MCP Transport Layer\n *\n * Speaks the MCP (Model Context Protocol) JSON-RPC 2.0 wire format\n * used by Commerce, Exchange, and Alive sub-sites.\n *\n * Wire format:\n * POST /api/mcp\n * Content-Type: application/json\n * Authorization: Bearer <token>\n *\n * { \"jsonrpc\": \"2.0\", \"method\": \"tools/call\", \"params\": { \"name\": \"<tool>\", \"arguments\": { ... } }, \"id\": 1 }\n *\n * Response:\n * { \"jsonrpc\": \"2.0\", \"result\": { \"content\": [{ \"type\": \"text\", \"text\": \"<json>\" }] }, \"id\": 1 }\n *\n * @internal\n */\n\nimport { GoodZApiError } from \"./transport\";\nimport type { TransportConfig } from \"./transport\";\n\n// Re-export for convenience\nexport type { TransportConfig };\n\n// ─── MCP request counter ────────────────────────────────────\n\nlet _mcpRequestId = 0;\nfunction nextId(): number {\n return ++_mcpRequestId;\n}\n\n// ─── Session management ─────────────────────────────────────\n\nconst _sessionIds = new Map<string, string>();\n\n// ─── Core MCP call function ─────────────────────────────────\n\n/**\n * Call an MCP tool on a sub-site.\n *\n * Handles:\n * - JSON-RPC 2.0 envelope construction\n * - Session ID management (mcp-session-id header)\n * - Response parsing (extracts JSON from text content)\n * - Error mapping to GoodZApiError\n */\nexport async function callMcpTool<TInput extends Record<string, any>, TOutput>(\n config: TransportConfig,\n toolName: string,\n args?: TInput,\n): Promise<TOutput> {\n const url = `${config.baseUrl}/api/mcp`;\n const headers = await config.getHeaders();\n\n // Add session ID if we have one for this endpoint\n const sessionId = _sessionIds.get(config.baseUrl);\n if (sessionId) {\n headers[\"mcp-session-id\"] = sessionId;\n }\n\n const body = {\n jsonrpc: \"2.0\" as const,\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args ?? {},\n },\n id: nextId(),\n };\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: {\n ...headers,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json, text/event-stream\",\n },\n body: JSON.stringify(body),\n });\n\n // Store session ID from response\n const newSessionId = res.headers.get(\"mcp-session-id\");\n if (newSessionId) {\n _sessionIds.set(config.baseUrl, newSessionId);\n }\n\n // Handle SSE responses (some MCP servers use streaming)\n const contentType = res.headers.get(\"content-type\") || \"\";\n if (contentType.includes(\"text/event-stream\")) {\n return parseSseResponse<TOutput>(res, toolName);\n }\n\n // Standard JSON response\n const text = await res.text();\n return parseJsonRpcResponse<TOutput>(text, res.status, toolName);\n}\n\n// ─── Response parsers ───────────────────────────────────────\n\nfunction parseJsonRpcResponse<T>(\n text: string,\n httpStatus: number,\n toolName: string,\n): T {\n let body: any;\n try {\n body = JSON.parse(text);\n } catch {\n throw new GoodZApiError({\n message: `Invalid JSON response from MCP tool ${toolName}: ${text.slice(0, 200)}`,\n code: \"PARSE_ERROR\",\n httpStatus,\n path: toolName,\n });\n }\n\n // JSON-RPC error\n if (body.error) {\n throw new GoodZApiError({\n message: body.error.message || \"MCP tool error\",\n code: body.error.code?.toString() || \"MCP_ERROR\",\n httpStatus,\n path: toolName,\n data: body.error.data,\n });\n }\n\n // Extract result from MCP content array\n return extractMcpResult<T>(body.result, toolName, httpStatus);\n}\n\nasync function parseSseResponse<T>(\n res: Response,\n toolName: string,\n): Promise<T> {\n const text = await res.text();\n const lines = text.split(\"\\n\");\n\n // Find the last \"data:\" line that contains a JSON-RPC response\n let lastData: string | null = null;\n for (const line of lines) {\n if (line.startsWith(\"data:\")) {\n lastData = line.slice(5).trim();\n }\n }\n\n if (!lastData) {\n throw new GoodZApiError({\n message: `Empty SSE response from MCP tool ${toolName}`,\n code: \"EMPTY_RESPONSE\",\n httpStatus: res.status,\n path: toolName,\n });\n }\n\n return parseJsonRpcResponse<T>(lastData, res.status, toolName);\n}\n\nfunction extractMcpResult<T>(\n result: any,\n toolName: string,\n httpStatus: number,\n): T {\n if (!result) {\n throw new GoodZApiError({\n message: `No result from MCP tool ${toolName}`,\n code: \"EMPTY_RESULT\",\n httpStatus,\n path: toolName,\n });\n }\n\n // MCP tools return { content: [{ type: \"text\", text: \"...\" }] }\n const content = result.content;\n if (Array.isArray(content)) {\n // Find the first text content block\n const textBlock = content.find((c: any) => c.type === \"text\");\n if (textBlock?.text) {\n // Check if the tool returned an error in the text\n if (result.isError) {\n throw new GoodZApiError({\n message: textBlock.text,\n code: \"MCP_TOOL_ERROR\",\n httpStatus,\n path: toolName,\n });\n }\n\n // Try to parse as JSON\n try {\n return JSON.parse(textBlock.text) as T;\n } catch {\n // If not JSON, return the text as-is (some tools return plain text)\n return textBlock.text as T;\n }\n }\n }\n\n // Fallback: return the result directly\n return result as T;\n}\n\n// ─── MCP transport config builder ───────────────────────────\n\n/**\n * Create a TransportConfig for an MCP sub-site endpoint.\n */\nexport function createMcpTransportConfig(\n baseUrl: string,\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>,\n): TransportConfig {\n return {\n baseUrl: baseUrl.replace(/\\/$/, \"\"),\n getHeaders,\n };\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createCommerceNamespace } from './chunk-MUZDYQ67.js';
|
|
2
|
+
import { createExchangeNamespace } from './chunk-OUKZ2PRD.js';
|
|
3
|
+
import { createAliveNamespace } from './chunk-JAVMQXJM.js';
|
|
4
|
+
import { createMcpTransportConfig, callMutation, callQuery } from './chunk-4SU7SU7K.js';
|
|
5
|
+
|
|
6
|
+
// src/core/index.ts
|
|
7
|
+
var DEFAULT_CORE_URL = "https://goodzcore.manus.space";
|
|
8
|
+
var DEFAULT_COMMERCE_URL = "https://goodzcommerce.manus.space";
|
|
9
|
+
var DEFAULT_EXCHANGE_URL = "https://goodzexchange.manus.space";
|
|
10
|
+
var DEFAULT_ALIVE_URL = "https://goodzalive.manus.space";
|
|
11
|
+
function createGoodZClient(config = {}) {
|
|
12
|
+
const {
|
|
13
|
+
coreUrl = DEFAULT_CORE_URL,
|
|
14
|
+
commerceUrl = DEFAULT_COMMERCE_URL,
|
|
15
|
+
exchangeUrl = DEFAULT_EXCHANGE_URL,
|
|
16
|
+
aliveUrl = DEFAULT_ALIVE_URL,
|
|
17
|
+
accessToken,
|
|
18
|
+
getAccessToken,
|
|
19
|
+
headers: customHeaders
|
|
20
|
+
} = config;
|
|
21
|
+
const buildHeaders = async () => {
|
|
22
|
+
const h = { ...customHeaders };
|
|
23
|
+
const token = getAccessToken ? await getAccessToken() : accessToken;
|
|
24
|
+
if (token) {
|
|
25
|
+
h["Authorization"] = `Bearer ${token}`;
|
|
26
|
+
}
|
|
27
|
+
return h;
|
|
28
|
+
};
|
|
29
|
+
const coreTransport = {
|
|
30
|
+
baseUrl: coreUrl.replace(/\/$/, ""),
|
|
31
|
+
getHeaders: buildHeaders
|
|
32
|
+
};
|
|
33
|
+
const commerceTransport = createMcpTransportConfig(commerceUrl, buildHeaders);
|
|
34
|
+
const exchangeTransport = createMcpTransportConfig(exchangeUrl, buildHeaders);
|
|
35
|
+
const aliveTransport = createMcpTransportConfig(aliveUrl, buildHeaders);
|
|
36
|
+
const q = (path) => (input) => callQuery(coreTransport, path, input);
|
|
37
|
+
const m = (path) => (input) => callMutation(coreTransport, path, input);
|
|
38
|
+
return {
|
|
39
|
+
// ── zcoin ──────────────────────────────────────────────
|
|
40
|
+
zcoin: {
|
|
41
|
+
getMyBalance: q("zcoin.getMyBalance"),
|
|
42
|
+
getMyHistory: q("zcoin.getMyHistory"),
|
|
43
|
+
getDepositPackages: q("zcoin.getDepositPackages"),
|
|
44
|
+
createDepositOrder: m("zcoin.createDepositOrder"),
|
|
45
|
+
getDepositStatus: q("zcoin.getDepositStatus"),
|
|
46
|
+
commercialTransfer: m("zcoin.commercialTransfer"),
|
|
47
|
+
mintAndCharge: m("zcoin.mintAndCharge"),
|
|
48
|
+
chargeUser: m("zcoin.chargeUser"),
|
|
49
|
+
createDirectPurchaseOrder: m("zcoin.createDirectPurchaseOrder")
|
|
50
|
+
},
|
|
51
|
+
// ── inventory ──────────────────────────────────────────
|
|
52
|
+
inventory: {
|
|
53
|
+
getUserInventory: q("inventory.getUserInventory"),
|
|
54
|
+
confirmOwnership: q("inventory.confirmOwnership"),
|
|
55
|
+
mint: m("inventory.mint"),
|
|
56
|
+
transfer: m("inventory.transfer"),
|
|
57
|
+
transferByCard: m("inventory.transferByCard"),
|
|
58
|
+
grantMintAuth: m("inventory.grantMintAuth"),
|
|
59
|
+
transferHistory: q("inventory.transferHistory")
|
|
60
|
+
},
|
|
61
|
+
// ── collectible ────────────────────────────────────────
|
|
62
|
+
collectible: {
|
|
63
|
+
getInstanceById: q("collectible.getInstanceById"),
|
|
64
|
+
getPublicInstance: q("collectible.getPublicInstance"),
|
|
65
|
+
getPublicInstancesBatch: q("collectible.getPublicInstancesBatch"),
|
|
66
|
+
getCardProfile: q("collectible.getCardProfile"),
|
|
67
|
+
getShellImageUrl: q("collectible.getShellImageUrl")
|
|
68
|
+
},
|
|
69
|
+
// ── user ───────────────────────────────────────────────
|
|
70
|
+
user: {
|
|
71
|
+
getPublicProfile: q("user.getPublicProfile"),
|
|
72
|
+
getPublicProfileById: q("user.getPublicProfileById")
|
|
73
|
+
},
|
|
74
|
+
// ── auth ───────────────────────────────────────────────
|
|
75
|
+
auth: {
|
|
76
|
+
me: q("auth.me"),
|
|
77
|
+
getOAuthAppInfo: q("auth.getOAuthAppInfo")
|
|
78
|
+
},
|
|
79
|
+
// ── ip (franchise/series/card) ─────────────────────────
|
|
80
|
+
ip: {
|
|
81
|
+
getFranchise: q("franchise.get"),
|
|
82
|
+
getSeries: q("series.get"),
|
|
83
|
+
listSeriesByFranchise: q("series.listByFranchise"),
|
|
84
|
+
getCard: q("card.get"),
|
|
85
|
+
listCardsBySeries: q("card.listBySeries")
|
|
86
|
+
},
|
|
87
|
+
// ── commerce (MCP) ─────────────────────────────────────
|
|
88
|
+
commerce: createCommerceNamespace(commerceTransport),
|
|
89
|
+
// ── exchange (MCP) ─────────────────────────────────────
|
|
90
|
+
exchange: createExchangeNamespace(exchangeTransport),
|
|
91
|
+
// ── alive (MCP) ────────────────────────────────────────
|
|
92
|
+
alive: createAliveNamespace(aliveTransport),
|
|
93
|
+
// ── raw escape hatches (Core tRPC only) ────────────────
|
|
94
|
+
rawQuery: (path, input) => callQuery(coreTransport, path, input),
|
|
95
|
+
rawMutation: (path, input) => callMutation(coreTransport, path, input)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
var createUserClient = createGoodZClient;
|
|
99
|
+
|
|
100
|
+
export { createGoodZClient, createUserClient };
|
|
101
|
+
//# sourceMappingURL=chunk-7O6UN2D2.js.map
|
|
102
|
+
//# sourceMappingURL=chunk-7O6UN2D2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/index.ts"],"names":[],"mappings":";;;;;;AAuHA,IAAM,gBAAA,GAAmB,+BAAA;AACzB,IAAM,oBAAA,GAAuB,mCAAA;AAC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BAA2B;AAAA,KACvG;AAAA;AAAA,IAGA,IAAA,EAAM;AAAA,MACJ,EAAA,EAAI,EAAyB,SAAS,CAAA;AAAA,MACtC,eAAA,EAAiB,EAAqD,sBAAsB;AAAA,KAC9F;AAAA;AAAA,IAGA,EAAA,EAAI;AAAA,MACF,YAAA,EAAc,EAA0B,eAAe,CAAA;AAAA,MACvD,SAAA,EAAW,EAAuB,YAAY,CAAA;AAAA,MAC9C,qBAAA,EAAuB,EAAqC,wBAAwB,CAAA;AAAA,MACpF,OAAA,EAAS,EAAqB,UAAU,CAAA;AAAA,MACxC,iBAAA,EAAmB,EAAgC,mBAAmB;AAAA,KACxE;AAAA;AAAA,IAGA,QAAA,EAAU,wBAAwB,iBAAiB,CAAA;AAAA;AAAA,IAGnD,QAAA,EAAU,wBAAwB,iBAAiB,CAAA;AAAA;AAAA,IAGnD,KAAA,EAAO,qBAAqB,cAAc,CAAA;AAAA;AAAA,IAG1C,UAAU,CAAU,IAAA,EAAc,UAAgB,SAAA,CAAkB,aAAA,EAAe,MAAM,KAAK,CAAA;AAAA,IAC9F,aAAa,CAAU,IAAA,EAAc,UAAgB,YAAA,CAAqB,aAAA,EAAe,MAAM,KAAK;AAAA,GACtG;AACF;AAMO,IAAM,gBAAA,GAAmB","file":"chunk-7O6UN2D2.js","sourcesContent":["/**\n * @goodz-core/sdk/core — Unified GoodZ API Client\n *\n * One client, all services. Stripe-style namespace architecture:\n * goodz.zcoin.* → Core settlement & Z-coin\n * goodz.inventory.* → Core instance management\n * goodz.collectible.* → Core card queries\n * goodz.user.* → Core user profiles\n * goodz.auth.* → Core auth\n * goodz.ip.* → Core IP (franchise/series/card)\n * goodz.commerce.* → Commerce/Shops (MCP)\n * goodz.exchange.* → Exchange marketplace (MCP)\n * goodz.alive.* → Alive companions (MCP)\n *\n * Core uses tRPC HTTP wire protocol; sub-sites use MCP JSON-RPC 2.0.\n * The client handles routing transparently.\n *\n * @example\n * ```ts\n * import { createGoodZClient } from \"@goodz-core/sdk\";\n *\n * const goodz = createGoodZClient({\n * accessToken: \"your-jwt-token\",\n * });\n *\n * // Core APIs\n * const balance = await goodz.zcoin.getMyBalance();\n * const result = await goodz.zcoin.commercialTransfer({ ... });\n *\n * // Commerce APIs\n * const shop = await goodz.commerce.createShop({ name: \"My Shop\" });\n * const order = await goodz.commerce.executePurchase({ campaignId: 1, quantity: 1 });\n *\n * // Exchange APIs\n * const listing = await goodz.exchange.createListing({ ... });\n * const data = await goodz.exchange.getMarketData({ coreGoodzId: 42 });\n *\n * // Alive APIs\n * const chat = await goodz.alive.sendMessage({ instanceId: 1, userId: 1, message: \"Hello!\" });\n * const memories = await goodz.alive.recallMemories({ instanceId: 1, userId: 1, query: \"birthday\" });\n * ```\n *\n * @module\n */\n\nimport { callQuery, callMutation, GoodZApiError } from \"../transport\";\nimport type { TransportConfig } from \"../transport\";\nimport { createMcpTransportConfig } from \"../mcp-transport\";\nimport { createCommerceNamespace } from \"../commerce/index\";\nimport type { CommerceNamespace } from \"../commerce/index\";\nimport { createExchangeNamespace } from \"../exchange/index\";\nimport type { ExchangeNamespace } from \"../exchange/index\";\nimport { createAliveNamespace } from \"../alive/index\";\nimport type { AliveNamespace } from \"../alive/index\";\nimport type {\n // zcoin\n ZcoinGetMyBalanceOutput,\n ZcoinGetMyHistoryInput,\n ZcoinCommercialTransferInput,\n ZcoinCommercialTransferOutput,\n ZcoinMintAndChargeInput,\n ZcoinMintAndChargeOutput,\n ZcoinChargeUserInput,\n ZcoinChargeUserOutput,\n ZcoinCreateDirectPurchaseOrderInput,\n ZcoinCreateDirectPurchaseOrderOutput,\n ZcoinGetDepositPackagesInput,\n ZcoinDepositPackage,\n ZcoinCreateDepositOrderInput,\n ZcoinCreateDepositOrderOutput,\n ZcoinGetDepositStatusInput,\n ZcoinGetDepositStatusOutput,\n // inventory\n InventoryGetUserInventoryInput,\n InventoryConfirmOwnershipInput,\n InventoryConfirmOwnershipOutput,\n InventoryMintInput,\n InventoryMintOutput,\n InventoryTransferInput,\n InventoryTransferOutput,\n InventoryTransferByCardInput,\n InventoryTransferByCardOutput,\n InventoryGrantMintAuthInput,\n InventoryTransferHistoryInput,\n // collectible\n CollectibleGetInstanceByIdInput,\n CollectibleGetPublicInstanceInput,\n CollectibleGetPublicInstancesBatchInput,\n CollectibleGetCardProfileInput,\n CollectibleGetShellImageUrlInput,\n // user\n UserGetPublicProfileInput,\n UserPublicProfile,\n UserGetPublicProfileByIdInput,\n // auth\n AuthGetOAuthAppInfoInput,\n AuthOAuthAppInfo,\n AuthUser,\n // ip\n FranchiseGetInput,\n SeriesGetInput,\n SeriesListByFranchiseInput,\n CardGetInput,\n CardListBySeriesInput,\n} from \"../types\";\n\n// ─── Re-export types and error class ─────────────────────────\n\nexport { GoodZApiError } from \"../transport\";\nexport type * from \"../types\";\nexport type * from \"../types-commerce\";\nexport type * from \"../types-exchange\";\nexport type * from \"../types-alive\";\nexport type { CommerceNamespace } from \"../commerce/index\";\nexport type { ExchangeNamespace } from \"../exchange/index\";\nexport type { AliveNamespace } from \"../alive/index\";\n\n// ─── Default sub-site URLs ──────────────────────────────────\n\nconst DEFAULT_CORE_URL = \"https://goodzcore.manus.space\";\nconst DEFAULT_COMMERCE_URL = \"https://goodzcommerce.manus.space\";\nconst DEFAULT_EXCHANGE_URL = \"https://goodzexchange.manus.space\";\nconst DEFAULT_ALIVE_URL = \"https://goodzalive.manus.space\";\n\n// ─── Client config ───────────────────────────────────────────\n\nexport interface GoodZClientConfig {\n /**\n * GoodZ.Core base URL.\n * @default \"https://goodzcore.manus.space\"\n */\n coreUrl?: string;\n\n /**\n * GoodZ.Commerce (Shops) base URL.\n * @default \"https://goodzcommerce.manus.space\"\n */\n commerceUrl?: string;\n\n /**\n * GoodZ.Exchange base URL.\n * @default \"https://goodzexchange.manus.space\"\n */\n exchangeUrl?: string;\n\n /**\n * GoodZ.Alive base URL.\n * @default \"https://goodzalive.manus.space\"\n */\n aliveUrl?: string;\n\n /**\n * Static access token (JWT) for authentication.\n * For server-to-server calls, obtain this via OAuth client_credentials flow.\n * For user-context calls, pass the user's access token.\n */\n accessToken?: string;\n\n /**\n * Dynamic token provider — called before every request.\n * Use this when tokens may rotate (e.g., auto-refresh).\n * Takes precedence over `accessToken` if both are set.\n */\n getAccessToken?: () => string | Promise<string>;\n\n /**\n * Custom headers to include in every request.\n * Useful for passing app identifiers or tracing headers.\n */\n headers?: Record<string, string>;\n}\n\n// ─── Core namespace interfaces (tRPC) ───────────────────────\n\nexport interface ZcoinNamespace {\n /** Get the authenticated user's Z-coin balance. */\n getMyBalance(): Promise<ZcoinGetMyBalanceOutput>;\n\n /** Get the authenticated user's Z-coin transaction history. */\n getMyHistory(input?: ZcoinGetMyHistoryInput): Promise<any[]>;\n\n /** Get available Z-coin deposit packages with pricing. */\n getDepositPackages(input?: ZcoinGetDepositPackagesInput): Promise<ZcoinDepositPackage[]>;\n\n /** Create a Stripe checkout session for Z-coin deposit. */\n createDepositOrder(input: ZcoinCreateDepositOrderInput): Promise<ZcoinCreateDepositOrderOutput>;\n\n /** Check the status of a deposit checkout session. */\n getDepositStatus(input: ZcoinGetDepositStatusInput): Promise<ZcoinGetDepositStatusOutput>;\n\n /**\n * Atomic commercial transfer: Z-coin payment + ownership transfer in one transaction.\n * This is the primary API for Commerce and Exchange purchase flows.\n *\n * Idempotent via referenceId — duplicate calls return the same result.\n *\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n * @throws {GoodZApiError} CONFLICT — version conflict (retry)\n * @throws {GoodZApiError} FORBIDDEN — seller doesn't own instance\n */\n commercialTransfer(input: ZcoinCommercialTransferInput): Promise<ZcoinCommercialTransferOutput>;\n\n /**\n * Mint a new card instance and charge the buyer in one atomic transaction.\n * Used by Commerce for gacha and direct-from-creator purchases.\n *\n * Requires mint authorization (granted via inventory.grantMintAuth).\n * Idempotent via referenceId.\n *\n * @throws {GoodZApiError} FORBIDDEN — no mint authorization\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n */\n mintAndCharge(input: ZcoinMintAndChargeInput): Promise<ZcoinMintAndChargeOutput>;\n\n /**\n * Charge a user's Z-coin balance for an in-app purchase.\n * Used by apps that sell non-GoodZ digital goods/services.\n *\n * Idempotent via appOrderId.\n *\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n * @throws {GoodZApiError} CONFLICT — version conflict\n */\n chargeUser(input: ZcoinChargeUserInput): Promise<ZcoinChargeUserOutput>;\n\n /**\n * Create a direct purchase checkout session (fiat → Z-coin → transfer).\n * Transparent intermediation: user sees fiat price, Core handles conversion.\n */\n createDirectPurchaseOrder(input: ZcoinCreateDirectPurchaseOrderInput): Promise<ZcoinCreateDirectPurchaseOrderOutput>;\n}\n\nexport interface InventoryNamespace {\n /** Get a user's inventory (owned card instances). */\n getUserInventory(input: InventoryGetUserInventoryInput): Promise<any[]>;\n\n /** Check if a user owns at least one instance of a specific card. */\n confirmOwnership(input: InventoryConfirmOwnershipInput): Promise<InventoryConfirmOwnershipOutput>;\n\n /**\n * Mint new card instances. Requires franchise ownership or admin role.\n * For Commerce/Exchange, use zcoin.mintAndCharge instead (includes payment).\n */\n mint(input: InventoryMintInput): Promise<InventoryMintOutput>;\n\n /**\n * Transfer a specific card instance to another user.\n * For commercial transfers, use zcoin.commercialTransfer instead.\n *\n * @deprecated for reason=\"purchase\"|\"trade\" — use commercialTransfer\n */\n transfer(input: InventoryTransferInput): Promise<InventoryTransferOutput>;\n\n /**\n * Transfer card instances by cardId (transfers oldest instances).\n * For commercial transfers, use zcoin.commercialTransfer instead.\n *\n * @deprecated for reason=\"purchase\"|\"trade\" — use commercialTransfer\n */\n transferByCard(input: InventoryTransferByCardInput): Promise<InventoryTransferByCardOutput>;\n\n /**\n * Grant mint authorization to another user/app for a specific card.\n * Required before Commerce can call zcoin.mintAndCharge for that card.\n */\n grantMintAuth(input: InventoryGrantMintAuthInput): Promise<any>;\n\n /** Get transfer/ownership history for an instance, card, or user. */\n transferHistory(input: InventoryTransferHistoryInput): Promise<any[]>;\n}\n\nexport interface CollectibleNamespace {\n /** Get a card instance by its numeric ID. Returns full instance data with card chain. */\n getInstanceById(input: CollectibleGetInstanceByIdInput): Promise<any>;\n\n /** Get a card instance by its instance code (public-facing identifier). */\n getPublicInstance(input: CollectibleGetPublicInstanceInput): Promise<any>;\n\n /** Batch-fetch multiple card instances by their IDs (max 100). */\n getPublicInstancesBatch(input: CollectibleGetPublicInstancesBatchInput): Promise<any[]>;\n\n /** Get the card profile (metadata, rarity, series info). */\n getCardProfile(input: CollectibleGetCardProfileInput): Promise<any>;\n\n /** Get the shell (packaging) image URL for a card. */\n getShellImageUrl(input: CollectibleGetShellImageUrlInput): Promise<any>;\n}\n\nexport interface UserNamespace {\n /** Get a user's public profile by openId. */\n getPublicProfile(input: UserGetPublicProfileInput): Promise<UserPublicProfile>;\n\n /** Get a user's public profile by internal userId. */\n getPublicProfileById(input: UserGetPublicProfileByIdInput): Promise<UserPublicProfile>;\n}\n\nexport interface AuthNamespace {\n /** Get the authenticated user's profile. Returns null if not authenticated. */\n me(): Promise<AuthUser | null>;\n\n /** Get public info about an OAuth app by its client ID. */\n getOAuthAppInfo(input: AuthGetOAuthAppInfoInput): Promise<AuthOAuthAppInfo | null>;\n}\n\nexport interface IpNamespace {\n /** Get a franchise by ID or slug. */\n getFranchise(input: FranchiseGetInput): Promise<any>;\n\n /** Get a series by ID or slug. */\n getSeries(input: SeriesGetInput): Promise<any>;\n\n /** List all series in a franchise. */\n listSeriesByFranchise(input: SeriesListByFranchiseInput): Promise<any[]>;\n\n /** Get a card by ID. */\n getCard(input: CardGetInput): Promise<any>;\n\n /** List all cards in a series. */\n listCardsBySeries(input: CardListBySeriesInput): Promise<any[]>;\n}\n\n// ─── GoodZClient type ────────────────────────────────────────\n\nexport interface GoodZClient {\n // ── Core namespaces (tRPC) ──\n readonly zcoin: ZcoinNamespace;\n readonly inventory: InventoryNamespace;\n readonly collectible: CollectibleNamespace;\n readonly user: UserNamespace;\n readonly auth: AuthNamespace;\n readonly ip: IpNamespace;\n\n // ── Sub-site namespaces (MCP) ──\n readonly commerce: CommerceNamespace;\n readonly exchange: ExchangeNamespace;\n readonly alive: AliveNamespace;\n\n /**\n * Make a raw tRPC query call to Core. Use this for routes not yet covered\n * by the typed namespaces.\n */\n rawQuery<T = any>(path: string, input?: any): Promise<T>;\n\n /**\n * Make a raw tRPC mutation call to Core. Use this for routes not yet covered\n * by the typed namespaces.\n */\n rawMutation<T = any>(path: string, input?: any): Promise<T>;\n}\n\n// ─── Client factory ──────────────────────────────────────────\n\n/**\n * Create a unified GoodZ API client — one client for all services.\n *\n * @example Server-to-server with static token\n * ```ts\n * const goodz = createGoodZClient({\n * accessToken: process.env.CORE_ACCESS_TOKEN,\n * });\n *\n * // Core\n * const balance = await goodz.zcoin.getMyBalance();\n *\n * // Commerce\n * const shop = await goodz.commerce.createShop({ name: \"My Shop\" });\n *\n * // Exchange\n * const listings = await goodz.exchange.browseMarketplace();\n *\n * // Alive\n * const chat = await goodz.alive.sendMessage({ instanceId: 1, userId: 1, message: \"Hi!\" });\n * ```\n *\n * @example With dynamic token provider (auto-refresh)\n * ```ts\n * const goodz = createGoodZClient({\n * getAccessToken: async () => {\n * const token = await refreshTokenIfNeeded();\n * return token;\n * },\n * });\n * ```\n *\n * @example Custom sub-site URLs (e.g., staging environment)\n * ```ts\n * const goodz = createGoodZClient({\n * accessToken: \"...\",\n * coreUrl: \"https://staging-core.goodz.dev\",\n * commerceUrl: \"https://staging-commerce.goodz.dev\",\n * exchangeUrl: \"https://staging-exchange.goodz.dev\",\n * aliveUrl: \"https://staging-alive.goodz.dev\",\n * });\n * ```\n */\nexport function createGoodZClient(config: GoodZClientConfig = {}): GoodZClient {\n const {\n coreUrl = DEFAULT_CORE_URL,\n commerceUrl = DEFAULT_COMMERCE_URL,\n exchangeUrl = DEFAULT_EXCHANGE_URL,\n aliveUrl = DEFAULT_ALIVE_URL,\n accessToken,\n getAccessToken,\n headers: customHeaders,\n } = config;\n\n // Shared header builder — used by both tRPC and MCP transports\n const buildHeaders = async (): Promise<Record<string, string>> => {\n const h: Record<string, string> = { ...customHeaders };\n const token = getAccessToken ? await getAccessToken() : accessToken;\n if (token) {\n h[\"Authorization\"] = `Bearer ${token}`;\n }\n return h;\n };\n\n // ── Core transport (tRPC) ──\n const coreTransport: TransportConfig = {\n baseUrl: coreUrl.replace(/\\/$/, \"\"),\n getHeaders: buildHeaders,\n };\n\n // ── Sub-site transports (MCP) ──\n const commerceTransport = createMcpTransportConfig(commerceUrl, buildHeaders);\n const exchangeTransport = createMcpTransportConfig(exchangeUrl, buildHeaders);\n const aliveTransport = createMcpTransportConfig(aliveUrl, buildHeaders);\n\n // Helper shortcuts for Core tRPC\n const q = <I, O>(path: string) => (input?: I) => callQuery<I, O>(coreTransport, path, input);\n const m = <I, O>(path: string) => (input?: I) => callMutation<I, O>(coreTransport, path, input);\n\n return {\n // ── zcoin ──────────────────────────────────────────────\n zcoin: {\n getMyBalance: q<void, ZcoinGetMyBalanceOutput>(\"zcoin.getMyBalance\"),\n getMyHistory: q<ZcoinGetMyHistoryInput, any[]>(\"zcoin.getMyHistory\"),\n getDepositPackages: q<ZcoinGetDepositPackagesInput, ZcoinDepositPackage[]>(\"zcoin.getDepositPackages\"),\n createDepositOrder: m<ZcoinCreateDepositOrderInput, ZcoinCreateDepositOrderOutput>(\"zcoin.createDepositOrder\"),\n getDepositStatus: q<ZcoinGetDepositStatusInput, ZcoinGetDepositStatusOutput>(\"zcoin.getDepositStatus\"),\n commercialTransfer: m<ZcoinCommercialTransferInput, ZcoinCommercialTransferOutput>(\"zcoin.commercialTransfer\"),\n mintAndCharge: m<ZcoinMintAndChargeInput, ZcoinMintAndChargeOutput>(\"zcoin.mintAndCharge\"),\n chargeUser: m<ZcoinChargeUserInput, ZcoinChargeUserOutput>(\"zcoin.chargeUser\"),\n createDirectPurchaseOrder: m<ZcoinCreateDirectPurchaseOrderInput, ZcoinCreateDirectPurchaseOrderOutput>(\"zcoin.createDirectPurchaseOrder\"),\n },\n\n // ── inventory ──────────────────────────────────────────\n inventory: {\n getUserInventory: q<InventoryGetUserInventoryInput, any[]>(\"inventory.getUserInventory\"),\n confirmOwnership: q<InventoryConfirmOwnershipInput, InventoryConfirmOwnershipOutput>(\"inventory.confirmOwnership\"),\n mint: m<InventoryMintInput, InventoryMintOutput>(\"inventory.mint\"),\n transfer: m<InventoryTransferInput, InventoryTransferOutput>(\"inventory.transfer\"),\n transferByCard: m<InventoryTransferByCardInput, InventoryTransferByCardOutput>(\"inventory.transferByCard\"),\n grantMintAuth: m<InventoryGrantMintAuthInput, any>(\"inventory.grantMintAuth\"),\n transferHistory: q<InventoryTransferHistoryInput, any[]>(\"inventory.transferHistory\"),\n },\n\n // ── collectible ────────────────────────────────────────\n collectible: {\n getInstanceById: q<CollectibleGetInstanceByIdInput, any>(\"collectible.getInstanceById\"),\n getPublicInstance: q<CollectibleGetPublicInstanceInput, any>(\"collectible.getPublicInstance\"),\n getPublicInstancesBatch: q<CollectibleGetPublicInstancesBatchInput, any[]>(\"collectible.getPublicInstancesBatch\"),\n getCardProfile: q<CollectibleGetCardProfileInput, any>(\"collectible.getCardProfile\"),\n getShellImageUrl: q<CollectibleGetShellImageUrlInput, any>(\"collectible.getShellImageUrl\"),\n },\n\n // ── user ───────────────────────────────────────────────\n user: {\n getPublicProfile: q<UserGetPublicProfileInput, UserPublicProfile>(\"user.getPublicProfile\"),\n getPublicProfileById: q<UserGetPublicProfileByIdInput, UserPublicProfile>(\"user.getPublicProfileById\"),\n },\n\n // ── auth ───────────────────────────────────────────────\n auth: {\n me: q<void, AuthUser | null>(\"auth.me\"),\n getOAuthAppInfo: q<AuthGetOAuthAppInfoInput, AuthOAuthAppInfo | null>(\"auth.getOAuthAppInfo\"),\n },\n\n // ── ip (franchise/series/card) ─────────────────────────\n ip: {\n getFranchise: q<FranchiseGetInput, any>(\"franchise.get\"),\n getSeries: q<SeriesGetInput, any>(\"series.get\"),\n listSeriesByFranchise: q<SeriesListByFranchiseInput, any[]>(\"series.listByFranchise\"),\n getCard: q<CardGetInput, any>(\"card.get\"),\n listCardsBySeries: q<CardListBySeriesInput, any[]>(\"card.listBySeries\"),\n },\n\n // ── commerce (MCP) ─────────────────────────────────────\n commerce: createCommerceNamespace(commerceTransport),\n\n // ── exchange (MCP) ─────────────────────────────────────\n exchange: createExchangeNamespace(exchangeTransport),\n\n // ── alive (MCP) ────────────────────────────────────────\n alive: createAliveNamespace(aliveTransport),\n\n // ── raw escape hatches (Core tRPC only) ────────────────\n rawQuery: <T = any>(path: string, input?: any) => callQuery<any, T>(coreTransport, path, input),\n rawMutation: <T = any>(path: string, input?: any) => callMutation<any, T>(coreTransport, path, input),\n };\n}\n\n/**\n * Alias for createGoodZClient — creates a client acting on behalf of a user.\n * Semantically identical, but makes the intent clearer in server-to-server code.\n */\nexport const createUserClient = createGoodZClient;\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { callMcpTool } from './chunk-4SU7SU7K.js';
|
|
2
|
+
|
|
3
|
+
// src/alive/index.ts
|
|
4
|
+
function createAliveNamespace(transport) {
|
|
5
|
+
const tool = (name) => (input) => callMcpTool(transport, name, input);
|
|
6
|
+
return {
|
|
7
|
+
// Memory
|
|
8
|
+
storeMemory: tool("store_memory"),
|
|
9
|
+
recallMemories: tool("recall_memories"),
|
|
10
|
+
forgetMemory: tool("forget_memory"),
|
|
11
|
+
// Intimacy
|
|
12
|
+
getIntimacy: tool("get_intimacy"),
|
|
13
|
+
updateIntimacy: tool("update_intimacy"),
|
|
14
|
+
// Context
|
|
15
|
+
buildContext: tool("build_context"),
|
|
16
|
+
// Intent
|
|
17
|
+
classifyIntent: tool("classify_intent"),
|
|
18
|
+
// Chat
|
|
19
|
+
sendMessage: tool("send_message"),
|
|
20
|
+
// Raw escape hatch
|
|
21
|
+
rawTool: (toolName, args) => callMcpTool(transport, toolName, args)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createAliveNamespace };
|
|
26
|
+
//# sourceMappingURL=chunk-JAVMQXJM.js.map
|
|
27
|
+
//# sourceMappingURL=chunk-JAVMQXJM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/alive/index.ts"],"names":[],"mappings":";;;AAqEO,SAAS,qBAAqB,SAAA,EAA4C;AAC/E,EAAA,MAAM,IAAA,GAAO,CAAmC,IAAA,KAC9C,CAAC,UAAc,WAAA,CAAkB,SAAA,EAAW,MAAM,KAAU,CAAA;AAE9D,EAAA,OAAO;AAAA;AAAA,IAEL,WAAA,EAAa,KAAyC,cAAc,CAAA;AAAA,IACpE,cAAA,EAAgB,KAA8C,iBAAiB,CAAA;AAAA,IAC/E,YAAA,EAAc,KAAkC,eAAe,CAAA;AAAA;AAAA,IAG/D,WAAA,EAAa,KAA2C,cAAc,CAAA;AAAA,IACtE,cAAA,EAAgB,KAA8C,iBAAiB,CAAA;AAAA;AAAA,IAG/E,YAAA,EAAc,KAA2C,eAAe,CAAA;AAAA;AAAA,IAGxE,cAAA,EAAgB,KAAsD,iBAAiB,CAAA;AAAA;AAAA,IAGvF,WAAA,EAAa,KAA+C,cAAc,CAAA;AAAA;AAAA,IAG1E,SAAS,CAAU,QAAA,EAAkB,SACnC,WAAA,CAAoC,SAAA,EAAW,UAAU,IAAI;AAAA,GACjE;AACF","file":"chunk-JAVMQXJM.js","sourcesContent":["/**\n * @goodz-core/sdk — Alive Namespace\n *\n * Provides typed access to GoodZ.Alive MCP tools:\n * memory management, intimacy/affection, context building,\n * intent classification, and chat sessions.\n *\n * GoodZ.Alive gives each GoodZ card a \"soul\" — an AI-powered\n * companion that remembers, grows, and responds uniquely.\n *\n * @module\n */\n\nimport { callMcpTool } from \"../mcp-transport\";\nimport type { TransportConfig } from \"../mcp-transport\";\nimport type {\n AliveStoreMemoryInput,\n AliveMemory,\n AliveRecallMemoriesInput,\n AliveForgetMemoryInput,\n AliveGetIntimacyInput,\n AliveIntimacy,\n AliveUpdateIntimacyInput,\n AliveBuildContextInput,\n AliveContext,\n AliveClassifyIntentInput,\n AliveClassifiedIntent,\n AliveSendMessageInput,\n AliveChatResponse,\n} from \"../types-alive\";\n\n// Re-export all Alive types\nexport type * from \"../types-alive\";\n\n// ─── Namespace interface ────────────────────────────────────\n\nexport interface AliveNamespace {\n // Memory\n /** Store a new memory for a character-user pair. */\n storeMemory(input: AliveStoreMemoryInput): Promise<AliveMemory>;\n /** Recall relevant memories using semantic search. */\n recallMemories(input: AliveRecallMemoriesInput): Promise<AliveMemory[]>;\n /** Delete a specific memory. */\n forgetMemory(input: AliveForgetMemoryInput): Promise<any>;\n\n // Intimacy\n /** Get the intimacy/affection state between a character and user. */\n getIntimacy(input: AliveGetIntimacyInput): Promise<AliveIntimacy>;\n /** Update intimacy level (e.g., after a positive/negative interaction). */\n updateIntimacy(input: AliveUpdateIntimacyInput): Promise<AliveIntimacy>;\n\n // Context\n /** Build a full context object for AI generation (profile + memories + history + system prompt). */\n buildContext(input: AliveBuildContextInput): Promise<AliveContext>;\n\n // Intent\n /** Classify a user's message into an intent category. */\n classifyIntent(input: AliveClassifyIntentInput): Promise<AliveClassifiedIntent>;\n\n // Chat\n /** Send a message and get a character response (includes memory, intimacy, and intent processing). */\n sendMessage(input: AliveSendMessageInput): Promise<AliveChatResponse>;\n\n /** Call a raw MCP tool by name. Escape hatch for tools not yet in the typed API. */\n rawTool<T = any>(toolName: string, args?: Record<string, any>): Promise<T>;\n}\n\n// ─── Factory ────────────────────────────────────────────────\n\nexport function createAliveNamespace(transport: TransportConfig): AliveNamespace {\n const tool = <I extends Record<string, any>, O>(name: string) =>\n (input?: I) => callMcpTool<I, O>(transport, name, input as I);\n\n return {\n // Memory\n storeMemory: tool<AliveStoreMemoryInput, AliveMemory>(\"store_memory\"),\n recallMemories: tool<AliveRecallMemoriesInput, AliveMemory[]>(\"recall_memories\"),\n forgetMemory: tool<AliveForgetMemoryInput, any>(\"forget_memory\"),\n\n // Intimacy\n getIntimacy: tool<AliveGetIntimacyInput, AliveIntimacy>(\"get_intimacy\"),\n updateIntimacy: tool<AliveUpdateIntimacyInput, AliveIntimacy>(\"update_intimacy\"),\n\n // Context\n buildContext: tool<AliveBuildContextInput, AliveContext>(\"build_context\"),\n\n // Intent\n classifyIntent: tool<AliveClassifyIntentInput, AliveClassifiedIntent>(\"classify_intent\"),\n\n // Chat\n sendMessage: tool<AliveSendMessageInput, AliveChatResponse>(\"send_message\"),\n\n // Raw escape hatch\n rawTool: <T = any>(toolName: string, args?: Record<string, any>) =>\n callMcpTool<Record<string, any>, T>(transport, toolName, args),\n };\n}\n"]}
|