openclaw-plugin-model-fetch 0.2.10 → 0.2.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-CN.md +1 -1
- package/README.md +1 -1
- package/dist/agent-tool.d.ts +20 -0
- package/dist/agent-tool.js +118 -0
- package/dist/index.js +2 -3
- package/dist/model-fetch.d.ts +2 -22
- package/dist/model-fetch.js +100 -319
- package/dist/model-replacement.d.ts +29 -0
- package/dist/model-replacement.js +117 -0
- package/dist/operations.d.ts +2 -14
- package/dist/operations.js +25 -364
- package/dist/session-cleanup.d.ts +23 -0
- package/dist/session-cleanup.js +187 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/control-ui-tab.d.ts +0 -31
- package/dist/control-ui-tab.js +0 -42
package/README-CN.md
CHANGED
|
@@ -91,7 +91,7 @@ openclaw plugins doctor
|
|
|
91
91
|
|
|
92
92
|
### 手机 App 里看不到 Model Fetch
|
|
93
93
|
|
|
94
|
-
Android 与 iOS App
|
|
94
|
+
Android 与 iOS App 目前不支持外部插件动态注册页面。Gateway 的 `controlUiTabs` 由 Web Control UI 消费,并不是原生移动 App 的插件页面接口,因此配对权限和重启 App 都无法让 Model Fetch 出现在原生页面列表中。请改用浏览器打开 Control UI;设置页直达地址是 `/settings/plugins/model-fetch?view=settings`。
|
|
95
95
|
|
|
96
96
|
### 获取远端模型失败
|
|
97
97
|
|
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ After an OpenClaw upgrade, the first activation restores Model Fetch as a pinned
|
|
|
91
91
|
|
|
92
92
|
### Model Fetch does not show up in the mobile apps
|
|
93
93
|
|
|
94
|
-
The Android and iOS apps
|
|
94
|
+
The Android and iOS apps do not currently support dynamic page registration for external plugins. The `controlUiTabs` Gateway payload is consumed by the web Control UI, not exposed as a native mobile plugin-page API. Pairing scopes and app restarts cannot add a Model Fetch entry to the native apps. Use the Control UI in a browser instead; the direct settings route is `/settings/plugins/model-fetch?view=settings`.
|
|
95
95
|
|
|
96
96
|
### Fetching remote models fails
|
|
97
97
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyAgentTool, OpenClawPluginApi, OpenClawPluginToolContext } from "openclaw/plugin-sdk/core";
|
|
2
|
+
import { fetchProviderModels } from "./model-fetch.js";
|
|
3
|
+
import { type ModelFetchSessionCleanup } from "./session-cleanup.js";
|
|
4
|
+
import { type ModelFetchConfig, type ModelFetchParams, type ModelFetchToolResult } from "./schemas.js";
|
|
5
|
+
export declare function runModelFetch({ api, toolContext, factoryConfig, fetchModels, params, signal, sessionCleanup, }: {
|
|
6
|
+
api: OpenClawPluginApi;
|
|
7
|
+
toolContext?: OpenClawPluginToolContext;
|
|
8
|
+
factoryConfig?: ModelFetchConfig;
|
|
9
|
+
fetchModels?: typeof fetchProviderModels;
|
|
10
|
+
params: ModelFetchParams;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
sessionCleanup?: ModelFetchSessionCleanup;
|
|
13
|
+
}): Promise<ModelFetchToolResult>;
|
|
14
|
+
export declare function createModelFetchTool({ api, toolContext, factoryConfig, fetchModels, sessionCleanup, }: {
|
|
15
|
+
api: OpenClawPluginApi;
|
|
16
|
+
toolContext: OpenClawPluginToolContext;
|
|
17
|
+
factoryConfig?: ModelFetchConfig;
|
|
18
|
+
fetchModels?: typeof fetchProviderModels;
|
|
19
|
+
sessionCleanup?: ModelFetchSessionCleanup;
|
|
20
|
+
}): AnyAgentTool;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsonResult } from "openclaw/plugin-sdk/tool-results";
|
|
2
|
+
import { applyModelReferenceProtection, fetchProviderModels, getProvider, mergeModels, MODEL_FETCH_TOOL_NAME, resolveApiKey, resolveEffectiveFilter, resolveProviderFilter, resolveProviderTargetAgents, selectFetchedModels, } from "./model-fetch.js";
|
|
3
|
+
import { mutateConfigFileWithRetry, replaceProviderModels } from "./model-replacement.js";
|
|
4
|
+
import { createModelFetchSessionCleanup, } from "./session-cleanup.js";
|
|
5
|
+
import { modelFetchParameters, } from "./schemas.js";
|
|
6
|
+
const CONFIG_PATH = "models.providers.<providerId>.models";
|
|
7
|
+
function currentConfig(api, toolContext) {
|
|
8
|
+
return (toolContext?.getRuntimeConfig?.() ??
|
|
9
|
+
toolContext?.runtimeConfig ??
|
|
10
|
+
toolContext?.config ??
|
|
11
|
+
api.runtime.config.current());
|
|
12
|
+
}
|
|
13
|
+
export async function runModelFetch({ api, toolContext, factoryConfig, fetchModels = fetchProviderModels, params, signal, sessionCleanup, }) {
|
|
14
|
+
const providerId = params.provider.trim();
|
|
15
|
+
if (!providerId)
|
|
16
|
+
throw new Error("Provider id is required.");
|
|
17
|
+
const config = currentConfig(api, toolContext);
|
|
18
|
+
const provider = getProvider(config, providerId);
|
|
19
|
+
const persistedFilter = resolveProviderFilter(providerId, config, factoryConfig);
|
|
20
|
+
const effectiveFilter = resolveEffectiveFilter(persistedFilter, params);
|
|
21
|
+
const apiKey = await resolveApiKey(api, providerId, provider, config);
|
|
22
|
+
const fetched = await fetchModels({
|
|
23
|
+
providerId,
|
|
24
|
+
provider,
|
|
25
|
+
apiKey,
|
|
26
|
+
signal,
|
|
27
|
+
});
|
|
28
|
+
const selected = selectFetchedModels(fetched, effectiveFilter);
|
|
29
|
+
const existing = provider.models ?? [];
|
|
30
|
+
const merge = mergeModels({
|
|
31
|
+
existing,
|
|
32
|
+
selected,
|
|
33
|
+
filter: effectiveFilter,
|
|
34
|
+
});
|
|
35
|
+
let persisted = false;
|
|
36
|
+
let configPath = CONFIG_PATH;
|
|
37
|
+
let added = merge.added;
|
|
38
|
+
let unchanged = merge.unchanged;
|
|
39
|
+
let removedIds = existing
|
|
40
|
+
.map((model) => model.id)
|
|
41
|
+
.filter((id) => !merge.models.some((model) => model.id === id));
|
|
42
|
+
let protectedModels = [];
|
|
43
|
+
if (!params.dryRun) {
|
|
44
|
+
const result = await mutateConfigFileWithRetry(api.runtime, {
|
|
45
|
+
base: "source",
|
|
46
|
+
afterWrite: { mode: "auto" },
|
|
47
|
+
mutate: (draft) => {
|
|
48
|
+
const replacement = replaceProviderModels(draft, {
|
|
49
|
+
providerId,
|
|
50
|
+
provider,
|
|
51
|
+
existingModels: existing,
|
|
52
|
+
mergedModels: merge.models,
|
|
53
|
+
targetAgents: resolveProviderTargetAgents(providerId, draft, factoryConfig),
|
|
54
|
+
});
|
|
55
|
+
const originalIds = new Set(existing.map((model) => model.id));
|
|
56
|
+
added = replacement.finalModels.filter((model) => !originalIds.has(model.id)).length;
|
|
57
|
+
unchanged = selected.filter((model) => originalIds.has(model.id)).length;
|
|
58
|
+
removedIds = replacement.removedIds;
|
|
59
|
+
protectedModels = replacement.protectedModels;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
configPath = result.path;
|
|
63
|
+
persisted = true;
|
|
64
|
+
await (sessionCleanup ?? createModelFetchSessionCleanup({
|
|
65
|
+
currentConfig: () => api.runtime.config.current(),
|
|
66
|
+
})).reset({
|
|
67
|
+
providerId,
|
|
68
|
+
removedIds,
|
|
69
|
+
scope: toolContext,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const protection = applyModelReferenceProtection({
|
|
74
|
+
existing,
|
|
75
|
+
merged: merge.models,
|
|
76
|
+
providerId,
|
|
77
|
+
config,
|
|
78
|
+
});
|
|
79
|
+
protectedModels = protection.protectedModels;
|
|
80
|
+
const finalIds = new Set(protection.models.map((model) => model.id));
|
|
81
|
+
removedIds = existing
|
|
82
|
+
.map((model) => model.id)
|
|
83
|
+
.filter((id) => !finalIds.has(id));
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
provider: providerId,
|
|
87
|
+
fetched: fetched.length,
|
|
88
|
+
selected: merge.selectedIds,
|
|
89
|
+
protectedModels,
|
|
90
|
+
added,
|
|
91
|
+
unchanged,
|
|
92
|
+
removed: removedIds.length,
|
|
93
|
+
replace: effectiveFilter.replace === true,
|
|
94
|
+
dryRun: params.dryRun === true,
|
|
95
|
+
configPath,
|
|
96
|
+
persisted,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function createModelFetchTool({ api, toolContext, factoryConfig, fetchModels = fetchProviderModels, sessionCleanup, }) {
|
|
100
|
+
return {
|
|
101
|
+
name: MODEL_FETCH_TOOL_NAME,
|
|
102
|
+
label: "Fetch Provider Models",
|
|
103
|
+
description: "Fetch a configured provider's model list, apply that provider's independent regex/manual selection strategy, and persist the selected models to OpenClaw config for WebUI use.",
|
|
104
|
+
parameters: modelFetchParameters,
|
|
105
|
+
resultContentSource: "network",
|
|
106
|
+
execute: async (_toolCallId, params, signal) => {
|
|
107
|
+
return jsonResult(await runModelFetch({
|
|
108
|
+
api,
|
|
109
|
+
toolContext,
|
|
110
|
+
factoryConfig,
|
|
111
|
+
fetchModels,
|
|
112
|
+
params,
|
|
113
|
+
signal,
|
|
114
|
+
sessionCleanup,
|
|
115
|
+
}));
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineToolPlugin } from "openclaw/plugin-sdk/tool-plugin";
|
|
2
|
-
import {
|
|
3
|
-
import { createModelFetchTool
|
|
2
|
+
import { MODEL_FETCH_TOOL_NAME, modelFetchConfigSchema, modelFetchParameters, } from "./model-fetch.js";
|
|
3
|
+
import { createModelFetchTool } from "./agent-tool.js";
|
|
4
4
|
import { registerModelFetchOperations } from "./operations.js";
|
|
5
5
|
const entry = defineToolPlugin({
|
|
6
6
|
id: "model-fetch",
|
|
@@ -20,7 +20,6 @@ const entry = defineToolPlugin({
|
|
|
20
20
|
const registerTools = entry.register;
|
|
21
21
|
entry.register = (api) => {
|
|
22
22
|
registerTools?.(api);
|
|
23
|
-
registerControlUiTab(api);
|
|
24
23
|
registerModelFetchOperations(api, {
|
|
25
24
|
factoryConfig: api.pluginConfig,
|
|
26
25
|
});
|
package/dist/model-fetch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
2
|
-
import type {
|
|
2
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
|
3
3
|
import { modelFetchConfigSchema, modelFetchFilterSchema, modelFetchParameters, modelFetchResultSchema, type ModelFetchConfig, type ModelFetchParams, type ModelFetchToolResult, type ModelFilterConfig, type ProtectedModel } from "./schemas.js";
|
|
4
4
|
export declare const MODEL_FETCH_TOOL_NAME = "model_fetch";
|
|
5
5
|
export { modelFetchConfigSchema, modelFetchFilterSchema, modelFetchParameters, modelFetchResultSchema, };
|
|
@@ -71,13 +71,7 @@ export declare function mergeModels({ existing, selected, filter, }: {
|
|
|
71
71
|
selected: ModelDefinitionLike[];
|
|
72
72
|
filter: ModelFilterConfig;
|
|
73
73
|
}): ModelMergeResult;
|
|
74
|
-
/**
|
|
75
|
-
* Rewrites the explicit model references that name `fromRef` to `toRef`.
|
|
76
|
-
*
|
|
77
|
-
* The reference collector only reads, so the walk is repeated here with a
|
|
78
|
-
* writable setter. `forEachExplicitModelReference` reports the exact path of
|
|
79
|
-
* every reference it finds, so the setter mirrors that path shape.
|
|
80
|
-
*/
|
|
74
|
+
/** Rewrites references discovered by the shared read/write walker. */
|
|
81
75
|
export declare function rewriteModelReferences(draft: unknown, fromRef: string, toRef: string): {
|
|
82
76
|
changed: boolean;
|
|
83
77
|
paths: string[];
|
|
@@ -154,17 +148,3 @@ export declare function fetchProviderModels({ providerId, provider, apiKey, sign
|
|
|
154
148
|
}): Promise<ModelDefinitionLike[]>;
|
|
155
149
|
export declare function getProvider(config: unknown, providerId: string): ProviderLike;
|
|
156
150
|
export declare function resolveApiKey(api: OpenClawPluginApi, providerId: string, provider: ProviderLike, config: unknown): Promise<string | undefined>;
|
|
157
|
-
export declare function runModelFetch({ api, toolContext, factoryConfig, fetchModels, params, signal, }: {
|
|
158
|
-
api: OpenClawPluginApi;
|
|
159
|
-
toolContext?: OpenClawPluginToolContext;
|
|
160
|
-
factoryConfig?: ModelFetchConfig;
|
|
161
|
-
fetchModels?: typeof fetchProviderModels;
|
|
162
|
-
params: ModelFetchParams;
|
|
163
|
-
signal?: AbortSignal;
|
|
164
|
-
}): Promise<ModelFetchToolResult>;
|
|
165
|
-
export declare function createModelFetchTool({ api, toolContext, factoryConfig, fetchModels, }: {
|
|
166
|
-
api: OpenClawPluginApi;
|
|
167
|
-
toolContext: OpenClawPluginToolContext;
|
|
168
|
-
factoryConfig?: ModelFetchConfig;
|
|
169
|
-
fetchModels?: typeof fetchProviderModels;
|
|
170
|
-
}): AnyAgentTool;
|