opentool 0.8.23 → 0.8.24

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.d.ts CHANGED
@@ -7,7 +7,7 @@ export { DEFAULT_HYPERLIQUID_MARKET_SLIPPAGE_BPS, HyperliquidAbstraction, Hyperl
7
7
  import { c as WalletFullContext } from './types-BVLpaY4O.js';
8
8
  export { C as ChainMetadata, i as ChainReference, a as ChainTokenMap, H as Hex, g as HexAddress, R as RpcProviderOptions, h as RpcUrlResolver, T as TokenMetadata, l as TurnkeyOptions, k as TurnkeySignWith, r as WalletBaseContext, s as WalletContext, n as WalletOptions, m as WalletOptionsBase, b as WalletPrivateKeyOptions, j as WalletProviderType, f as WalletReadonlyContext, e as WalletReadonlyOptions, W as WalletRegistry, o as WalletSendTransactionParams, q as WalletSignerContext, p as WalletTransferParams, d as WalletTurnkeyOptions } from './types-BVLpaY4O.js';
9
9
  export { AIAbortError, AIClientConfig, AIError, AIFetchError, AIRequestMetadata, AIResponseError, ChatCompletionChoice, ChatCompletionLogProbs, ChatCompletionResponse, ChatCompletionUsage, ChatMessage, ChatMessageContentPart, ChatMessageContentPartImageUrl, ChatMessageContentPartText, ChatMessageRole, DEFAULT_BASE_URL, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, FunctionToolDefinition, GenerateTextOptions, GenerateTextResult, GenerationParameters, JsonSchema, ResolvedAIClientConfig, ResponseErrorDetails, StreamTextOptions, StreamTextResult, StreamingEventHandlers, ToolChoice, ToolDefinition, ToolExecutionPolicy, WEBSEARCH_TOOL_DEFINITION, WEBSEARCH_TOOL_NAME, WebSearchOptions, createAIClient, ensureTextContent, flattenMessageContent, generateText, getModelConfig, isStreamingSupported, isToolCallingSupported, listModels, normalizeModelName, resolveConfig, resolveToolset, streamText } from './ai/index.js';
10
- export { AgentDigestRequest, MyToolsResponse, StoreAction, StoreError, StoreEventInput, StoreOptions, StoreResponse, StoreRetrieveParams, StoreRetrieveResult, ToolExecuteRequest, ToolExecuteResponse, executeTool, getMyPerformance, getMyTools, postAgentDigest, retrieve, store } from './store/index.js';
10
+ export { AgentDigestRequest, MyToolsResponse, StoreAction, StoreError, StoreEventInput, StoreEventLevel, StoreOptions, StoreResponse, StoreRetrieveParams, StoreRetrieveResult, ToolExecuteRequest, ToolExecuteResponse, executeTool, getMyPerformance, getMyTools, postAgentDigest, retrieve, store } from './store/index.js';
11
11
  import { ZodSchema } from 'zod';
12
12
  import 'viem';
13
13
  import 'viem/accounts';
package/dist/index.js CHANGED
@@ -1626,6 +1626,29 @@ var walletToolkit = {
1626
1626
  };
1627
1627
 
1628
1628
  // src/store/index.ts
1629
+ var STORE_EVENT_LEVELS = [
1630
+ "decision",
1631
+ "execution",
1632
+ "lifecycle"
1633
+ ];
1634
+ var STORE_EVENT_LEVEL_SET = new Set(STORE_EVENT_LEVELS);
1635
+ var MARKET_REQUIRED_ACTIONS = [
1636
+ "swap",
1637
+ "bridge",
1638
+ "order",
1639
+ "trade",
1640
+ "lend",
1641
+ "borrow",
1642
+ "repay",
1643
+ "stake",
1644
+ "unstake",
1645
+ "withdraw",
1646
+ "provide_liquidity",
1647
+ "remove_liquidity",
1648
+ "claim"
1649
+ ];
1650
+ var MARKET_REQUIRED_ACTIONS_SET = new Set(MARKET_REQUIRED_ACTIONS);
1651
+ var EXECUTION_ACTIONS_SET = new Set(MARKET_REQUIRED_ACTIONS);
1629
1652
  var StoreError = class extends Error {
1630
1653
  constructor(message, status, causeData) {
1631
1654
  super(message);
@@ -1634,13 +1657,57 @@ var StoreError = class extends Error {
1634
1657
  this.name = "StoreError";
1635
1658
  }
1636
1659
  };
1660
+ var normalizeAction = (action) => {
1661
+ const normalized = action?.trim().toLowerCase();
1662
+ return normalized ? normalized : null;
1663
+ };
1664
+ var coerceEventLevel = (value) => {
1665
+ if (typeof value !== "string") return null;
1666
+ const normalized = value.trim().toLowerCase();
1667
+ if (!normalized || !STORE_EVENT_LEVEL_SET.has(normalized)) return null;
1668
+ return normalized;
1669
+ };
1637
1670
  var requiresMarketIdentity = (input) => {
1638
- const action = (input.action ?? "").toLowerCase();
1639
- if (action === "order" || action === "swap" || action === "trade") return true;
1640
- return false;
1671
+ const action = normalizeAction(input.action);
1672
+ if (!action) return false;
1673
+ return MARKET_REQUIRED_ACTIONS_SET.has(action);
1641
1674
  };
1642
1675
  var hasMarketIdentity = (value) => {
1643
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1676
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1677
+ const record = value;
1678
+ const requiredKeys = ["market_type", "venue", "environment", "canonical_symbol"];
1679
+ return requiredKeys.every((key) => {
1680
+ const field = record[key];
1681
+ return typeof field === "string" && field.trim().length > 0;
1682
+ });
1683
+ };
1684
+ var resolveEventLevel = (input) => {
1685
+ const direct = coerceEventLevel(input.eventLevel);
1686
+ if (direct) return direct;
1687
+ const metadataLevel = coerceEventLevel(input.metadata?.eventLevel);
1688
+ if (metadataLevel) return metadataLevel;
1689
+ const action = normalizeAction(input.action);
1690
+ if (action && EXECUTION_ACTIONS_SET.has(action) && (input.metadata?.lifecycle === true || typeof input.metadata?.executionRef === "string" || typeof input.metadata?.parentExecutionRef === "string")) {
1691
+ return "lifecycle";
1692
+ }
1693
+ if (action && EXECUTION_ACTIONS_SET.has(action) || hasMarketIdentity(input.market)) {
1694
+ return "execution";
1695
+ }
1696
+ if (action) return "decision";
1697
+ return null;
1698
+ };
1699
+ var normalizeStoreInput = (input) => {
1700
+ const metadata = { ...input.metadata ?? {} };
1701
+ const eventLevel = resolveEventLevel({ ...input, metadata });
1702
+ if (eventLevel) {
1703
+ metadata.eventLevel = eventLevel;
1704
+ }
1705
+ const hasMetadata = Object.keys(metadata).length > 0;
1706
+ return {
1707
+ ...input,
1708
+ ...eventLevel ? { eventLevel } : {},
1709
+ ...hasMetadata ? { metadata } : {}
1710
+ };
1644
1711
  };
1645
1712
  function resolveConfig(options) {
1646
1713
  const baseUrl = options?.baseUrl ?? process.env.BASE_URL ?? "https://api.openpond.ai";
@@ -1693,8 +1760,26 @@ async function requestJson(url, options, init) {
1693
1760
  }
1694
1761
  }
1695
1762
  async function store(input, options) {
1696
- if (requiresMarketIdentity(input) && !hasMarketIdentity(input.market)) {
1697
- throw new StoreError("market is required for trade events");
1763
+ const normalizedInput = normalizeStoreInput(input);
1764
+ const eventLevel = normalizedInput.eventLevel;
1765
+ const normalizedAction = normalizeAction(normalizedInput.action);
1766
+ if (eventLevel === "execution" || eventLevel === "lifecycle") {
1767
+ if (!normalizedAction || !EXECUTION_ACTIONS_SET.has(normalizedAction)) {
1768
+ throw new StoreError(
1769
+ `eventLevel "${eventLevel}" requires an execution action`
1770
+ );
1771
+ }
1772
+ }
1773
+ if (eventLevel === "execution" && !hasMarketIdentity(normalizedInput.market)) {
1774
+ throw new StoreError(
1775
+ `market is required for execution events. market must include market_type, venue, environment, canonical_symbol`
1776
+ );
1777
+ }
1778
+ const shouldApplyLegacyMarketRule = eventLevel == null || eventLevel === "execution";
1779
+ if (shouldApplyLegacyMarketRule && requiresMarketIdentity(normalizedInput) && !hasMarketIdentity(normalizedInput.market)) {
1780
+ throw new StoreError(
1781
+ `market is required for action "${normalizedInput.action}". market must include market_type, venue, environment, canonical_symbol`
1782
+ );
1698
1783
  }
1699
1784
  const { baseUrl, apiKey, fetchFn } = resolveConfig(options);
1700
1785
  const url = `${baseUrl}/apps/positions/tx`;
@@ -1706,7 +1791,7 @@ async function store(input, options) {
1706
1791
  "content-type": "application/json",
1707
1792
  "openpond-api-key": apiKey
1708
1793
  },
1709
- body: JSON.stringify(input)
1794
+ body: JSON.stringify(normalizedInput)
1710
1795
  });
1711
1796
  } catch (error) {
1712
1797
  throw new StoreError("Failed to reach store endpoint", void 0, error);