@cogcoin/client 1.1.2 → 1.1.3

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.
@@ -65,18 +65,55 @@ function annotateProviderCandidates(options) {
65
65
  },
66
66
  }));
67
67
  }
68
- function parseProviderJsonResponse(options) {
69
- const response = parseStrictJsonValue(stripMarkdownCodeFence(options.raw), `${options.providerLabel} returned invalid JSON.`);
68
+ const ANTHROPIC_MINING_RESPONSE_TOOL_NAME = "return_mining_candidates";
69
+ const ANTHROPIC_MINING_RESPONSE_TOOL = {
70
+ name: ANTHROPIC_MINING_RESPONSE_TOOL_NAME,
71
+ description: [
72
+ "Return the Cogcoin mining sentence generation result in structured form.",
73
+ "Use this tool exactly once instead of writing prose, markdown, or code fences.",
74
+ "Set schemaVersion to 1, copy the requestId exactly, and include only candidates for domainId values from rootDomains.",
75
+ "Each candidate sentence must be a single natural-language sentence with no surrounding commentary.",
76
+ ].join(" "),
77
+ input_schema: {
78
+ type: "object",
79
+ properties: {
80
+ schemaVersion: { type: "integer" },
81
+ requestId: { type: "string" },
82
+ candidates: {
83
+ type: "array",
84
+ items: {
85
+ type: "object",
86
+ properties: {
87
+ domainId: { type: "integer" },
88
+ sentence: { type: "string" },
89
+ },
90
+ required: ["domainId", "sentence"],
91
+ additionalProperties: false,
92
+ },
93
+ },
94
+ },
95
+ required: ["schemaVersion", "requestId", "candidates"],
96
+ additionalProperties: false,
97
+ },
98
+ };
99
+ function normalizeProviderCandidateResponse(options) {
70
100
  try {
71
101
  return normalizeMiningSentenceResponse({
72
102
  request: options.request,
73
- response,
103
+ response: options.response,
74
104
  }).candidates;
75
105
  }
76
106
  catch (error) {
77
107
  throw new Error(error instanceof Error ? error.message : `${options.providerLabel} returned an invalid response.`);
78
108
  }
79
109
  }
110
+ function parseProviderJsonResponse(options) {
111
+ return normalizeProviderCandidateResponse({
112
+ response: parseStrictJsonValue(stripMarkdownCodeFence(options.raw), `${options.providerLabel} returned invalid JSON.`),
113
+ request: options.request,
114
+ providerLabel: options.providerLabel,
115
+ });
116
+ }
80
117
  function createProviderSignal(signal, timeoutMs) {
81
118
  const controller = new AbortController();
82
119
  let didTimeout = false;
@@ -179,6 +216,11 @@ async function requestBuiltInSentences(options) {
179
216
  content: buildUserPrompt(options.request),
180
217
  },
181
218
  ],
219
+ tools: [ANTHROPIC_MINING_RESPONSE_TOOL],
220
+ tool_choice: {
221
+ type: "tool",
222
+ name: ANTHROPIC_MINING_RESPONSE_TOOL_NAME,
223
+ },
182
224
  }),
183
225
  signal: providerSignal.signal,
184
226
  });
@@ -199,8 +241,8 @@ async function requestBuiltInSentences(options) {
199
241
  throw new MiningProviderRequestError("unavailable", `The built-in Anthropic mining provider returned HTTP ${response.status}.`);
200
242
  }
201
243
  return annotateProviderCandidates({
202
- candidates: parseProviderJsonResponse({
203
- raw: extractAnthropicText(await response.json()),
244
+ candidates: normalizeProviderCandidateResponse({
245
+ response: extractAnthropicResponsePayload(await response.json()),
204
246
  request: options.request,
205
247
  providerLabel: "The built-in Anthropic mining provider",
206
248
  }),
@@ -280,6 +322,24 @@ function extractAnthropicText(payload) {
280
322
  }
281
323
  throw new Error("The built-in Anthropic mining provider returned an empty response.");
282
324
  }
325
+ function extractAnthropicResponsePayload(payload) {
326
+ if (payload !== null && typeof payload === "object") {
327
+ const content = payload.content;
328
+ if (Array.isArray(content)) {
329
+ for (const entry of content) {
330
+ if (entry === null || typeof entry !== "object") {
331
+ continue;
332
+ }
333
+ const typedEntry = entry;
334
+ if (typedEntry.type === "tool_use"
335
+ && typedEntry.name === ANTHROPIC_MINING_RESPONSE_TOOL_NAME) {
336
+ return typedEntry.input;
337
+ }
338
+ }
339
+ }
340
+ }
341
+ return parseStrictJsonValue(stripMarkdownCodeFence(extractAnthropicText(payload)), "The built-in Anthropic mining provider returned invalid JSON.");
342
+ }
283
343
  export async function generateMiningSentences(request, options) {
284
344
  const config = await loadClientConfig({
285
345
  path: options.paths.clientConfigPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cogcoin/client",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Store-backed Cogcoin client with wallet flows, SQLite persistence, and managed Bitcoin Core integration.",
5
5
  "license": "MIT",
6
6
  "type": "module",