@quantish/agent 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +55 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2682,9 +2682,17 @@ You help users build ANY application that interacts with prediction markets - tr
2682
2682
 
2683
2683
  ## Building Applications with Quantish MCP
2684
2684
 
2685
- When users ask you to create ANY application that uses prediction market data or trading (bots, APIs, web apps, scripts, etc.), you MUST use the Quantish MCP API. This is the ONLY way to access market data and trading functionality in standalone applications.
2685
+ When users ask you to create ANY application that uses prediction market data or trading (bots, APIs, web apps, scripts, etc.), you MUST use the Quantish MCP HTTP API. This is the ONLY way to access market data and trading functionality in standalone applications.
2686
2686
 
2687
- ### MCP API Endpoint
2687
+ ### \u26A0\uFE0F CRITICAL: DO NOT USE MCP SDK DIRECTLY
2688
+ NEVER import or use these packages in standalone apps:
2689
+ - \u274C @modelcontextprotocol/sdk
2690
+ - \u274C StdioClientTransport
2691
+ - \u274C Client from MCP SDK
2692
+
2693
+ These only work within the Quantish CLI itself. Standalone apps MUST use the HTTP API with fetch().
2694
+
2695
+ ### MCP HTTP API Endpoint
2688
2696
  \`\`\`
2689
2697
  POST https://quantish-sdk-production.up.railway.app/mcp/execute
2690
2698
  \`\`\`
@@ -2875,6 +2883,35 @@ const orderResult = await callTool('place_order', {
2875
2883
  console.log('Order placed:', orderResult.orderId);
2876
2884
  \`\`\`
2877
2885
 
2886
+ ### SIMPLE EXAMPLE - Copy This Pattern Exactly
2887
+
2888
+ \`\`\`javascript
2889
+ // Simple bot that searches markets - CORRECT PATTERN
2890
+ require('dotenv').config();
2891
+
2892
+ async function callTool(name, args = {}) {
2893
+ const res = await fetch('https://quantish.live/mcp/execute', {
2894
+ method: 'POST',
2895
+ headers: {
2896
+ 'Content-Type': 'application/json',
2897
+ 'X-API-Key': 'qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8'
2898
+ },
2899
+ body: JSON.stringify({
2900
+ jsonrpc: '2.0',
2901
+ method: 'tools/call',
2902
+ params: { name, arguments: args },
2903
+ id: 1
2904
+ })
2905
+ });
2906
+ const data = await res.json();
2907
+ return JSON.parse(data.result.content[0].text);
2908
+ }
2909
+
2910
+ // Use it!
2911
+ const markets = await callTool('search_markets', { query: 'bitcoin', limit: 5 });
2912
+ console.log(markets);
2913
+ \`\`\`
2914
+
2878
2915
  ### Complete Production-Ready Template
2879
2916
 
2880
2917
  Use this as the starting point for ANY application:
@@ -3125,13 +3162,16 @@ var Agent = class {
3125
3162
  }
3126
3163
  /**
3127
3164
  * Run the agent with a user message (supports streaming)
3165
+ * @param userMessage - The user's input message
3166
+ * @param options - Optional configuration including abort signal
3128
3167
  */
3129
- async run(userMessage) {
3168
+ async run(userMessage, options) {
3130
3169
  const maxIterations = this.config.maxIterations ?? 15;
3131
3170
  const model = this.config.model ?? "claude-sonnet-4-5-20250929";
3132
3171
  const maxTokens = this.config.maxTokens ?? 8192;
3133
3172
  const systemPrompt = this.config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
3134
3173
  const useStreaming = this.config.streaming ?? true;
3174
+ const signal = options?.signal;
3135
3175
  const allTools = await this.getAllTools();
3136
3176
  const contextManagement = this.config.contextEditing && this.config.contextEditing.length > 0 ? { edits: this.config.contextEditing } : void 0;
3137
3177
  const contextMessage = `[Working directory: ${this.workingDirectory}]
@@ -3145,6 +3185,9 @@ ${userMessage}`;
3145
3185
  let iterations = 0;
3146
3186
  let finalText = "";
3147
3187
  while (iterations < maxIterations) {
3188
+ if (signal?.aborted) {
3189
+ throw new Error("Operation aborted by user");
3190
+ }
3148
3191
  iterations++;
3149
3192
  this.config.onStreamStart?.();
3150
3193
  let response;
@@ -3169,8 +3212,12 @@ ${userMessage}`;
3169
3212
  if (contextManagement) {
3170
3213
  streamOptions.context_management = contextManagement;
3171
3214
  }
3172
- const stream = this.anthropic.messages.stream(streamOptions);
3215
+ const stream = this.anthropic.messages.stream(streamOptions, { signal });
3173
3216
  for await (const event of stream) {
3217
+ if (signal?.aborted) {
3218
+ stream.controller.abort();
3219
+ throw new Error("Operation aborted by user");
3220
+ }
3174
3221
  if (event.type === "content_block_delta") {
3175
3222
  const delta = event.delta;
3176
3223
  if (delta.type === "text_delta" && delta.text) {
@@ -3235,6 +3282,9 @@ ${userMessage}`;
3235
3282
  }
3236
3283
  const toolResults = [];
3237
3284
  for (const toolUse of toolUses) {
3285
+ if (signal?.aborted) {
3286
+ throw new Error("Operation aborted by user");
3287
+ }
3238
3288
  this.config.onToolCall?.(toolUse.name, toolUse.input);
3239
3289
  await new Promise((resolve2) => setImmediate(resolve2));
3240
3290
  const { result, source } = await this.executeTool(
@@ -3893,7 +3943,7 @@ Last API Call Cost:
3893
3943
  completedToolCalls.current = [];
3894
3944
  abortController.current = new AbortController();
3895
3945
  try {
3896
- const result = await agent.run(trimmed);
3946
+ const result = await agent.run(trimmed, { signal: abortController.current?.signal });
3897
3947
  if (isInterrupted) {
3898
3948
  setMessages((prev) => [...prev, {
3899
3949
  role: "system",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantish/agent",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "AI-powered agent for building trading bots on Polymarket",
5
5
  "type": "module",
6
6
  "bin": {