opentool 0.7.9 → 0.7.11
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/README.md +6 -1
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.js +101 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +112 -2
- package/dist/index.js.map +1 -1
- package/dist/store/index.d.ts +41 -0
- package/dist/store/index.js +70 -0
- package/dist/store/index.js.map +1 -0
- package/dist/{validate-BBjyq5nS.d.ts → validate-uetwG5jo.d.ts} +9 -1
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { I as InternalToolDefinition, T as ToolResponse } from './validate-
|
|
3
|
-
export { B as BuildConfig,
|
|
2
|
+
import { I as InternalToolDefinition, T as ToolResponse } from './validate-uetwG5jo.js';
|
|
3
|
+
export { B as BuildConfig, m as BuildMetadata, H as HTTP_METHODS, f as HttpHandlerDefinition, e as HttpMethod, h as McpConfig, M as Metadata, N as NormalizedSchedule, P as PaymentConfig, S as ScheduleType, i as ServerConfig, j as Tool, d as ToolContent, k as ToolMetadataOverrides, b as generateMetadata, g as generateMetadataCommand, l as loadAndValidateTools, v as validateCommand } from './validate-uetwG5jo.js';
|
|
4
4
|
import { z, ZodSchema } from 'zod';
|
|
5
5
|
export { CurrencySpec, DEFAULT_FACILITATOR, DefineX402PaymentConfig, EIP3009Authorization, PAYMENT_HEADERS, RequireX402PaymentOptions, RequireX402PaymentOutcome, RequireX402PaymentSuccess, SUPPORTED_CURRENCIES, X402BrowserClient, X402BrowserClientConfig, X402Client, X402ClientConfig, X402FacilitatorConfig, X402PayRequest, X402PayResult, X402Payment, X402PaymentContext, X402PaymentDefinition, X402PaymentRequiredError, X402VerificationResult, defineX402Payment, getX402PaymentContext, payX402, payX402WithWallet, requireX402Payment, withX402Payment } from './x402/index.js';
|
|
6
6
|
export { ChainMetadata, ChainReference, ChainTokenMap, DEFAULT_CHAIN, DEFAULT_TOKENS, Hex, HexAddress, RpcProviderOptions, RpcUrlResolver, TokenMetadata, TurnkeyOptions, TurnkeySignWith, WalletBaseContext, WalletContext, WalletFullContext, WalletOptions, WalletOptionsBase, WalletPrivateKeyOptions, WalletProviderType, WalletReadonlyContext, WalletReadonlyOptions, WalletRegistry, WalletSendTransactionParams, WalletSignerContext, WalletTransferParams, WalletTurnkeyOptions, chains, getRpcUrl, registry, tokens, wallet, walletToolkit } from './wallets/index.js';
|
|
7
7
|
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';
|
|
8
|
+
export { StoreAction, StoreError, StoreEventInput, StoreOptions, StoreResponse, store } from './store/index.js';
|
|
8
9
|
import 'viem';
|
|
9
10
|
import 'viem/accounts';
|
|
10
11
|
|
|
@@ -19,6 +20,9 @@ declare function createStdioServer(tools?: InternalToolDefinition[]): Promise<vo
|
|
|
19
20
|
declare function resolveRuntimePath(value: string): string;
|
|
20
21
|
|
|
21
22
|
type CronSpec = {
|
|
23
|
+
/**
|
|
24
|
+
* AWS EventBridge schedule expression (`cron(...)` or `rate(...)`).
|
|
25
|
+
*/
|
|
22
26
|
cron: string;
|
|
23
27
|
enabled?: boolean;
|
|
24
28
|
};
|
package/dist/index.js
CHANGED
|
@@ -2274,6 +2274,73 @@ function toAbortError(reason) {
|
|
|
2274
2274
|
}
|
|
2275
2275
|
return new AIAbortError(String(reason ?? "AI request aborted"));
|
|
2276
2276
|
}
|
|
2277
|
+
|
|
2278
|
+
// src/store/index.ts
|
|
2279
|
+
var StoreError = class extends Error {
|
|
2280
|
+
constructor(message, status, causeData) {
|
|
2281
|
+
super(message);
|
|
2282
|
+
this.status = status;
|
|
2283
|
+
this.causeData = causeData;
|
|
2284
|
+
this.name = "StoreError";
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
function resolveConfig2(options) {
|
|
2288
|
+
const baseUrl = options?.baseUrl ?? process.env.BASE_URL;
|
|
2289
|
+
const apiKey = options?.apiKey ?? process.env.OPENPOND_API_KEY;
|
|
2290
|
+
if (!baseUrl) {
|
|
2291
|
+
throw new StoreError("BASE_URL is required to store activity events");
|
|
2292
|
+
}
|
|
2293
|
+
if (!apiKey) {
|
|
2294
|
+
throw new StoreError(
|
|
2295
|
+
"OPENPOND_API_KEY is required to store activity events"
|
|
2296
|
+
);
|
|
2297
|
+
}
|
|
2298
|
+
const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
|
|
2299
|
+
const fetchFn = options?.fetchFn ?? globalThis.fetch;
|
|
2300
|
+
if (!fetchFn) {
|
|
2301
|
+
throw new StoreError("Fetch is not available in this environment");
|
|
2302
|
+
}
|
|
2303
|
+
return { baseUrl: normalizedBaseUrl, apiKey, fetchFn };
|
|
2304
|
+
}
|
|
2305
|
+
async function store(input, options) {
|
|
2306
|
+
const { baseUrl, apiKey, fetchFn } = resolveConfig2(options);
|
|
2307
|
+
const url = `${baseUrl}/apps/positions/tx`;
|
|
2308
|
+
let response;
|
|
2309
|
+
try {
|
|
2310
|
+
response = await fetchFn(url, {
|
|
2311
|
+
method: "POST",
|
|
2312
|
+
headers: {
|
|
2313
|
+
"content-type": "application/json",
|
|
2314
|
+
"openpond-api-key": apiKey
|
|
2315
|
+
},
|
|
2316
|
+
body: JSON.stringify(input)
|
|
2317
|
+
});
|
|
2318
|
+
} catch (error) {
|
|
2319
|
+
throw new StoreError("Failed to reach store endpoint", void 0, error);
|
|
2320
|
+
}
|
|
2321
|
+
if (!response.ok) {
|
|
2322
|
+
let body;
|
|
2323
|
+
try {
|
|
2324
|
+
body = await response.json();
|
|
2325
|
+
} catch {
|
|
2326
|
+
body = await response.text().catch(() => void 0);
|
|
2327
|
+
}
|
|
2328
|
+
throw new StoreError(
|
|
2329
|
+
`Store request failed with status ${response.status}`,
|
|
2330
|
+
response.status,
|
|
2331
|
+
body
|
|
2332
|
+
);
|
|
2333
|
+
}
|
|
2334
|
+
try {
|
|
2335
|
+
const data = await response.json();
|
|
2336
|
+
return {
|
|
2337
|
+
id: data.id ?? "",
|
|
2338
|
+
status: data.status ?? null
|
|
2339
|
+
};
|
|
2340
|
+
} catch {
|
|
2341
|
+
return { id: "", status: null };
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2277
2344
|
var METADATA_SPEC_VERSION = "1.1.0";
|
|
2278
2345
|
var McpAnnotationsSchema = z.object({
|
|
2279
2346
|
title: z.string().optional(),
|
|
@@ -2696,6 +2763,42 @@ function buildDiscovery(authored) {
|
|
|
2696
2763
|
};
|
|
2697
2764
|
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
2698
2765
|
}
|
|
2766
|
+
|
|
2767
|
+
// src/utils/schedule.ts
|
|
2768
|
+
var CRON_WRAPPED_REGEX = /^cron\((.*)\)$/i;
|
|
2769
|
+
var CRON_TOKEN_REGEX = /^[A-Za-z0-9*?/,\-#L]+$/;
|
|
2770
|
+
function normalizeScheduleExpression(raw, context) {
|
|
2771
|
+
const value = raw?.trim();
|
|
2772
|
+
if (!value) {
|
|
2773
|
+
throw new Error(`${context}: profile.schedule.cron must be a non-empty string`);
|
|
2774
|
+
}
|
|
2775
|
+
const cronBody = extractCronBody(value);
|
|
2776
|
+
const cronFields = cronBody.trim().split(/\s+/).filter(Boolean);
|
|
2777
|
+
if (cronFields.length !== 5 && cronFields.length !== 6) {
|
|
2778
|
+
throw new Error(`${context}: cron expression must have 5 or 6 fields (got ${cronFields.length})`);
|
|
2779
|
+
}
|
|
2780
|
+
validateCronTokens(cronFields, context);
|
|
2781
|
+
return {
|
|
2782
|
+
type: "cron",
|
|
2783
|
+
expression: cronFields.join(" ")
|
|
2784
|
+
};
|
|
2785
|
+
}
|
|
2786
|
+
function extractCronBody(value) {
|
|
2787
|
+
const cronMatch = CRON_WRAPPED_REGEX.exec(value);
|
|
2788
|
+
if (cronMatch) {
|
|
2789
|
+
return (cronMatch[1] ?? "").trim();
|
|
2790
|
+
}
|
|
2791
|
+
return value;
|
|
2792
|
+
}
|
|
2793
|
+
function validateCronTokens(fields, context) {
|
|
2794
|
+
fields.forEach((token2, idx) => {
|
|
2795
|
+
if (!CRON_TOKEN_REGEX.test(token2)) {
|
|
2796
|
+
throw new Error(`${context}: invalid cron token "${token2}" at position ${idx + 1}`);
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
// src/cli/validate.ts
|
|
2699
2802
|
var SUPPORTED_EXTENSIONS = [
|
|
2700
2803
|
".ts",
|
|
2701
2804
|
".tsx",
|
|
@@ -2780,11 +2883,16 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
2780
2883
|
if (hasGET === hasPOST) {
|
|
2781
2884
|
throw new Error(`${file}: export exactly one of GET or POST`);
|
|
2782
2885
|
}
|
|
2886
|
+
let normalizedSchedule = null;
|
|
2783
2887
|
if (hasGET) {
|
|
2784
2888
|
const schedule = toolModule?.profile?.schedule;
|
|
2785
2889
|
if (!schedule || typeof schedule?.cron !== "string" || schedule.cron.trim().length === 0) {
|
|
2786
2890
|
throw new Error(`${file}: GET tools require profile.schedule { cron }`);
|
|
2787
2891
|
}
|
|
2892
|
+
normalizedSchedule = normalizeScheduleExpression(schedule.cron, file);
|
|
2893
|
+
if (typeof schedule.enabled === "boolean") {
|
|
2894
|
+
normalizedSchedule.authoredEnabled = schedule.enabled;
|
|
2895
|
+
}
|
|
2788
2896
|
}
|
|
2789
2897
|
if (hasPOST) {
|
|
2790
2898
|
if (!schema) {
|
|
@@ -2841,7 +2949,9 @@ async function loadAndValidateTools(toolsDir, options = {}) {
|
|
|
2841
2949
|
filename: toBaseName(file),
|
|
2842
2950
|
sourcePath: path5.join(toolsDir, file),
|
|
2843
2951
|
handler: async (params) => adapter(params),
|
|
2844
|
-
payment: paymentExport ?? null
|
|
2952
|
+
payment: paymentExport ?? null,
|
|
2953
|
+
schedule: normalizedSchedule,
|
|
2954
|
+
profileDescription: typeof toolModule?.profile?.description === "string" ? toolModule.profile?.description ?? null : null
|
|
2845
2955
|
};
|
|
2846
2956
|
tools.push(tool);
|
|
2847
2957
|
}
|
|
@@ -3073,6 +3183,6 @@ function timestamp() {
|
|
|
3073
3183
|
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
|
|
3074
3184
|
}
|
|
3075
3185
|
|
|
3076
|
-
export { AIAbortError, AIError, AIFetchError, AIResponseError, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, PAYMENT_HEADERS, SUPPORTED_CURRENCIES, WEBSEARCH_TOOL_DEFINITION, WEBSEARCH_TOOL_NAME, X402BrowserClient, X402Client, X402PaymentRequiredError, chains, createAIClient, createDevServer, createMcpAdapter, createStdioServer, defineX402Payment, ensureTextContent, flattenMessageContent, generateMetadata, generateMetadataCommand, generateText, getModelConfig, getRpcUrl, getX402PaymentContext, isStreamingSupported, isToolCallingSupported, listModels, loadAndValidateTools, normalizeModelName, payX402, payX402WithWallet, registry, requireX402Payment, resolveConfig, resolveRuntimePath, resolveToolset, responseToToolResponse, streamText, tokens, validateCommand, wallet, walletToolkit, withX402Payment };
|
|
3186
|
+
export { AIAbortError, AIError, AIFetchError, AIResponseError, DEFAULT_BASE_URL, DEFAULT_CHAIN, DEFAULT_FACILITATOR, DEFAULT_MODEL, DEFAULT_TIMEOUT_MS, DEFAULT_TOKENS, HTTP_METHODS2 as HTTP_METHODS, PAYMENT_HEADERS, SUPPORTED_CURRENCIES, StoreError, WEBSEARCH_TOOL_DEFINITION, WEBSEARCH_TOOL_NAME, X402BrowserClient, X402Client, X402PaymentRequiredError, chains, createAIClient, createDevServer, createMcpAdapter, createStdioServer, defineX402Payment, ensureTextContent, flattenMessageContent, generateMetadata, generateMetadataCommand, generateText, getModelConfig, getRpcUrl, getX402PaymentContext, isStreamingSupported, isToolCallingSupported, listModels, loadAndValidateTools, normalizeModelName, payX402, payX402WithWallet, registry, requireX402Payment, resolveConfig, resolveRuntimePath, resolveToolset, responseToToolResponse, store, streamText, tokens, validateCommand, wallet, walletToolkit, withX402Payment };
|
|
3077
3187
|
//# sourceMappingURL=index.js.map
|
|
3078
3188
|
//# sourceMappingURL=index.js.map
|