@quantish/agent 0.1.4 → 0.1.6
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/dist/index.js +43 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2754,12 +2754,27 @@ const result = JSON.parse(data.result.content[0].text);
|
|
|
2754
2754
|
- \`transfer_usdc\`: Send USDC. Args: { toAddress, amount }
|
|
2755
2755
|
|
|
2756
2756
|
### Key Discovery Tools (free, no auth required)
|
|
2757
|
-
Discovery uses a
|
|
2758
|
-
\`\`\`
|
|
2759
|
-
|
|
2760
|
-
|
|
2757
|
+
Discovery uses a SIMPLER request format (not full JSON-RPC):
|
|
2758
|
+
\`\`\`javascript
|
|
2759
|
+
// Discovery API - uses simple { name, arguments } format
|
|
2760
|
+
const response = await fetch('https://quantish.live/mcp/execute', {
|
|
2761
|
+
method: 'POST',
|
|
2762
|
+
headers: {
|
|
2763
|
+
'Content-Type': 'application/json',
|
|
2764
|
+
'X-API-Key': 'qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8'
|
|
2765
|
+
},
|
|
2766
|
+
body: JSON.stringify({
|
|
2767
|
+
name: 'search_markets', // Tool name at top level
|
|
2768
|
+
arguments: { query: 'bitcoin', limit: 5 } // Arguments at top level
|
|
2769
|
+
})
|
|
2770
|
+
});
|
|
2771
|
+
|
|
2772
|
+
// Response is still JSON-RPC wrapped:
|
|
2773
|
+
const data = await response.json();
|
|
2774
|
+
const result = JSON.parse(data.result.content[0].text);
|
|
2761
2775
|
\`\`\`
|
|
2762
2776
|
|
|
2777
|
+
Available Discovery Tools:
|
|
2763
2778
|
- \`search_markets\`: Find markets. Args: { query, limit?, platform?: "polymarket"|"kalshi"|"all" }
|
|
2764
2779
|
- \`get_market_details\`: Get market info. Args: { platform, marketId }
|
|
2765
2780
|
- \`get_trending_markets\`: Popular markets. Args: { limit?, platform? }
|
|
@@ -2886,29 +2901,25 @@ console.log('Order placed:', orderResult.orderId);
|
|
|
2886
2901
|
### SIMPLE EXAMPLE - Copy This Pattern Exactly
|
|
2887
2902
|
|
|
2888
2903
|
\`\`\`javascript
|
|
2889
|
-
// Simple bot that searches markets
|
|
2904
|
+
// Simple bot that searches markets using Discovery API (free, no auth)
|
|
2890
2905
|
require('dotenv').config();
|
|
2891
2906
|
|
|
2892
|
-
|
|
2907
|
+
// Discovery API uses SIMPLE format: { name, arguments }
|
|
2908
|
+
async function callDiscovery(name, args = {}) {
|
|
2893
2909
|
const res = await fetch('https://quantish.live/mcp/execute', {
|
|
2894
2910
|
method: 'POST',
|
|
2895
2911
|
headers: {
|
|
2896
2912
|
'Content-Type': 'application/json',
|
|
2897
|
-
'X-API-Key': 'qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8'
|
|
2913
|
+
'X-API-Key': 'qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8' // Public key
|
|
2898
2914
|
},
|
|
2899
|
-
body: JSON.stringify({
|
|
2900
|
-
jsonrpc: '2.0',
|
|
2901
|
-
method: 'tools/call',
|
|
2902
|
-
params: { name, arguments: args },
|
|
2903
|
-
id: 1
|
|
2904
|
-
})
|
|
2915
|
+
body: JSON.stringify({ name, arguments: args }) // Simple format!
|
|
2905
2916
|
});
|
|
2906
2917
|
const data = await res.json();
|
|
2907
2918
|
return JSON.parse(data.result.content[0].text);
|
|
2908
2919
|
}
|
|
2909
2920
|
|
|
2910
2921
|
// Use it!
|
|
2911
|
-
const markets = await
|
|
2922
|
+
const markets = await callDiscovery('search_markets', { query: 'bitcoin', limit: 5 });
|
|
2912
2923
|
console.log(markets);
|
|
2913
2924
|
\`\`\`
|
|
2914
2925
|
|
|
@@ -2976,6 +2987,7 @@ async function callTradingTool(name, args = {}) {
|
|
|
2976
2987
|
|
|
2977
2988
|
/**
|
|
2978
2989
|
* Call a discovery tool (no auth required)
|
|
2990
|
+
* Uses SIMPLE format: { name, arguments } - NOT full JSON-RPC
|
|
2979
2991
|
* Tools: search_markets, get_market_details, get_trending_markets, find_arbitrage
|
|
2980
2992
|
*/
|
|
2981
2993
|
async function callDiscoveryTool(name, args = {}) {
|
|
@@ -2985,12 +2997,7 @@ async function callDiscoveryTool(name, args = {}) {
|
|
|
2985
2997
|
'Content-Type': 'application/json',
|
|
2986
2998
|
'X-API-Key': DISCOVERY_API_KEY
|
|
2987
2999
|
},
|
|
2988
|
-
body: JSON.stringify({
|
|
2989
|
-
jsonrpc: '2.0',
|
|
2990
|
-
method: 'tools/call',
|
|
2991
|
-
params: { name, arguments: args },
|
|
2992
|
-
id: Date.now()
|
|
2993
|
-
})
|
|
3000
|
+
body: JSON.stringify({ name, arguments: args }) // Simple format for Discovery!
|
|
2994
3001
|
});
|
|
2995
3002
|
|
|
2996
3003
|
const data = await response.json();
|
|
@@ -3162,13 +3169,16 @@ var Agent = class {
|
|
|
3162
3169
|
}
|
|
3163
3170
|
/**
|
|
3164
3171
|
* Run the agent with a user message (supports streaming)
|
|
3172
|
+
* @param userMessage - The user's input message
|
|
3173
|
+
* @param options - Optional configuration including abort signal
|
|
3165
3174
|
*/
|
|
3166
|
-
async run(userMessage) {
|
|
3175
|
+
async run(userMessage, options) {
|
|
3167
3176
|
const maxIterations = this.config.maxIterations ?? 15;
|
|
3168
3177
|
const model = this.config.model ?? "claude-sonnet-4-5-20250929";
|
|
3169
3178
|
const maxTokens = this.config.maxTokens ?? 8192;
|
|
3170
3179
|
const systemPrompt = this.config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
3171
3180
|
const useStreaming = this.config.streaming ?? true;
|
|
3181
|
+
const signal = options?.signal;
|
|
3172
3182
|
const allTools = await this.getAllTools();
|
|
3173
3183
|
const contextManagement = this.config.contextEditing && this.config.contextEditing.length > 0 ? { edits: this.config.contextEditing } : void 0;
|
|
3174
3184
|
const contextMessage = `[Working directory: ${this.workingDirectory}]
|
|
@@ -3182,6 +3192,9 @@ ${userMessage}`;
|
|
|
3182
3192
|
let iterations = 0;
|
|
3183
3193
|
let finalText = "";
|
|
3184
3194
|
while (iterations < maxIterations) {
|
|
3195
|
+
if (signal?.aborted) {
|
|
3196
|
+
throw new Error("Operation aborted by user");
|
|
3197
|
+
}
|
|
3185
3198
|
iterations++;
|
|
3186
3199
|
this.config.onStreamStart?.();
|
|
3187
3200
|
let response;
|
|
@@ -3206,8 +3219,12 @@ ${userMessage}`;
|
|
|
3206
3219
|
if (contextManagement) {
|
|
3207
3220
|
streamOptions.context_management = contextManagement;
|
|
3208
3221
|
}
|
|
3209
|
-
const stream = this.anthropic.messages.stream(streamOptions);
|
|
3222
|
+
const stream = this.anthropic.messages.stream(streamOptions, { signal });
|
|
3210
3223
|
for await (const event of stream) {
|
|
3224
|
+
if (signal?.aborted) {
|
|
3225
|
+
stream.controller.abort();
|
|
3226
|
+
throw new Error("Operation aborted by user");
|
|
3227
|
+
}
|
|
3211
3228
|
if (event.type === "content_block_delta") {
|
|
3212
3229
|
const delta = event.delta;
|
|
3213
3230
|
if (delta.type === "text_delta" && delta.text) {
|
|
@@ -3272,6 +3289,9 @@ ${userMessage}`;
|
|
|
3272
3289
|
}
|
|
3273
3290
|
const toolResults = [];
|
|
3274
3291
|
for (const toolUse of toolUses) {
|
|
3292
|
+
if (signal?.aborted) {
|
|
3293
|
+
throw new Error("Operation aborted by user");
|
|
3294
|
+
}
|
|
3275
3295
|
this.config.onToolCall?.(toolUse.name, toolUse.input);
|
|
3276
3296
|
await new Promise((resolve2) => setImmediate(resolve2));
|
|
3277
3297
|
const { result, source } = await this.executeTool(
|
|
@@ -3930,7 +3950,7 @@ Last API Call Cost:
|
|
|
3930
3950
|
completedToolCalls.current = [];
|
|
3931
3951
|
abortController.current = new AbortController();
|
|
3932
3952
|
try {
|
|
3933
|
-
const result = await agent.run(trimmed);
|
|
3953
|
+
const result = await agent.run(trimmed, { signal: abortController.current?.signal });
|
|
3934
3954
|
if (isInterrupted) {
|
|
3935
3955
|
setMessages((prev) => [...prev, {
|
|
3936
3956
|
role: "system",
|