nolo-cli 0.1.10 → 0.1.12
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 +0 -32
- package/agentRuntimeCommands.ts +1 -1
- package/client/compactDialog.ts +2 -5
- package/commandRegistry.ts +2 -2
- package/machineCommands.ts +28 -3
- package/package.json +5 -25
- package/ai/agent/_executeModel.ts +0 -118
- package/ai/agent/agentSlice.ts +0 -525
- package/ai/agent/appWorkingMemory.ts +0 -126
- package/ai/agent/avatarUtils.ts +0 -24
- package/ai/agent/buildEditingContext.ts +0 -373
- package/ai/agent/buildSystemPrompt.ts +0 -532
- package/ai/agent/cleanAgentMessages.ts +0 -140
- package/ai/agent/cliChatClient.ts +0 -119
- package/ai/agent/contextCompiler.ts +0 -107
- package/ai/agent/contextLayerContract.ts +0 -44
- package/ai/agent/createAgentSchema.ts +0 -234
- package/ai/agent/executeToolCall.ts +0 -58
- package/ai/agent/fetchAgentContexts.ts +0 -42
- package/ai/agent/generatePrompt.ts +0 -3
- package/ai/agent/getFullChatContextKeys.ts +0 -168
- package/ai/agent/hooks/fetchPublicAgents.ts +0 -133
- package/ai/agent/hooks/useAgentConfig.ts +0 -61
- package/ai/agent/hooks/useAgentDialog.ts +0 -35
- package/ai/agent/hooks/useAgentFormValidation.ts +0 -202
- package/ai/agent/hooks/usePublicAgents.ts +0 -473
- package/ai/agent/persistMessageWithFixedId.ts +0 -37
- package/ai/agent/planSlice.ts +0 -259
- package/ai/agent/referenceUtils.ts +0 -229
- package/ai/agent/runAgentBackground.ts +0 -238
- package/ai/agent/runAgentClientLoop.ts +0 -138
- package/ai/agent/runtimeGuidance.ts +0 -97
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/ai/agent/server/fetchPublicAgents.ts +0 -128
- package/ai/agent/startParallelAgentStreams.ts +0 -424
- package/ai/agent/startupProtocol.ts +0 -53
- package/ai/agent/streamAgentChatTurn.ts +0 -1278
- package/ai/agent/streamAgentChatTurnUtils.ts +0 -738
- package/ai/agent/types.ts +0 -71
- package/ai/agent/utils/imageOutput.ts +0 -33
- package/ai/agent/utils/sortUtils.ts +0 -250
- package/ai/agent/web/referencePickerUtils.ts +0 -146
- package/ai/ai.locale.ts +0 -1079
- package/ai/chat/accumulateToolCallChunks.ts +0 -95
- package/ai/chat/fetchUtils.native.ts +0 -276
- package/ai/chat/fetchUtils.ts +0 -153
- package/ai/chat/parseApiError.ts +0 -64
- package/ai/chat/parseMultilineSSE.ts +0 -95
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +0 -682
- package/ai/chat/sendOpenAICompletionsRequest.ts +0 -703
- package/ai/chat/sendOpenAIResponseRequest.ts +0 -491
- package/ai/chat/shouldUseServerProxy.ts +0 -18
- package/ai/chat/sseClient.native.ts +0 -91
- package/ai/chat/sseClient.ts +0 -67
- package/ai/chat/streamReader.native.ts +0 -31
- package/ai/chat/streamReader.ts +0 -62
- package/ai/chat/updateTotalUsage.ts +0 -72
- package/ai/context/buildReferenceContext.ts +0 -437
- package/ai/context/calculateContextUsage.ts +0 -133
- package/ai/context/retention.ts +0 -165
- package/ai/context/tokenUtils.ts +0 -78
- package/ai/index.ts +0 -1
- package/ai/llm/calculateGeminiImageTokens.ts +0 -57
- package/ai/llm/deepinfra.ts +0 -28
- package/ai/llm/fireworks.ts +0 -50
- package/ai/llm/generateRequestBody.ts +0 -165
- package/ai/llm/getModelContextWindow.ts +0 -84
- package/ai/llm/getNoloKey.ts +0 -31
- package/ai/llm/getPricing.ts +0 -199
- package/ai/llm/hooks/useModelPricing.ts +0 -75
- package/ai/llm/imagePricing.ts +0 -40
- package/ai/llm/isResponseAPIModel.ts +0 -13
- package/ai/llm/mimo.ts +0 -71
- package/ai/llm/mistral.ts +0 -22
- package/ai/llm/modelAvatar.ts +0 -427
- package/ai/llm/models.ts +0 -45
- package/ai/llm/openrouterModels.ts +0 -269
- package/ai/llm/providers.ts +0 -306
- package/ai/llm/reasoningModels.ts +0 -28
- package/ai/llm/types.ts +0 -59
- package/ai/llm/usageRequestOptions.ts +0 -59
- package/ai/memory/capture.ts +0 -148
- package/ai/memory/consolidate.ts +0 -104
- package/ai/memory/delete.ts +0 -147
- package/ai/memory/overlay.ts +0 -84
- package/ai/memory/query.ts +0 -38
- package/ai/memory/queryShared.ts +0 -160
- package/ai/memory/rank.ts +0 -105
- package/ai/memory/recentRelationshipRecap.ts +0 -249
- package/ai/memory/remember.ts +0 -167
- package/ai/memory/runtime.ts +0 -76
- package/ai/memory/store.ts +0 -20
- package/ai/memory/storeShared.ts +0 -76
- package/ai/memory/types.ts +0 -46
- package/ai/memory/understanding.ts +0 -349
- package/ai/memory/understandingGreeting.ts +0 -264
- package/ai/messages/type.ts +0 -20
- package/ai/policy/personalizationDialog.ts +0 -333
- package/ai/policy/runtimePolicy.ts +0 -440
- package/ai/policy/selfUpdateFields.ts +0 -48
- package/ai/policy/types.ts +0 -64
- package/ai/skills/referenceRuntime.ts +0 -274
- package/ai/skills/skillDiagnostics.ts +0 -251
- package/ai/skills/skillDocBuilder.ts +0 -139
- package/ai/skills/skillDocProtocol.ts +0 -434
- package/ai/skills/skillReferenceSummary.ts +0 -63
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/ai/token/calculatePrice.ts +0 -544
- package/ai/token/db.ts +0 -98
- package/ai/token/externalToolCost.ts +0 -330
- package/ai/token/hooks/useRecords.ts +0 -65
- package/ai/token/missingUsageEstimate.ts +0 -42
- package/ai/token/modelUsageQuery.ts +0 -252
- package/ai/token/normalizeUsage.ts +0 -84
- package/ai/token/openaiImageGenerationUsage.ts +0 -56
- package/ai/token/prepareTokenUsageData.ts +0 -88
- package/ai/token/query.ts +0 -88
- package/ai/token/queryUserTokens.ts +0 -59
- package/ai/token/resolveBillingTarget.ts +0 -52
- package/ai/token/saveTokenRecord.ts +0 -53
- package/ai/token/serverDialogProjection.ts +0 -78
- package/ai/token/serverTokenWriter.ts +0 -143
- package/ai/token/stats.ts +0 -21
- package/ai/token/tokenThunks.ts +0 -24
- package/ai/token/types.ts +0 -93
- package/ai/tools/agent/agentTools.ts +0 -176
- package/ai/tools/agent/agentUpdateShared.ts +0 -311
- package/ai/tools/agent/callAgentTool.ts +0 -139
- package/ai/tools/agent/createAgentTool.ts +0 -512
- package/ai/tools/agent/createDialogTool.ts +0 -69
- package/ai/tools/agent/createSkillAgentTool.ts +0 -62
- package/ai/tools/agent/parallelBudget.ts +0 -221
- package/ai/tools/agent/presets/appBuilderPreset.ts +0 -145
- package/ai/tools/agent/runLlmTool.ts +0 -96
- package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
- package/ai/tools/agent/skillAgentArgs.ts +0 -106
- package/ai/tools/agent/skillAgentPreset.ts +0 -89
- package/ai/tools/agent/streamParallelAgentsTool.ts +0 -122
- package/ai/tools/agent/updateAgentTool.ts +0 -96
- package/ai/tools/agent/updateSelfTool.ts +0 -113
- package/ai/tools/amazonProductScraperTool.ts +0 -86
- package/ai/tools/apifyActorClient.ts +0 -45
- package/ai/tools/appEditGuard.ts +0 -372
- package/ai/tools/appReadSnapshot.ts +0 -153
- package/ai/tools/appTools.ts +0 -1549
- package/ai/tools/applyEditTool.ts +0 -256
- package/ai/tools/applyLineEditsTool.ts +0 -312
- package/ai/tools/browserTools/click.ts +0 -33
- package/ai/tools/browserTools/closeSession.ts +0 -29
- package/ai/tools/browserTools/common.ts +0 -27
- package/ai/tools/browserTools/openSession.ts +0 -48
- package/ai/tools/browserTools/readContent.ts +0 -38
- package/ai/tools/browserTools/selectOption.ts +0 -46
- package/ai/tools/browserTools/typeText.ts +0 -42
- package/ai/tools/category/createCategoryTool.ts +0 -66
- package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
- package/ai/tools/category/updateContentCategoryTool.ts +0 -75
- package/ai/tools/cfBrowserTools.ts +0 -319
- package/ai/tools/cfSpeechToTextTool.ts +0 -49
- package/ai/tools/checkEnvTool.ts +0 -65
- package/ai/tools/cloudflareCrawlTool.ts +0 -289
- package/ai/tools/codeSearchTool.ts +0 -111
- package/ai/tools/codeTools.ts +0 -101
- package/ai/tools/createDocTool.ts +0 -132
- package/ai/tools/createPlanTool.ts +0 -999
- package/ai/tools/createSkillDocTool.ts +0 -155
- package/ai/tools/createWorkflowTool.ts +0 -154
- package/ai/tools/deepseekOcrTool.ts +0 -34
- package/ai/tools/delayTool.ts +0 -31
- package/ai/tools/deleteSpacesTool.ts +0 -325
- package/ai/tools/deleteSpacesToolModel.ts +0 -159
- package/ai/tools/devReloadUtils.ts +0 -29
- package/ai/tools/dialogMessageSearch.ts +0 -137
- package/ai/tools/doctorSkillTool.ts +0 -72
- package/ai/tools/ecommerceScraperTool.ts +0 -86
- package/ai/tools/emailTools.ts +0 -549
- package/ai/tools/evalSkillTool.ts +0 -92
- package/ai/tools/exaSearchTool.ts +0 -64
- package/ai/tools/execBashTool.ts +0 -379
- package/ai/tools/executeSqlTool.ts +0 -192
- package/ai/tools/fetchWebpageSupport.ts +0 -309
- package/ai/tools/fetchWebpageTool.ts +0 -84
- package/ai/tools/geminiImagePreviewTool.ts +0 -361
- package/ai/tools/generateDocxTool.ts +0 -215
- package/ai/tools/googleSearchScraperTool.ts +0 -106
- package/ai/tools/importDataTool.ts +0 -133
- package/ai/tools/importSkillTool.ts +0 -162
- package/ai/tools/index.ts +0 -1858
- package/ai/tools/listFilesTool.ts +0 -82
- package/ai/tools/listUserSpacesTool.ts +0 -113
- package/ai/tools/modelUsageTools.ts +0 -142
- package/ai/tools/olmOcrTool.ts +0 -34
- package/ai/tools/openaiImageTool.ts +0 -218
- package/ai/tools/paddleOcrTool.ts +0 -34
- package/ai/tools/prepareTools.ts +0 -23
- package/ai/tools/readDocTool.ts +0 -84
- package/ai/tools/readFileTool.ts +0 -211
- package/ai/tools/readTool.ts +0 -163
- package/ai/tools/readXPostTool.ts +0 -233
- package/ai/tools/rememberMemoryTool.ts +0 -84
- package/ai/tools/remotionVideoTool.ts +0 -151
- package/ai/tools/searchDialogMessagesTool.ts +0 -222
- package/ai/tools/searchRepoTool.ts +0 -115
- package/ai/tools/searchWorkspaceTool.ts +0 -259
- package/ai/tools/skillFollowup.ts +0 -86
- package/ai/tools/surfWeatherTool.ts +0 -169
- package/ai/tools/table/addTableRowTool.ts +0 -217
- package/ai/tools/table/createTableTool.ts +0 -315
- package/ai/tools/table/rowTools.ts +0 -366
- package/ai/tools/table/schemaTools.ts +0 -244
- package/ai/tools/table/shareTableTool.ts +0 -148
- package/ai/tools/table/toolShared.ts +0 -129
- package/ai/tools/toolApiClient.ts +0 -198
- package/ai/tools/toolNameAliases.ts +0 -57
- package/ai/tools/toolResultError.ts +0 -42
- package/ai/tools/toolRunSlice.ts +0 -303
- package/ai/tools/toolSchemaCompatibility.ts +0 -53
- package/ai/tools/toolVisibility.ts +0 -4
- package/ai/tools/types.ts +0 -20
- package/ai/tools/uiAskChoiceTool.ts +0 -104
- package/ai/tools/updateContentTitleTool.ts +0 -84
- package/ai/tools/updateDocTool.ts +0 -105
- package/ai/tools/updateUserPreferenceProfileTool.ts +0 -145
- package/ai/tools/whisperTool.ts +0 -77
- package/ai/tools/writeFileTool.ts +0 -210
- package/ai/tools/youtubeScraperTool.ts +0 -116
- package/ai/tools/ziweiChartTool.ts +0 -678
- package/ai/types.ts +0 -55
- package/ai/workflow/workflowExecutor.ts +0 -323
- package/ai/workflow/workflowSlice.ts +0 -73
- package/ai/workflow/workflowTypes.ts +0 -106
- package/connector-experimental/index.ts +0 -5
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
// packages/ai/tools/cfBrowserTools.ts
|
|
2
|
-
// Cloudflare Browser Rendering 工具:截图、Markdown、PDF、JSON 结构化提取
|
|
3
|
-
// Docs: https://developers.cloudflare.com/browser-rendering/rest-api/
|
|
4
|
-
|
|
5
|
-
import { callToolApi } from "./toolApiClient";
|
|
6
|
-
import {
|
|
7
|
-
assertFetchableDocsUrl,
|
|
8
|
-
detectExtractionIssue,
|
|
9
|
-
discoverCanonicalDocsUrl,
|
|
10
|
-
} from "./fetchWebpageSupport";
|
|
11
|
-
|
|
12
|
-
async function resolveCfBrowserUrl(url?: string) {
|
|
13
|
-
if (!url) {
|
|
14
|
-
return {
|
|
15
|
-
targetUrl: url,
|
|
16
|
-
originalUrl: url,
|
|
17
|
-
rewritten: false,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const resolution = await discoverCanonicalDocsUrl(url);
|
|
22
|
-
const targetUrl = resolution.resolvedUrl;
|
|
23
|
-
await assertFetchableDocsUrl(targetUrl, fetch, url);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
targetUrl,
|
|
27
|
-
originalUrl: url,
|
|
28
|
-
rewritten: targetUrl !== url,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function buildNormalizationNote(originalUrl?: string, targetUrl?: string) {
|
|
33
|
-
if (!originalUrl || !targetUrl || originalUrl === targetUrl) return "";
|
|
34
|
-
return `\n🧭 文档地址已规范化: ${originalUrl} → ${targetUrl}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ──────────────────────────────────────────────────────────
|
|
38
|
-
// cfScreenshot
|
|
39
|
-
// ──────────────────────────────────────────────────────────
|
|
40
|
-
export const cfScreenshotFunctionSchema = {
|
|
41
|
-
name: "cfScreenshot",
|
|
42
|
-
description:
|
|
43
|
-
"使用 Cloudflare Browser Rendering 对指定网页或 HTML 内容截图,支持全页截图、自定义视口。" +
|
|
44
|
-
"返回 base64 图片数据,可直接在对话中展示。",
|
|
45
|
-
parameters: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: {
|
|
48
|
-
url: {
|
|
49
|
-
type: "string",
|
|
50
|
-
description: "要截图的网页 URL(http/https),与 html 二选一。",
|
|
51
|
-
},
|
|
52
|
-
html: {
|
|
53
|
-
type: "string",
|
|
54
|
-
description: "直接传入 HTML 字符串进行渲染截图,与 url 二选一。",
|
|
55
|
-
},
|
|
56
|
-
fullPage: {
|
|
57
|
-
type: "boolean",
|
|
58
|
-
description: "是否截取完整页面(包括滚动区域),默认 false 只截可视区。",
|
|
59
|
-
default: false,
|
|
60
|
-
},
|
|
61
|
-
viewport: {
|
|
62
|
-
type: "object",
|
|
63
|
-
description: "浏览器视口尺寸,例如 { width: 1280, height: 720 }。",
|
|
64
|
-
properties: {
|
|
65
|
-
width: { type: "integer" },
|
|
66
|
-
height: { type: "integer" },
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export async function cfScreenshotFunc(
|
|
74
|
-
args: {
|
|
75
|
-
url?: string;
|
|
76
|
-
html?: string;
|
|
77
|
-
fullPage?: boolean;
|
|
78
|
-
viewport?: { width: number; height: number };
|
|
79
|
-
},
|
|
80
|
-
thunkApi: any
|
|
81
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
82
|
-
const { url, html, fullPage = false, viewport } = args;
|
|
83
|
-
|
|
84
|
-
if (!url && !html) throw new Error("必须提供 url 或 html 参数");
|
|
85
|
-
const { targetUrl, originalUrl, rewritten } = await resolveCfBrowserUrl(url);
|
|
86
|
-
|
|
87
|
-
const data = await callToolApi<{
|
|
88
|
-
dataUrl: string;
|
|
89
|
-
mimeType: string;
|
|
90
|
-
browserMsUsed?: number;
|
|
91
|
-
source: string;
|
|
92
|
-
}>(
|
|
93
|
-
thunkApi,
|
|
94
|
-
"/api/cf-screenshot",
|
|
95
|
-
{ url: targetUrl, html, fullPage, viewport },
|
|
96
|
-
{ withAuth: true }
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const seconds = data.browserMsUsed ? (data.browserMsUsed / 1000).toFixed(2) : "?";
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
rawData: rewritten ? { ...data, originalUrl, resolvedUrl: targetUrl } : data,
|
|
103
|
-
displayData:
|
|
104
|
-
`📸 截图完成\n- 来源: ${data.source}\n- 浏览器耗时: ${seconds}s` +
|
|
105
|
-
buildNormalizationNote(originalUrl, targetUrl) +
|
|
106
|
-
`\n\n` +
|
|
107
|
-
``,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ──────────────────────────────────────────────────────────
|
|
112
|
-
// cfGetMarkdown
|
|
113
|
-
// ──────────────────────────────────────────────────────────
|
|
114
|
-
export const cfGetMarkdownFunctionSchema = {
|
|
115
|
-
name: "cfGetMarkdown",
|
|
116
|
-
description:
|
|
117
|
-
"使用 Cloudflare Browser Rendering 将网页内容转换为 Markdown 格式,支持 JS 渲染。" +
|
|
118
|
-
"比 cloudflareCrawl 更快(单页),比 fetchWebpage 更准确(支持 JS 动态内容)。" +
|
|
119
|
-
"适合文章阅读、内容总结、单页数据提取。",
|
|
120
|
-
parameters: {
|
|
121
|
-
type: "object",
|
|
122
|
-
properties: {
|
|
123
|
-
url: {
|
|
124
|
-
type: "string",
|
|
125
|
-
description: "要读取的网页 URL(http/https),与 html 二选一。",
|
|
126
|
-
},
|
|
127
|
-
html: {
|
|
128
|
-
type: "string",
|
|
129
|
-
description: "直接传入 HTML 字符串转换,与 url 二选一。",
|
|
130
|
-
},
|
|
131
|
-
waitForNetworkIdle: {
|
|
132
|
-
type: "boolean",
|
|
133
|
-
description: "是否等待网络请求结束再提取(适合 SPA/动态页面),默认 false。",
|
|
134
|
-
default: false,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export async function cfGetMarkdownFunc(
|
|
141
|
-
args: {
|
|
142
|
-
url?: string;
|
|
143
|
-
html?: string;
|
|
144
|
-
waitForNetworkIdle?: boolean;
|
|
145
|
-
},
|
|
146
|
-
thunkApi: any
|
|
147
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
148
|
-
const { url, html, waitForNetworkIdle = false } = args;
|
|
149
|
-
|
|
150
|
-
if (!url && !html) throw new Error("必须提供 url 或 html 参数");
|
|
151
|
-
const { targetUrl, originalUrl, rewritten } = await resolveCfBrowserUrl(url);
|
|
152
|
-
|
|
153
|
-
const gotoOptions = waitForNetworkIdle ? { waitUntil: "networkidle0" } : undefined;
|
|
154
|
-
|
|
155
|
-
const data = await callToolApi<{
|
|
156
|
-
markdown: string;
|
|
157
|
-
success: boolean;
|
|
158
|
-
browserMsUsed?: number;
|
|
159
|
-
source: string;
|
|
160
|
-
}>(thunkApi, "/api/cf-markdown", { url: targetUrl, html, gotoOptions }, { withAuth: true });
|
|
161
|
-
|
|
162
|
-
const extractionIssue = detectExtractionIssue(data.markdown ?? "", targetUrl ?? url ?? "网页");
|
|
163
|
-
if (extractionIssue) {
|
|
164
|
-
throw new Error(extractionIssue.message);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const seconds = data.browserMsUsed ? (data.browserMsUsed / 1000).toFixed(2) : "?";
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
rawData: rewritten ? { ...data, originalUrl, resolvedUrl: targetUrl } : data,
|
|
171
|
-
displayData:
|
|
172
|
-
`📄 Markdown 提取完成\n- 来源: ${data.source}\n- 浏览器耗时: ${seconds}s\n- 字符数: ${data.markdown?.length ?? 0}` +
|
|
173
|
-
buildNormalizationNote(originalUrl, targetUrl) +
|
|
174
|
-
`\n\n` +
|
|
175
|
-
data.markdown,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ──────────────────────────────────────────────────────────
|
|
180
|
-
// cfGeneratePDF
|
|
181
|
-
// ──────────────────────────────────────────────────────────
|
|
182
|
-
export const cfGeneratePDFFunctionSchema = {
|
|
183
|
-
name: "cfGeneratePDF",
|
|
184
|
-
description:
|
|
185
|
-
"使用 Cloudflare Browser Rendering 将网页或 HTML 渲染为 PDF 文件。" +
|
|
186
|
-
"适合导出文档、报告、打印版网页等场景。",
|
|
187
|
-
parameters: {
|
|
188
|
-
type: "object",
|
|
189
|
-
properties: {
|
|
190
|
-
url: {
|
|
191
|
-
type: "string",
|
|
192
|
-
description: "要转换为 PDF 的网页 URL(http/https),与 html 二选一。",
|
|
193
|
-
},
|
|
194
|
-
html: {
|
|
195
|
-
type: "string",
|
|
196
|
-
description: "直接传入 HTML 字符串转换为 PDF,与 url 二选一。",
|
|
197
|
-
},
|
|
198
|
-
pdfOptions: {
|
|
199
|
-
type: "object",
|
|
200
|
-
description: "PDF 生成选项,例如 { format: 'A4', landscape: false, printBackground: true }。",
|
|
201
|
-
properties: {
|
|
202
|
-
format: { type: "string", description: "页面大小,如 'A4'、'Letter'。" },
|
|
203
|
-
landscape: { type: "boolean" },
|
|
204
|
-
printBackground: { type: "boolean" },
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
export async function cfGeneratePDFFunc(
|
|
212
|
-
args: {
|
|
213
|
-
url?: string;
|
|
214
|
-
html?: string;
|
|
215
|
-
pdfOptions?: { format?: string; landscape?: boolean; printBackground?: boolean };
|
|
216
|
-
},
|
|
217
|
-
thunkApi: any
|
|
218
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
219
|
-
const { url, html, pdfOptions } = args;
|
|
220
|
-
|
|
221
|
-
if (!url && !html) throw new Error("必须提供 url 或 html 参数");
|
|
222
|
-
const { targetUrl, originalUrl, rewritten } = await resolveCfBrowserUrl(url);
|
|
223
|
-
|
|
224
|
-
const data = await callToolApi<{
|
|
225
|
-
dataUrl: string;
|
|
226
|
-
mimeType: string;
|
|
227
|
-
filename: string;
|
|
228
|
-
browserMsUsed?: number;
|
|
229
|
-
source: string;
|
|
230
|
-
}>(thunkApi, "/api/cf-pdf", { url: targetUrl, html, pdfOptions }, { withAuth: true });
|
|
231
|
-
|
|
232
|
-
const seconds = data.browserMsUsed ? (data.browserMsUsed / 1000).toFixed(2) : "?";
|
|
233
|
-
|
|
234
|
-
return {
|
|
235
|
-
rawData: rewritten ? { ...data, originalUrl, resolvedUrl: targetUrl } : data,
|
|
236
|
-
displayData:
|
|
237
|
-
`📑 PDF 生成完成\n- 来源: ${data.source}\n- 文件名: ${data.filename}\n- 浏览器耗时: ${seconds}s` +
|
|
238
|
-
buildNormalizationNote(originalUrl, targetUrl) +
|
|
239
|
-
`\n\n` +
|
|
240
|
-
`[下载 PDF](${data.dataUrl})`,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// ──────────────────────────────────────────────────────────
|
|
245
|
-
// cfExtractJSON
|
|
246
|
-
// ──────────────────────────────────────────────────────────
|
|
247
|
-
export const cfExtractJSONFunctionSchema = {
|
|
248
|
-
name: "cfExtractJSON",
|
|
249
|
-
description:
|
|
250
|
-
"使用 Cloudflare Browser Rendering + AI,从网页中提取结构化数据。" +
|
|
251
|
-
"用自然语言描述你想要的数据(prompt),或提供 JSON Schema 定义结构,AI 自动抓取并返回结构化 JSON。" +
|
|
252
|
-
"适合:商品信息、职位列表、文章元数据、价格比较、任何需要从网页提取结构化数据的场景。",
|
|
253
|
-
parameters: {
|
|
254
|
-
type: "object",
|
|
255
|
-
properties: {
|
|
256
|
-
url: {
|
|
257
|
-
type: "string",
|
|
258
|
-
description: "目标网页 URL(http/https),与 html 二选一。",
|
|
259
|
-
},
|
|
260
|
-
html: {
|
|
261
|
-
type: "string",
|
|
262
|
-
description: "直接传入 HTML 字符串,与 url 二选一。",
|
|
263
|
-
},
|
|
264
|
-
prompt: {
|
|
265
|
-
type: "string",
|
|
266
|
-
description:
|
|
267
|
-
"用自然语言描述要提取的数据,例如:'提取所有商品的名称、价格和库存状态'。" +
|
|
268
|
-
"与 response_format 至少提供一个,同时提供时 prompt 引导提取方向,response_format 约束结构。",
|
|
269
|
-
},
|
|
270
|
-
response_format: {
|
|
271
|
-
type: "object",
|
|
272
|
-
description:
|
|
273
|
-
"JSON Schema 格式的结构定义,用于约束返回的数据结构。" +
|
|
274
|
-
"格式: { type: 'json_schema', schema: { type: 'object', properties: {...} } }",
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
required: [],
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
export async function cfExtractJSONFunc(
|
|
282
|
-
args: {
|
|
283
|
-
url?: string;
|
|
284
|
-
html?: string;
|
|
285
|
-
prompt?: string;
|
|
286
|
-
response_format?: object;
|
|
287
|
-
},
|
|
288
|
-
thunkApi: any
|
|
289
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
290
|
-
const { url, html, prompt, response_format } = args;
|
|
291
|
-
|
|
292
|
-
if (!url && !html) throw new Error("必须提供 url 或 html 参数");
|
|
293
|
-
if (!prompt && !response_format) throw new Error("必须提供 prompt 或 response_format");
|
|
294
|
-
const { targetUrl, originalUrl, rewritten } = await resolveCfBrowserUrl(url);
|
|
295
|
-
|
|
296
|
-
const data = await callToolApi<{
|
|
297
|
-
result: unknown;
|
|
298
|
-
success: boolean;
|
|
299
|
-
browserMsUsed?: number;
|
|
300
|
-
source: string;
|
|
301
|
-
}>(
|
|
302
|
-
thunkApi,
|
|
303
|
-
"/api/cf-json",
|
|
304
|
-
{ url: targetUrl, html, prompt, response_format },
|
|
305
|
-
{ withAuth: true }
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
const seconds = data.browserMsUsed ? (data.browserMsUsed / 1000).toFixed(2) : "?";
|
|
309
|
-
const resultStr = JSON.stringify(data.result, null, 2);
|
|
310
|
-
|
|
311
|
-
return {
|
|
312
|
-
rawData: rewritten ? { ...data, originalUrl, resolvedUrl: targetUrl } : data,
|
|
313
|
-
displayData:
|
|
314
|
-
`🔍 结构化数据提取完成\n- 来源: ${data.source}\n- 浏览器耗时: ${seconds}s` +
|
|
315
|
-
buildNormalizationNote(originalUrl, targetUrl) +
|
|
316
|
-
`\n\n` +
|
|
317
|
-
`\`\`\`json\n${resultStr}\n\`\`\``,
|
|
318
|
-
};
|
|
319
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// packages/ai/tools/cfSpeechToTextTool.ts
|
|
2
|
-
// Cloudflare Workers AI Whisper 语音转文字工具
|
|
3
|
-
// Docs: https://developers.cloudflare.com/workers-ai/models/whisper/
|
|
4
|
-
|
|
5
|
-
import { callToolApi } from "./toolApiClient";
|
|
6
|
-
|
|
7
|
-
export const cfSpeechToTextFunctionSchema = {
|
|
8
|
-
name: "cfSpeechToText",
|
|
9
|
-
description:
|
|
10
|
-
"使用 Cloudflare Workers AI (@cf/openai/whisper) 将音频文件转换为文字。" +
|
|
11
|
-
"支持多种语言,自动识别语言。接受公开可访问的音频 URL。" +
|
|
12
|
-
"价格:$0.00045/分钟,适合偶发的语音转写任务。",
|
|
13
|
-
parameters: {
|
|
14
|
-
type: "object",
|
|
15
|
-
properties: {
|
|
16
|
-
audioUrl: {
|
|
17
|
-
type: "string",
|
|
18
|
-
description: "音频文件的公开访问 URL(支持 mp3、wav、flac、ogg 等格式)。",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
required: ["audioUrl"],
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export async function cfSpeechToTextFunc(
|
|
26
|
-
args: { audioUrl: string },
|
|
27
|
-
thunkApi: any
|
|
28
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
29
|
-
const { audioUrl } = args;
|
|
30
|
-
|
|
31
|
-
if (!audioUrl || typeof audioUrl !== "string") {
|
|
32
|
-
throw new Error("必须提供有效的 audioUrl");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const data = await callToolApi<{
|
|
36
|
-
text: string;
|
|
37
|
-
wordCount?: number;
|
|
38
|
-
words?: Array<{ word: string; start: number; end: number }>;
|
|
39
|
-
vtt?: string;
|
|
40
|
-
source: string;
|
|
41
|
-
}>(thunkApi, "/api/cf-speech-to-text", { audioUrl }, { withAuth: true });
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
rawData: data,
|
|
45
|
-
displayData:
|
|
46
|
-
`🎤 语音转文字完成\n- 来源: ${data.source}\n- 字数: ${data.wordCount ?? "?"}\n\n` +
|
|
47
|
-
`**转录内容:**\n\n${data.text}`,
|
|
48
|
-
};
|
|
49
|
-
}
|
package/ai/tools/checkEnvTool.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// 文件路径: packages/ai/tools/checkEnvTool.ts
|
|
2
|
-
// 用于在本地环境执行“生效前检查”(当前最小实现:build)
|
|
3
|
-
|
|
4
|
-
import { callToolApi } from "./toolApiClient";
|
|
5
|
-
|
|
6
|
-
export type CheckEnvArgs = {
|
|
7
|
-
check?: "build" | "context";
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const checkEnvFunctionSchema = {
|
|
11
|
-
name: "checkEnv",
|
|
12
|
-
description: [
|
|
13
|
-
"执行环境检查并返回结构化结果。",
|
|
14
|
-
"check='context' 可查看当前平台、工作目录与可用 shell;check='build' 可快速验证是否可编译。",
|
|
15
|
-
].join("\n"),
|
|
16
|
-
parameters: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
check: {
|
|
20
|
-
type: "string",
|
|
21
|
-
enum: ["build", "context"],
|
|
22
|
-
description: "检查项:context 返回当前运行环境;build 执行构建检查。",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export async function checkEnvFunc(
|
|
29
|
-
args: CheckEnvArgs,
|
|
30
|
-
thunkApi: any
|
|
31
|
-
): Promise<{ rawData: any; displayData: string }> {
|
|
32
|
-
const check = args?.check === "context" ? "context" : "build";
|
|
33
|
-
|
|
34
|
-
const result = await callToolApi<any>(
|
|
35
|
-
thunkApi,
|
|
36
|
-
"/api/check-env",
|
|
37
|
-
{ check }
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const ok = !!result?.ok;
|
|
41
|
-
const exitCode = typeof result?.exitCode === "number" ? result.exitCode : -1;
|
|
42
|
-
|
|
43
|
-
if (check === "context") {
|
|
44
|
-
const displayParts = [
|
|
45
|
-
`平台: ${result?.platform ?? "unknown"}`,
|
|
46
|
-
`cwd: ${result?.cwd ?? "unknown"}`,
|
|
47
|
-
`defaultShell: ${result?.defaultShell ?? "unknown"}`,
|
|
48
|
-
`bash: ${result?.shells?.bash ? "yes" : "no"}`,
|
|
49
|
-
`powershell: ${result?.shells?.powershell ? "yes" : "no"}`,
|
|
50
|
-
`pwsh: ${result?.shells?.pwsh ? "yes" : "no"}`,
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
rawData: result,
|
|
55
|
-
displayData: `🧭 当前环境\n${displayParts.join("\n")}`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
rawData: result,
|
|
61
|
-
displayData: ok
|
|
62
|
-
? `✅ 环境检查通过: ${check}`
|
|
63
|
-
: `❌ 环境检查失败: ${check} (exitCode=${exitCode})`,
|
|
64
|
-
};
|
|
65
|
-
}
|