@quantish/agent 0.1.49 → 0.1.51
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/LICENSE +0 -2
- package/README.md +20 -1
- package/dist/index.js +1 -221
- package/package.json +1 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
# @quantish/agent
|
|
1
|
+
# @quantish/agent (V1)
|
|
2
2
|
|
|
3
3
|
AI-powered coding & trading agent for Polymarket and Kalshi. Build trading bots, analyze markets, and execute trades using natural language.
|
|
4
4
|
|
|
5
|
+
> **Looking for V2?** See [@quantish/agent-v2](https://github.com/joinQuantish/quantish-agent-v2) - Gemini-powered with native MCP integration.
|
|
6
|
+
|
|
7
|
+
## V1 vs V2 - Which Should I Use?
|
|
8
|
+
|
|
9
|
+
| Feature | V1 (`@quantish/agent`) | V2 (`@quantish/agent-v2`) |
|
|
10
|
+
|---------|------------------------|---------------------------|
|
|
11
|
+
| CLI Command | `quantish` | `quantish2` |
|
|
12
|
+
| Backend | OpenRouter / Anthropic | Google Gemini |
|
|
13
|
+
| Auth | API Key only | Google OAuth / API Key / Vertex AI |
|
|
14
|
+
| File Tools | Basic read/write | Full sandbox with file operations |
|
|
15
|
+
| MCP Integration | Custom HTTP clients | Native MCP protocol |
|
|
16
|
+
| Best For | Custom bots, full control | General trading, app building |
|
|
17
|
+
|
|
18
|
+
**Install both side-by-side:**
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @quantish/agent # V1 -> quantish
|
|
21
|
+
npm install -g @quantish/agent-v2 # V2 -> quantish2
|
|
22
|
+
```
|
|
23
|
+
|
|
5
24
|
## ✨ Features
|
|
6
25
|
|
|
7
26
|
- **🤖 Multi-Provider AI** - Use Anthropic Claude or 100+ OpenRouter models (GLM-4.7, MiniMax, DeepSeek, etc.)
|
package/dist/index.js
CHANGED
|
@@ -3579,192 +3579,6 @@ function createLLMProvider(config) {
|
|
|
3579
3579
|
}
|
|
3580
3580
|
|
|
3581
3581
|
// src/agent/loop.ts
|
|
3582
|
-
var MAX_TOOL_RESULT_CHARS = 8e3;
|
|
3583
|
-
function truncateToolResult(result, toolName) {
|
|
3584
|
-
const resultStr = JSON.stringify(result);
|
|
3585
|
-
if (resultStr.length <= MAX_TOOL_RESULT_CHARS) {
|
|
3586
|
-
return result;
|
|
3587
|
-
}
|
|
3588
|
-
if (typeof result === "object" && result !== null) {
|
|
3589
|
-
const obj = result;
|
|
3590
|
-
if (Array.isArray(obj.content) && obj.content.length > 0) {
|
|
3591
|
-
const firstContent = obj.content[0];
|
|
3592
|
-
if (firstContent?.type === "text" && typeof firstContent.text === "string") {
|
|
3593
|
-
try {
|
|
3594
|
-
const innerData = JSON.parse(firstContent.text);
|
|
3595
|
-
const truncatedInner = truncateDataObject(innerData);
|
|
3596
|
-
return {
|
|
3597
|
-
content: [{
|
|
3598
|
-
type: "text",
|
|
3599
|
-
text: JSON.stringify(truncatedInner)
|
|
3600
|
-
}]
|
|
3601
|
-
};
|
|
3602
|
-
} catch {
|
|
3603
|
-
const truncatedText = firstContent.text.length > MAX_TOOL_RESULT_CHARS ? firstContent.text.substring(0, MAX_TOOL_RESULT_CHARS) + "... [truncated]" : firstContent.text;
|
|
3604
|
-
return {
|
|
3605
|
-
content: [{
|
|
3606
|
-
type: "text",
|
|
3607
|
-
text: truncatedText
|
|
3608
|
-
}]
|
|
3609
|
-
};
|
|
3610
|
-
}
|
|
3611
|
-
}
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
if (Array.isArray(result)) {
|
|
3615
|
-
return truncateArray(result);
|
|
3616
|
-
}
|
|
3617
|
-
if (typeof result === "object" && result !== null) {
|
|
3618
|
-
return truncateDataObject(result);
|
|
3619
|
-
}
|
|
3620
|
-
if (typeof result === "string" && result.length > MAX_TOOL_RESULT_CHARS) {
|
|
3621
|
-
return result.substring(0, MAX_TOOL_RESULT_CHARS) + "... [truncated]";
|
|
3622
|
-
}
|
|
3623
|
-
return result;
|
|
3624
|
-
}
|
|
3625
|
-
function truncateArray(arr) {
|
|
3626
|
-
const MAX_ITEMS = 5;
|
|
3627
|
-
const truncated = arr.slice(0, MAX_ITEMS).map(
|
|
3628
|
-
(item) => typeof item === "object" && item !== null ? truncateObject(item) : item
|
|
3629
|
-
);
|
|
3630
|
-
return {
|
|
3631
|
-
_truncated: arr.length > MAX_ITEMS,
|
|
3632
|
-
_originalCount: arr.length,
|
|
3633
|
-
_note: arr.length > MAX_ITEMS ? `Showing ${MAX_ITEMS} of ${arr.length} items.` : void 0,
|
|
3634
|
-
items: truncated
|
|
3635
|
-
};
|
|
3636
|
-
}
|
|
3637
|
-
function truncateDataObject(obj) {
|
|
3638
|
-
const truncated = {};
|
|
3639
|
-
const MAX_ARRAY_ITEMS = 5;
|
|
3640
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
3641
|
-
if (Array.isArray(value)) {
|
|
3642
|
-
if (value.length > MAX_ARRAY_ITEMS) {
|
|
3643
|
-
truncated[key] = value.slice(0, MAX_ARRAY_ITEMS).map(
|
|
3644
|
-
(item) => typeof item === "object" && item !== null ? truncateObject(item) : item
|
|
3645
|
-
);
|
|
3646
|
-
truncated[`_${key}Count`] = value.length;
|
|
3647
|
-
truncated["_truncated"] = true;
|
|
3648
|
-
} else {
|
|
3649
|
-
truncated[key] = value.map(
|
|
3650
|
-
(item) => typeof item === "object" && item !== null ? truncateObject(item) : item
|
|
3651
|
-
);
|
|
3652
|
-
}
|
|
3653
|
-
} else if (typeof value === "object" && value !== null) {
|
|
3654
|
-
truncated[key] = truncateObject(value);
|
|
3655
|
-
} else if (typeof value === "string" && value.length > 500) {
|
|
3656
|
-
truncated[key] = value.substring(0, 500) + "...";
|
|
3657
|
-
} else {
|
|
3658
|
-
truncated[key] = value;
|
|
3659
|
-
}
|
|
3660
|
-
}
|
|
3661
|
-
return truncated;
|
|
3662
|
-
}
|
|
3663
|
-
var ACTIONABLE_FIELDS = /* @__PURE__ */ new Set([
|
|
3664
|
-
// Market identifiers (required for trading)
|
|
3665
|
-
"conditionId",
|
|
3666
|
-
"tokenId",
|
|
3667
|
-
"marketId",
|
|
3668
|
-
"id",
|
|
3669
|
-
"ticker",
|
|
3670
|
-
// Token info (required for order placement)
|
|
3671
|
-
"token_id",
|
|
3672
|
-
"clobTokenIds",
|
|
3673
|
-
"tokens",
|
|
3674
|
-
// Pricing (required for trading decisions)
|
|
3675
|
-
"price",
|
|
3676
|
-
"probability",
|
|
3677
|
-
"outcomePrices",
|
|
3678
|
-
"bestBid",
|
|
3679
|
-
"bestAsk",
|
|
3680
|
-
// Market identity (for user understanding)
|
|
3681
|
-
"title",
|
|
3682
|
-
"question",
|
|
3683
|
-
"slug",
|
|
3684
|
-
"outcome",
|
|
3685
|
-
"name",
|
|
3686
|
-
// Status info (affects tradability)
|
|
3687
|
-
"active",
|
|
3688
|
-
"closed",
|
|
3689
|
-
"status",
|
|
3690
|
-
"endDate",
|
|
3691
|
-
// Platform (for multi-platform support)
|
|
3692
|
-
"platform",
|
|
3693
|
-
// Nested structures containing price data (Discovery MCP response)
|
|
3694
|
-
"markets",
|
|
3695
|
-
"outcomes"
|
|
3696
|
-
]);
|
|
3697
|
-
var SUMMARY_FIELDS = /* @__PURE__ */ new Set([
|
|
3698
|
-
"volume",
|
|
3699
|
-
"liquidity",
|
|
3700
|
-
"volume24hr"
|
|
3701
|
-
]);
|
|
3702
|
-
var DROP_FIELDS = /* @__PURE__ */ new Set([
|
|
3703
|
-
"description",
|
|
3704
|
-
"rules",
|
|
3705
|
-
"resolutionSource",
|
|
3706
|
-
"image",
|
|
3707
|
-
"icon",
|
|
3708
|
-
"createdAt",
|
|
3709
|
-
"updatedAt",
|
|
3710
|
-
"lastTradePrice",
|
|
3711
|
-
"spread",
|
|
3712
|
-
"acceptingOrders",
|
|
3713
|
-
"acceptingOrdersTimestamp",
|
|
3714
|
-
"minimum_tick_size",
|
|
3715
|
-
"minimum_order_size",
|
|
3716
|
-
"maker_base_fee",
|
|
3717
|
-
"taker_base_fee",
|
|
3718
|
-
"neg_risk",
|
|
3719
|
-
"neg_risk_market_id",
|
|
3720
|
-
"neg_risk_request_id",
|
|
3721
|
-
"notifications_enabled",
|
|
3722
|
-
"is_50_50_outcome",
|
|
3723
|
-
"game_start_time",
|
|
3724
|
-
"seconds_delay",
|
|
3725
|
-
"icon",
|
|
3726
|
-
"fpmm",
|
|
3727
|
-
"rewards",
|
|
3728
|
-
"competitive"
|
|
3729
|
-
]);
|
|
3730
|
-
function truncateObject(obj) {
|
|
3731
|
-
const truncated = {};
|
|
3732
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
3733
|
-
if (DROP_FIELDS.has(key)) continue;
|
|
3734
|
-
if (ACTIONABLE_FIELDS.has(key)) {
|
|
3735
|
-
if (typeof value === "string" && value.length > 150) {
|
|
3736
|
-
truncated[key] = value.substring(0, 150) + "...";
|
|
3737
|
-
} else if (Array.isArray(value)) {
|
|
3738
|
-
truncated[key] = value.slice(0, 10).map((item) => {
|
|
3739
|
-
if (typeof item === "object" && item !== null) {
|
|
3740
|
-
return extractTokenInfo(item);
|
|
3741
|
-
}
|
|
3742
|
-
return item;
|
|
3743
|
-
});
|
|
3744
|
-
} else {
|
|
3745
|
-
truncated[key] = value;
|
|
3746
|
-
}
|
|
3747
|
-
continue;
|
|
3748
|
-
}
|
|
3749
|
-
if (SUMMARY_FIELDS.has(key)) {
|
|
3750
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
3751
|
-
truncated[key] = value;
|
|
3752
|
-
}
|
|
3753
|
-
continue;
|
|
3754
|
-
}
|
|
3755
|
-
if (typeof value !== "object" && JSON.stringify(truncated).length < 800) {
|
|
3756
|
-
truncated[key] = value;
|
|
3757
|
-
}
|
|
3758
|
-
}
|
|
3759
|
-
return truncated;
|
|
3760
|
-
}
|
|
3761
|
-
function extractTokenInfo(token) {
|
|
3762
|
-
return {
|
|
3763
|
-
token_id: token.token_id ?? token.tokenId,
|
|
3764
|
-
outcome: token.outcome ?? token.name,
|
|
3765
|
-
price: token.price ?? token.probability
|
|
3766
|
-
};
|
|
3767
|
-
}
|
|
3768
3582
|
var DEFAULT_SYSTEM_PROMPT = `You are Quantish, an AI trading agent for prediction markets (Polymarket, Kalshi).
|
|
3769
3583
|
|
|
3770
3584
|
You have tools to search markets and place trades. When showing market data, display ALL relevant information from the response including prices/probabilities.
|
|
@@ -4270,41 +4084,7 @@ ${userMessage}`;
|
|
|
4270
4084
|
* - Future turns: Only actionable data (IDs, prices) is in context
|
|
4271
4085
|
*/
|
|
4272
4086
|
truncateLastToolResults() {
|
|
4273
|
-
|
|
4274
|
-
const message = this.conversationHistory[i];
|
|
4275
|
-
if (message.role === "user" && Array.isArray(message.content)) {
|
|
4276
|
-
const toolResults = message.content.filter(
|
|
4277
|
-
(block) => block.type === "tool_result"
|
|
4278
|
-
);
|
|
4279
|
-
if (toolResults.length > 0) {
|
|
4280
|
-
const truncatedContent = message.content.map((block) => {
|
|
4281
|
-
if (block.type === "tool_result" && typeof block.content === "string") {
|
|
4282
|
-
try {
|
|
4283
|
-
const fullResult = JSON.parse(block.content);
|
|
4284
|
-
const truncatedResult = truncateToolResult(fullResult, "unknown");
|
|
4285
|
-
return {
|
|
4286
|
-
...block,
|
|
4287
|
-
content: JSON.stringify(truncatedResult)
|
|
4288
|
-
};
|
|
4289
|
-
} catch {
|
|
4290
|
-
if (block.content.length > MAX_TOOL_RESULT_CHARS) {
|
|
4291
|
-
return {
|
|
4292
|
-
...block,
|
|
4293
|
-
content: block.content.substring(0, MAX_TOOL_RESULT_CHARS) + "... [truncated for context]"
|
|
4294
|
-
};
|
|
4295
|
-
}
|
|
4296
|
-
}
|
|
4297
|
-
}
|
|
4298
|
-
return block;
|
|
4299
|
-
});
|
|
4300
|
-
this.conversationHistory[i] = {
|
|
4301
|
-
...message,
|
|
4302
|
-
content: truncatedContent
|
|
4303
|
-
};
|
|
4304
|
-
break;
|
|
4305
|
-
}
|
|
4306
|
-
}
|
|
4307
|
-
}
|
|
4087
|
+
return;
|
|
4308
4088
|
}
|
|
4309
4089
|
/**
|
|
4310
4090
|
* Update cumulative token usage from API response
|
package/package.json
CHANGED