@insmind/cli 1.4.1 → 1.4.2
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.
|
@@ -121,6 +121,16 @@
|
|
|
121
121
|
"description": {
|
|
122
122
|
"$ref": "#/$defs/NonBlankString"
|
|
123
123
|
},
|
|
124
|
+
"minimum": {
|
|
125
|
+
"type": "number"
|
|
126
|
+
},
|
|
127
|
+
"maximum": {
|
|
128
|
+
"type": "number"
|
|
129
|
+
},
|
|
130
|
+
"step": {
|
|
131
|
+
"type": "number",
|
|
132
|
+
"exclusiveMinimum": 0
|
|
133
|
+
},
|
|
124
134
|
"default": {
|
|
125
135
|
"anyOf": [
|
|
126
136
|
{
|
|
@@ -208,7 +208,12 @@ export function createProductionRuntime(options = {}) {
|
|
|
208
208
|
const validators = createContractValidators({
|
|
209
209
|
organizations: product.exposesOrganizations
|
|
210
210
|
});
|
|
211
|
-
const modelCatalog = createMnsCatalogAdapter({
|
|
211
|
+
const modelCatalog = createMnsCatalogAdapter({
|
|
212
|
+
transport: mnsTransport,
|
|
213
|
+
...(product.id === "insmind"
|
|
214
|
+
? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
|
|
215
|
+
: {})
|
|
216
|
+
});
|
|
212
217
|
const damApi = createDamApiAdapter({ transport: damTransport });
|
|
213
218
|
const damRepositories = createDamRepositoryCatalog({ transport: damTransport });
|
|
214
219
|
const damOperations = createDamOperationExecutor({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
2
|
import addFormatsImport, {} from "ajv-formats";
|
|
3
3
|
import { ToolInputError } from "./catalog.js";
|
|
4
|
-
function parameterSchema(parameter) {
|
|
4
|
+
function parameterSchema(parameter, includeBounds = false) {
|
|
5
5
|
const common = {
|
|
6
6
|
...(parameter.description === undefined ? {} : { description: parameter.description }),
|
|
7
7
|
...(parameter.default === undefined ? {} : { default: parameter.default })
|
|
@@ -11,8 +11,18 @@ function parameterSchema(parameter) {
|
|
|
11
11
|
if (parameter.type === "uri[]") {
|
|
12
12
|
return { type: "array", items: { type: "string", format: "uri" }, ...common };
|
|
13
13
|
}
|
|
14
|
-
if (parameter.type === "number")
|
|
15
|
-
return {
|
|
14
|
+
if (parameter.type === "number") {
|
|
15
|
+
return {
|
|
16
|
+
type: "number",
|
|
17
|
+
...(includeBounds && parameter.minimum !== undefined
|
|
18
|
+
? { minimum: parameter.minimum }
|
|
19
|
+
: {}),
|
|
20
|
+
...(includeBounds && parameter.maximum !== undefined
|
|
21
|
+
? { maximum: parameter.maximum }
|
|
22
|
+
: {}),
|
|
23
|
+
...common
|
|
24
|
+
};
|
|
25
|
+
}
|
|
16
26
|
return {
|
|
17
27
|
type: "string",
|
|
18
28
|
...(parameter.options === undefined
|
|
@@ -78,7 +88,7 @@ export function buildModelArgumentsSchema(model) {
|
|
|
78
88
|
}
|
|
79
89
|
};
|
|
80
90
|
for (const parameter of model.parameters) {
|
|
81
|
-
properties[parameter.name] = parameterSchema(parameter);
|
|
91
|
+
properties[parameter.name] = parameterSchema(parameter, true);
|
|
82
92
|
}
|
|
83
93
|
return {
|
|
84
94
|
type: "object",
|
|
@@ -105,7 +115,7 @@ function controlArgumentsValidator(model) {
|
|
|
105
115
|
|| parameter.type === "uri"
|
|
106
116
|
|| parameter.type === "uri[]")
|
|
107
117
|
continue;
|
|
108
|
-
properties[parameter.name] = parameterSchema(parameter);
|
|
118
|
+
properties[parameter.name] = parameterSchema(parameter, true);
|
|
109
119
|
}
|
|
110
120
|
return ajv.compile({
|
|
111
121
|
type: "object",
|
|
@@ -116,13 +126,31 @@ function controlArgumentsValidator(model) {
|
|
|
116
126
|
}
|
|
117
127
|
export function assertModelArguments(model, value) {
|
|
118
128
|
if (typeof value !== "object" || value === null
|
|
119
|
-
|| !validator(model)(value)
|
|
129
|
+
|| !validator(model)(value)
|
|
130
|
+
|| !sliderStepsAreValid(model, value)) {
|
|
120
131
|
throw new ToolInputError();
|
|
121
132
|
}
|
|
122
133
|
}
|
|
134
|
+
function sliderStepsAreValid(model, value) {
|
|
135
|
+
return model.parameters.every((parameter) => {
|
|
136
|
+
if (parameter.step === undefined || !Object.hasOwn(value, parameter.name))
|
|
137
|
+
return true;
|
|
138
|
+
const candidate = value[parameter.name];
|
|
139
|
+
const minimum = parameter.minimum;
|
|
140
|
+
if (typeof candidate !== "number" || minimum === undefined || parameter.step <= 0) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const steps = (candidate - minimum) / parameter.step;
|
|
144
|
+
const nearestStep = Math.round(steps);
|
|
145
|
+
const expected = minimum + nearestStep * parameter.step;
|
|
146
|
+
const tolerance = Number.EPSILON * Math.max(1, Math.abs(candidate), Math.abs(expected), Math.abs(minimum), Math.abs(nearestStep * parameter.step)) * 2;
|
|
147
|
+
return Math.abs(candidate - expected) <= tolerance;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
123
150
|
export function modelControlArgumentsAreValid(model, value) {
|
|
124
151
|
return typeof value === "object"
|
|
125
152
|
&& value !== null
|
|
126
153
|
&& !Array.isArray(value)
|
|
127
|
-
&& controlArgumentsValidator(model)(value)
|
|
154
|
+
&& controlArgumentsValidator(model)(value)
|
|
155
|
+
&& sliderStepsAreValid(model, value);
|
|
128
156
|
}
|
|
@@ -95,17 +95,33 @@ function parameter(value) {
|
|
|
95
95
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(name))
|
|
96
96
|
return undefined;
|
|
97
97
|
const sourceType = requiredText(field.type);
|
|
98
|
-
const type =
|
|
99
|
-
? "
|
|
100
|
-
: name
|
|
101
|
-
? "uri"
|
|
102
|
-
: sourceType === "
|
|
103
|
-
? "
|
|
104
|
-
: sourceType === "
|
|
105
|
-
? "
|
|
106
|
-
:
|
|
98
|
+
const type = sourceType === "SLIDER"
|
|
99
|
+
? "number"
|
|
100
|
+
: multiUriKeys.has(name)
|
|
101
|
+
? "uri[]"
|
|
102
|
+
: name === "start_frame" || name === "end_frame" || sourceType === "IMAGE"
|
|
103
|
+
? "uri"
|
|
104
|
+
: sourceType === "NUMBER"
|
|
105
|
+
? "number"
|
|
106
|
+
: sourceType === "TEXT" || sourceType === "INPUT" || sourceType === "SELECT"
|
|
107
|
+
? "string"
|
|
108
|
+
: undefined;
|
|
107
109
|
if (type === undefined)
|
|
108
110
|
throw new Error("unsupported parameter");
|
|
111
|
+
let minimum;
|
|
112
|
+
let maximum;
|
|
113
|
+
let step;
|
|
114
|
+
if (sourceType === "SLIDER") {
|
|
115
|
+
if (typeof field.min !== "number" || !Number.isFinite(field.min)
|
|
116
|
+
|| typeof field.max !== "number" || !Number.isFinite(field.max)
|
|
117
|
+
|| typeof field.step !== "number" || !Number.isFinite(field.step)
|
|
118
|
+
|| field.min > field.max || field.step <= 0) {
|
|
119
|
+
throw new Error("invalid slider constraints");
|
|
120
|
+
}
|
|
121
|
+
minimum = field.min;
|
|
122
|
+
maximum = field.max;
|
|
123
|
+
step = field.step;
|
|
124
|
+
}
|
|
109
125
|
let options;
|
|
110
126
|
if (sourceType === "SELECT") {
|
|
111
127
|
if (!Array.isArray(field.options))
|
|
@@ -132,6 +148,9 @@ function parameter(value) {
|
|
|
132
148
|
name,
|
|
133
149
|
type,
|
|
134
150
|
required: field.required === true,
|
|
151
|
+
...(minimum === undefined ? {} : { minimum }),
|
|
152
|
+
...(maximum === undefined ? {} : { maximum }),
|
|
153
|
+
...(step === undefined ? {} : { step }),
|
|
135
154
|
...(description === undefined ? {} : { description }),
|
|
136
155
|
...(hasDefault
|
|
137
156
|
? { default: defaultValue }
|
|
@@ -251,7 +270,8 @@ export function createMnsCatalogAdapter(dependencies) {
|
|
|
251
270
|
models,
|
|
252
271
|
warnings: invalidCount === 0
|
|
253
272
|
? []
|
|
254
|
-
: [
|
|
273
|
+
: [dependencies.invalidModelWarning?.(invalidCount)
|
|
274
|
+
?? `已忽略 ${invalidCount} 个无效模型配置。`]
|
|
255
275
|
};
|
|
256
276
|
}
|
|
257
277
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@gaoding/cli": "workspace:*"
|
|
47
47
|
},
|
|
48
48
|
"gaodingRelease": {
|
|
49
|
-
"sourceCommit": "
|
|
50
|
-
"pipelineId": "
|
|
51
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
49
|
+
"sourceCommit": "d1bad7971a87411d6cc35728f35449915e120f96",
|
|
50
|
+
"pipelineId": "185792",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/185792"
|
|
52
52
|
}
|
|
53
53
|
}
|