buckyos 0.7.122 → 0.7.124
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/cli/dist/cli.mjs +1 -1
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/version.ts +1 -1
- package/dist/aicc_client.d.ts +1093 -482
- package/dist/aicc_client.d.ts.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +40 -42
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +40 -42
- package/dist/ndm_proxy-357b2a64.js +13 -0
- package/dist/ndm_proxy-357b2a64.js.map +1 -0
- package/dist/{ndm_proxy-8f547002.mjs → ndm_proxy-ebc5a1bf.mjs} +415 -388
- package/dist/ndm_proxy-ebc5a1bf.mjs.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +40 -42
- package/package.json +1 -1
- package/dist/ndm_proxy-8f547002.mjs.map +0 -1
- package/dist/ndm_proxy-93a8869b.js +0 -13
- package/dist/ndm_proxy-93a8869b.js.map +0 -1
|
@@ -498,14 +498,14 @@ var TaskEventType = /* @__PURE__ */ ((TaskEventType2) => {
|
|
|
498
498
|
TaskEventType2["PayloadRedacted"] = "PayloadRedacted";
|
|
499
499
|
return TaskEventType2;
|
|
500
500
|
})(TaskEventType || {});
|
|
501
|
-
function asRecord$
|
|
501
|
+
function asRecord$4(value, what) {
|
|
502
502
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
503
503
|
throw new RPCError(`Expected ${what} in TaskMgr response`);
|
|
504
504
|
}
|
|
505
505
|
return value;
|
|
506
506
|
}
|
|
507
507
|
function requiredField$1(value, field, what) {
|
|
508
|
-
const record = asRecord$
|
|
508
|
+
const record = asRecord$4(value, what);
|
|
509
509
|
if (!(field in record)) {
|
|
510
510
|
throw new RPCError(`Expected ${field} in TaskMgr response`);
|
|
511
511
|
}
|
|
@@ -653,11 +653,11 @@ class TaskManagerClient {
|
|
|
653
653
|
}
|
|
654
654
|
async listTaskSchemas(request = {}) {
|
|
655
655
|
const result = await this.rpcClient.call("list_task_schemas", request);
|
|
656
|
-
const
|
|
657
|
-
if (!Array.isArray(
|
|
656
|
+
const schemas2 = requiredField$1(result, "schemas", "task schema list");
|
|
657
|
+
if (!Array.isArray(schemas2)) {
|
|
658
658
|
throw new RPCError("Expected schemas array in TaskMgr response");
|
|
659
659
|
}
|
|
660
|
-
return
|
|
660
|
+
return schemas2;
|
|
661
661
|
}
|
|
662
662
|
async setTaskSchemaEnabled(schemaId, schemaVersion, enabled) {
|
|
663
663
|
return this.rpcClient.call("set_task_schema_enabled", {
|
|
@@ -883,7 +883,7 @@ var WorkflowScheduledTaskFireStatus = /* @__PURE__ */ ((WorkflowScheduledTaskFir
|
|
|
883
883
|
WorkflowScheduledTaskFireStatus2["Failed"] = "failed";
|
|
884
884
|
return WorkflowScheduledTaskFireStatus2;
|
|
885
885
|
})(WorkflowScheduledTaskFireStatus || {});
|
|
886
|
-
function asRecord$
|
|
886
|
+
function asRecord$3(value) {
|
|
887
887
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
888
888
|
throw new RPCError("Invalid workflow RPC response format");
|
|
889
889
|
}
|
|
@@ -904,7 +904,7 @@ class WorkflowClient {
|
|
|
904
904
|
}
|
|
905
905
|
async callOk(method, params) {
|
|
906
906
|
const result = await this.rpcClient.call(method, params);
|
|
907
|
-
const parsed = asRecord$
|
|
907
|
+
const parsed = asRecord$3(result);
|
|
908
908
|
if (parsed.ok === true) {
|
|
909
909
|
return parsed;
|
|
910
910
|
}
|
|
@@ -1160,17 +1160,16 @@ class SystemConfigClient {
|
|
|
1160
1160
|
await this.rpcClient.call("sys_refresh_trust_keys", {});
|
|
1161
1161
|
}
|
|
1162
1162
|
}
|
|
1163
|
-
const AICC_SERVICE_NAME = "aicc";
|
|
1164
1163
|
const AICC_SERVICE_UNIQUE_ID = "aicc";
|
|
1165
|
-
const AICC_SERVICE_SERVICE_NAME =
|
|
1164
|
+
const AICC_SERVICE_SERVICE_NAME = "aicc";
|
|
1166
1165
|
const AICC_SERVICE_SERVICE_PORT = 4040;
|
|
1167
1166
|
const AICC_AI_METHODS = {
|
|
1168
|
-
|
|
1169
|
-
|
|
1167
|
+
CHAT_COMPLETIONS_CREATE: "chat.completions.create",
|
|
1168
|
+
IMAGES_GENERATE: "images.generate",
|
|
1170
1169
|
EMBEDDING_TEXT: "embedding.text",
|
|
1171
1170
|
EMBEDDING_MULTIMODAL: "embedding.multimodal",
|
|
1172
1171
|
RERANK: "rerank",
|
|
1173
|
-
|
|
1172
|
+
DECISION_EVALUATE: "decision.evaluate",
|
|
1174
1173
|
IMAGE_IMG2IMG: "image.img2img",
|
|
1175
1174
|
IMAGE_INPAINT: "image.inpaint",
|
|
1176
1175
|
IMAGE_UPSCALE: "image.upscale",
|
|
@@ -1190,28 +1189,46 @@ const AICC_AI_METHODS = {
|
|
|
1190
1189
|
VIDEO_UPSCALE: "video.upscale",
|
|
1191
1190
|
AGENT_COMPUTER_USE: "agent.computer_use"
|
|
1192
1191
|
};
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1192
|
+
const AICC_CORE_METHODS = {
|
|
1193
|
+
ROUTE_RESOLVE: "route.resolve",
|
|
1194
|
+
HELPER_LLM_CHAT: "helper.llm_chat",
|
|
1195
|
+
HELPER_TEXT_TO_IMAGE: "helper.text_to_image",
|
|
1196
|
+
CANCEL: "cancel"
|
|
1197
|
+
};
|
|
1198
|
+
const AICC_MANAGEMENT_METHODS = {
|
|
1196
1199
|
SERVICE_RELOAD_SETTINGS: "service.reload_settings",
|
|
1197
1200
|
QUOTA_QUERY: "quota.query",
|
|
1201
|
+
USAGE_QUERY: "usage.query",
|
|
1202
|
+
TRACE_QUERY: "trace.query",
|
|
1203
|
+
ROUTING_GET: "routing.get",
|
|
1204
|
+
ROUTING_PREVIEW: "routing.preview",
|
|
1205
|
+
ROUTING_UPDATE: "routing.update",
|
|
1206
|
+
PROVIDER_CATALOG: "provider.catalog",
|
|
1207
|
+
PROTOCOL_ADAPTER_LIST: "protocol_adapter.list",
|
|
1208
|
+
PROVIDER_VALIDATE: "provider.validate",
|
|
1209
|
+
PROVIDER_ADD: "provider.add",
|
|
1198
1210
|
PROVIDER_LIST: "provider.list",
|
|
1199
|
-
PROVIDER_HEALTH: "provider.health"
|
|
1211
|
+
PROVIDER_HEALTH: "provider.health",
|
|
1212
|
+
PROVIDER_UPDATE: "provider.update",
|
|
1213
|
+
PROVIDER_DELETE: "provider.delete",
|
|
1214
|
+
PROVIDER_REFRESH_MODELS: "provider.refresh_models",
|
|
1215
|
+
MODELS_LIST: "models.list",
|
|
1216
|
+
DRIVER_METADATA_UPDATE_GET: "driver_metadata_update.get",
|
|
1217
|
+
DRIVER_METADATA_UPDATE_SET: "driver_metadata_update.set"
|
|
1200
1218
|
};
|
|
1219
|
+
const AICC_METHODS = { ...AICC_AI_METHODS, ...AICC_CORE_METHODS, ...AICC_MANAGEMENT_METHODS };
|
|
1201
1220
|
const AICC_FEATURES = {
|
|
1202
1221
|
PLAN: "plan",
|
|
1203
|
-
|
|
1204
|
-
|
|
1222
|
+
TOOL_CALL: "tool_call",
|
|
1223
|
+
JSON_SCHEMA: "json_schema",
|
|
1205
1224
|
WEB_SEARCH: "web_search",
|
|
1206
1225
|
VISION: "vision",
|
|
1226
|
+
IMAGE_GENERATION: "image_generation",
|
|
1207
1227
|
ASR: "asr",
|
|
1208
1228
|
VIDEO_UNDERSTAND: "video_understand"
|
|
1209
1229
|
};
|
|
1230
|
+
const AICC_EXECUTION_MODES = { IMMEDIATE: "immediate", STREAM: "stream" };
|
|
1210
1231
|
const AI_METHOD_SET = new Set(Object.values(AICC_AI_METHODS));
|
|
1211
|
-
const CAPABILITY_SET = /* @__PURE__ */ new Set(["llm", "embedding", "rerank", "image", "vision", "audio", "video", "agent"]);
|
|
1212
|
-
const METHOD_STATUS_SET = /* @__PURE__ */ new Set(["succeeded", "running", "failed"]);
|
|
1213
|
-
const AI_ROLE_SET = /* @__PURE__ */ new Set(["system", "user", "assistant", "tool", "developer"]);
|
|
1214
|
-
const NON_TEXT_BLOCK_ESTIMATED_LEN = 256;
|
|
1215
1232
|
function isAiccAiMethod(method) {
|
|
1216
1233
|
return AI_METHOD_SET.has(method);
|
|
1217
1234
|
}
|
|
@@ -1219,390 +1236,402 @@ function aiccTextMessage(role, text) {
|
|
|
1219
1236
|
return { role, content: [{ type: "text", text }] };
|
|
1220
1237
|
}
|
|
1221
1238
|
function aiccMessageTextContent(message) {
|
|
1222
|
-
return message.content.filter((
|
|
1239
|
+
return message.content.filter((b2) => b2.type === "text").map((b2) => b2.text).join("\n");
|
|
1223
1240
|
}
|
|
1224
1241
|
function aiccMessageFirstText(message) {
|
|
1225
1242
|
var _a2;
|
|
1226
|
-
return (_a2 = message.content.find((
|
|
1227
|
-
}
|
|
1228
|
-
function aiccResponseTextContent(response) {
|
|
1229
|
-
return aiccMessageTextContent(response.message);
|
|
1230
|
-
}
|
|
1231
|
-
function aiccResponseToolCalls(response) {
|
|
1232
|
-
return response.message.content.filter((block) => block.type === "tool_use").map((block) => ({
|
|
1233
|
-
name: block.name,
|
|
1234
|
-
args: block.args,
|
|
1235
|
-
call_id: block.call_id
|
|
1236
|
-
}));
|
|
1237
|
-
}
|
|
1238
|
-
function aiccResponseArtifacts(response) {
|
|
1239
|
-
const artifacts = [];
|
|
1240
|
-
response.message.content.forEach((block, index) => {
|
|
1241
|
-
if (block.type === "image") {
|
|
1242
|
-
artifacts.push({
|
|
1243
|
-
name: `image_${index + 1}`,
|
|
1244
|
-
resource: block.source,
|
|
1245
|
-
mime: aiccResourceRefMime(block.source)
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1248
|
-
if (block.type === "document") {
|
|
1249
|
-
artifacts.push({
|
|
1250
|
-
name: block.title ?? `document_${index + 1}`,
|
|
1251
|
-
resource: block.source,
|
|
1252
|
-
mime: aiccResourceRefMime(block.source)
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
return artifacts;
|
|
1257
|
-
}
|
|
1258
|
-
function aiccRenderMessageForDebug(message) {
|
|
1259
|
-
return message.content.map(renderAiccContentForDebug).join("");
|
|
1260
|
-
}
|
|
1261
|
-
function aiccEstimateMessageTextLen(message) {
|
|
1262
|
-
return message.content.reduce((total, block) => {
|
|
1263
|
-
var _a2, _b;
|
|
1264
|
-
if (block.type === "text") {
|
|
1265
|
-
return total + block.text.length;
|
|
1266
|
-
}
|
|
1267
|
-
if (block.type === "thinking") {
|
|
1268
|
-
return total + (((_a2 = block.summary) == null ? void 0 : _a2.length) ?? 0) + (((_b = block.text) == null ? void 0 : _b.length) ?? 0);
|
|
1269
|
-
}
|
|
1270
|
-
return total + NON_TEXT_BLOCK_ESTIMATED_LEN;
|
|
1271
|
-
}, 0);
|
|
1243
|
+
return (_a2 = message.content.find((b2) => b2.type === "text")) == null ? void 0 : _a2.text;
|
|
1272
1244
|
}
|
|
1273
1245
|
function validateAiccMessage(message) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1246
|
+
const allowed = {
|
|
1247
|
+
system: ["text"],
|
|
1248
|
+
developer: ["text"],
|
|
1249
|
+
user: ["text", "image", "document"],
|
|
1250
|
+
assistant: ["text", "image", "document", "tool_use", "thinking", "provider_state"],
|
|
1251
|
+
tool: ["tool_result"]
|
|
1252
|
+
};
|
|
1253
|
+
if (!message || !Array.isArray(message.content) || !allowed[message.role])
|
|
1254
|
+
throw new RPCError("invalid AiMessage");
|
|
1255
|
+
if (message.role === "tool" && (message.content.length !== 1 || message.content[0].type !== "tool_result")) {
|
|
1256
|
+
throw new RPCError("role Tool requires exactly one ToolResult block");
|
|
1282
1257
|
}
|
|
1283
1258
|
for (const block of message.content) {
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
if (
|
|
1307
|
-
throw new RPCError("
|
|
1259
|
+
if (!allowed[message.role].includes(block.type))
|
|
1260
|
+
throw new RPCError(`AiMessage role ${message.role} cannot contain ${block.type} content`);
|
|
1261
|
+
if ((block.type === "tool_use" || block.type === "tool_result") && !block.call_id)
|
|
1262
|
+
throw new RPCError(`${block.type} requires call_id`);
|
|
1263
|
+
if (block.type === "tool_result" && block.content.length === 0)
|
|
1264
|
+
throw new RPCError("tool_result requires non-empty content");
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
function exact(value) {
|
|
1268
|
+
if (!value || value.split("@").length !== 2 || value.startsWith("@") || value.endsWith("@")) {
|
|
1269
|
+
throw new RPCError("exact_model must be `<provider_model_id>[:<variant>]@<provider_instance_name>`");
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
function logical(value) {
|
|
1273
|
+
if (!(value == null ? void 0 : value.trim()) || value.includes("@"))
|
|
1274
|
+
throw new RPCError("logical_model must be a non-empty logical path without `@`");
|
|
1275
|
+
}
|
|
1276
|
+
function strict(request, allowed) {
|
|
1277
|
+
for (const key of Object.keys(request))
|
|
1278
|
+
if (!allowed.includes(key))
|
|
1279
|
+
throw new RPCError(`unknown field \`${key}\``);
|
|
1280
|
+
const mode = request.execution_mode;
|
|
1281
|
+
if (mode !== void 0 && mode !== AICC_EXECUTION_MODES.IMMEDIATE && mode !== AICC_EXECUTION_MODES.STREAM) {
|
|
1282
|
+
throw new RPCError("execution_mode must be `immediate` or `stream`");
|
|
1283
|
+
}
|
|
1284
|
+
const sessionId = request.session_id;
|
|
1285
|
+
if (sessionId !== void 0 && (typeof sessionId !== "string" || !sessionId.trim() || new TextEncoder().encode(sessionId).length > 512)) {
|
|
1286
|
+
throw new RPCError("session_id must contain 1..512 bytes");
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
const common = ["exact_model", "trace_id", "execution_mode", "idempotency_key", "task_options", "session_id"];
|
|
1290
|
+
const schemas = {
|
|
1291
|
+
[AICC_AI_METHODS.CHAT_COMPLETIONS_CREATE]: [...common, "messages", "tools", "response_format", "temperature", "top_p", "max_output_tokens", "seed", "stop", "output"],
|
|
1292
|
+
[AICC_AI_METHODS.IMAGES_GENERATE]: [...common, "prompt", "negative_prompt", "n", "aspect_ratio", "size", "quality", "style", "seed", "output"],
|
|
1293
|
+
[AICC_AI_METHODS.EMBEDDING_TEXT]: [...common, "items", "chunking", "embedding_space_id", "dimensions", "normalize", "prefer_artifact"],
|
|
1294
|
+
[AICC_AI_METHODS.EMBEDDING_MULTIMODAL]: [...common, "items", "dimensions", "normalize"],
|
|
1295
|
+
[AICC_AI_METHODS.DECISION_EVALUATE]: [...common, "state", "questions"],
|
|
1296
|
+
[AICC_AI_METHODS.RERANK]: [...common, "query", "documents", "n", "return_documents"],
|
|
1297
|
+
[AICC_AI_METHODS.IMAGE_IMG2IMG]: [...common, "images", "prompt", "strength", "output"],
|
|
1298
|
+
[AICC_AI_METHODS.IMAGE_INPAINT]: [...common, "image", "mask", "prompt", "mask_semantics", "output"],
|
|
1299
|
+
[AICC_AI_METHODS.IMAGE_UPSCALE]: [...common, "image", "scale", "target_width", "target_height", "preserve_faces", "output"],
|
|
1300
|
+
[AICC_AI_METHODS.IMAGE_BG_REMOVE]: [...common, "image", "mode", "output"],
|
|
1301
|
+
[AICC_AI_METHODS.VISION_OCR]: [...common, "document", "level", "language_hints", "return_layout", "return_artifacts"],
|
|
1302
|
+
[AICC_AI_METHODS.VISION_CAPTION]: [...common, "image", "style", "language", "n"],
|
|
1303
|
+
[AICC_AI_METHODS.VISION_DETECT]: [...common, "image", "classes", "score_threshold", "bbox_spec"],
|
|
1304
|
+
[AICC_AI_METHODS.VISION_SEGMENT]: [...common, "image", "prompt", "mask_format", "return_bitmap_mask"],
|
|
1305
|
+
[AICC_AI_METHODS.AUDIO_TTS]: [...common, "text", "voice", "speed", "output"],
|
|
1306
|
+
[AICC_AI_METHODS.AUDIO_ASR]: [...common, "audio", "language", "timestamps", "diarization", "output_formats"],
|
|
1307
|
+
[AICC_AI_METHODS.AUDIO_MUSIC]: [...common, "prompt", "duration_seconds", "instrumental", "lyrics", "seed", "output"],
|
|
1308
|
+
[AICC_AI_METHODS.AUDIO_ENHANCE]: [...common, "audio", "task", "strength", "return_stems"],
|
|
1309
|
+
[AICC_AI_METHODS.VIDEO_TXT2VIDEO]: [...common, "prompt", "duration_seconds", "aspect_ratio", "resolution", "generate_audio", "seed", "output"],
|
|
1310
|
+
[AICC_AI_METHODS.VIDEO_IMG2VIDEO]: [...common, "image", "prompt", "duration_seconds", "aspect_ratio", "resolution"],
|
|
1311
|
+
[AICC_AI_METHODS.VIDEO_VIDEO2VIDEO]: [...common, "video", "prompt", "preserve_motion", "time_range"],
|
|
1312
|
+
[AICC_AI_METHODS.VIDEO_EXTEND]: [...common, "video", "prompt", "continuation_handle", "duration_seconds", "resolution"],
|
|
1313
|
+
[AICC_AI_METHODS.VIDEO_UPSCALE]: [...common, "video", "target_resolution", "denoise", "sharpen", "output"],
|
|
1314
|
+
[AICC_AI_METHODS.AGENT_COMPUTER_USE]: [...common, "task", "environment", "allowed_actions"],
|
|
1315
|
+
[AICC_CORE_METHODS.ROUTE_RESOLVE]: ["trace_id", "execution_mode", "request_id", "api_type", "logical_model", "requirements", "disable", "policy", "estimated_input_tokens", "estimated_output_tokens", "session_overlay", "session_id"],
|
|
1316
|
+
[AICC_CORE_METHODS.HELPER_LLM_CHAT]: ["logical_model", "trace_id", "execution_mode", "requirements", "disable", "policy", "messages", "tools", "response_format", "temperature", "top_p", "max_output_tokens", "seed", "stop", "output", "idempotency_key", "task_options", "session_overlay", "session_id"],
|
|
1317
|
+
[AICC_CORE_METHODS.HELPER_TEXT_TO_IMAGE]: ["logical_model", "trace_id", "execution_mode", "requirements", "disable", "policy", "prompt", "negative_prompt", "n", "aspect_ratio", "size", "quality", "style", "seed", "output", "idempotency_key", "task_options", "session_overlay", "session_id"],
|
|
1318
|
+
[AICC_CORE_METHODS.CANCEL]: ["task_id"],
|
|
1319
|
+
[AICC_MANAGEMENT_METHODS.SERVICE_RELOAD_SETTINGS]: [],
|
|
1320
|
+
[AICC_MANAGEMENT_METHODS.QUOTA_QUERY]: ["capability", "method"],
|
|
1321
|
+
[AICC_MANAGEMENT_METHODS.USAGE_QUERY]: ["time_range", "filters", "group_by", "time_bucket", "output_mode", "limit", "cursor"],
|
|
1322
|
+
[AICC_MANAGEMENT_METHODS.TRACE_QUERY]: ["limit", "cursor", "start_time_ms", "end_time_ms", "task_ids", "request_ids", "api_types", "provider_instance_names", "selected_exact_models", "scheduler_profiles", "query", "outcome"],
|
|
1323
|
+
[AICC_MANAGEMENT_METHODS.ROUTING_GET]: [],
|
|
1324
|
+
[AICC_MANAGEMENT_METHODS.ROUTING_PREVIEW]: ["paths", "explain", "requirements"],
|
|
1325
|
+
[AICC_MANAGEMENT_METHODS.ROUTING_UPDATE]: ["settings_revision", "provider_weights"],
|
|
1326
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_CATALOG]: [],
|
|
1327
|
+
[AICC_MANAGEMENT_METHODS.PROTOCOL_ADAPTER_LIST]: [],
|
|
1328
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_VALIDATE]: ["provider_instance_name", "provider_type", "provider_profile_id", "protocol_family_id", "protocol_adapter_id", "base_url", "credentials", "region", "workspace", "account", "provider_rules_id", "auth", "discovery", "instance_rules", "timeout_ms", "auto_sync_models"],
|
|
1329
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_ADD]: ["provider_instance_name", "provider_type", "provider_profile_id", "protocol_family_id", "protocol_adapter_id", "base_url", "credentials", "region", "workspace", "account", "provider_rules_id", "auth", "discovery", "instance_rules", "timeout_ms", "auto_sync_models"],
|
|
1330
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_LIST]: ["method"],
|
|
1331
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_HEALTH]: ["exact_model"],
|
|
1332
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_UPDATE]: ["provider_instance_name", "settings_revision", "enabled", "base_url", "credential", "provider_profile_id", "protocol_adapter_id", "discovery", "instance_rules"],
|
|
1333
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_DELETE]: ["provider_instance_name"],
|
|
1334
|
+
[AICC_MANAGEMENT_METHODS.PROVIDER_REFRESH_MODELS]: ["provider_instance_name"],
|
|
1335
|
+
[AICC_MANAGEMENT_METHODS.MODELS_LIST]: [],
|
|
1336
|
+
[AICC_MANAGEMENT_METHODS.DRIVER_METADATA_UPDATE_GET]: [],
|
|
1337
|
+
[AICC_MANAGEMENT_METHODS.DRIVER_METADATA_UPDATE_SET]: ["enabled", "source_url", "interval_secs"]
|
|
1338
|
+
};
|
|
1339
|
+
class AiccClient {
|
|
1340
|
+
constructor(rpcClient) {
|
|
1341
|
+
this.rpcClient = rpcClient;
|
|
1308
1342
|
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
switch (block.type) {
|
|
1312
|
-
case "text":
|
|
1313
|
-
return block.text;
|
|
1314
|
-
case "image":
|
|
1315
|
-
return "[image]";
|
|
1316
|
-
case "document":
|
|
1317
|
-
return block.title ? `[document title=${block.title}]` : "[document]";
|
|
1318
|
-
case "tool_use":
|
|
1319
|
-
return `[tool_use name=${block.name} call_id=${block.call_id}]`;
|
|
1320
|
-
case "tool_result":
|
|
1321
|
-
return `[tool_result call_id=${block.call_id}${block.is_error ? " is_error=true" : ""}]`;
|
|
1322
|
-
case "thinking":
|
|
1323
|
-
return block.text ?? block.summary ?? "[thinking]";
|
|
1324
|
-
case "provider_state":
|
|
1325
|
-
return `[provider_state provider=${block.provider}]`;
|
|
1343
|
+
setSeq(seq) {
|
|
1344
|
+
this.rpcClient.setSeq(seq);
|
|
1326
1345
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
return resource.mime;
|
|
1334
|
-
case "named_object":
|
|
1335
|
-
return null;
|
|
1346
|
+
call(method, request) {
|
|
1347
|
+
const schema = schemas[method];
|
|
1348
|
+
const params = (schema == null ? void 0 : schema.includes("execution_mode")) && request.execution_mode === void 0 ? { ...request, execution_mode: AICC_EXECUTION_MODES.IMMEDIATE } : request;
|
|
1349
|
+
if (schema)
|
|
1350
|
+
strict(params, schema);
|
|
1351
|
+
return this.rpcClient.call(method, params);
|
|
1336
1352
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
throw new RPCError(`AiccMessage contains an invalid content block for role ${role}`);
|
|
1353
|
+
inference(method, request) {
|
|
1354
|
+
exact(request.exact_model);
|
|
1355
|
+
return this.call(method, request);
|
|
1341
1356
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1357
|
+
routeResolve(r) {
|
|
1358
|
+
logical(r.logical_model);
|
|
1359
|
+
return this.call(AICC_CORE_METHODS.ROUTE_RESOLVE, r);
|
|
1344
1360
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1361
|
+
chatCompletionsCreate(r) {
|
|
1362
|
+
r.messages.forEach(validateAiccMessage);
|
|
1363
|
+
return this.inference(AICC_AI_METHODS.CHAT_COMPLETIONS_CREATE, r);
|
|
1347
1364
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1365
|
+
imagesGenerate(r) {
|
|
1366
|
+
return this.inference(AICC_AI_METHODS.IMAGES_GENERATE, r);
|
|
1350
1367
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1368
|
+
helperLlmChat(r) {
|
|
1369
|
+
logical(r.logical_model);
|
|
1370
|
+
r.messages.forEach(validateAiccMessage);
|
|
1371
|
+
return this.call(AICC_CORE_METHODS.HELPER_LLM_CHAT, r);
|
|
1353
1372
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1373
|
+
helperTextToImage(r) {
|
|
1374
|
+
logical(r.logical_model);
|
|
1375
|
+
return this.call(AICC_CORE_METHODS.HELPER_TEXT_TO_IMAGE, r);
|
|
1358
1376
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1377
|
+
embeddingText(r) {
|
|
1378
|
+
return this.inference(AICC_AI_METHODS.EMBEDDING_TEXT, r);
|
|
1361
1379
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
if (!content || typeof content !== "object" || Array.isArray(content)) {
|
|
1365
|
-
throw new RPCError("AiccToolResultContent must be an object");
|
|
1380
|
+
embeddingMultimodal(r) {
|
|
1381
|
+
return this.inference(AICC_AI_METHODS.EMBEDDING_MULTIMODAL, r);
|
|
1366
1382
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
case "image":
|
|
1374
|
-
if (!content.source) {
|
|
1375
|
-
throw new RPCError("AiccToolResultContent.image requires source");
|
|
1376
|
-
}
|
|
1377
|
-
return;
|
|
1378
|
-
case "document":
|
|
1379
|
-
if (!content.source) {
|
|
1380
|
-
throw new RPCError("AiccToolResultContent.document requires source");
|
|
1381
|
-
}
|
|
1382
|
-
return;
|
|
1383
|
-
default:
|
|
1384
|
-
throw new RPCError(`AiccToolResultContent type is invalid: ${String(content.type)}`);
|
|
1383
|
+
async decisionEvaluate(r) {
|
|
1384
|
+
validateDecisionRequest(r);
|
|
1385
|
+
const result = await this.inference(AICC_AI_METHODS.DECISION_EVALUATE, r);
|
|
1386
|
+
if (result.status === "succeeded")
|
|
1387
|
+
validateDecisionAnswers(r, result.answers ?? []);
|
|
1388
|
+
return result;
|
|
1385
1389
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
switch (role) {
|
|
1389
|
-
case "system":
|
|
1390
|
-
case "developer":
|
|
1391
|
-
return blockType === "text";
|
|
1392
|
-
case "user":
|
|
1393
|
-
return blockType === "text" || blockType === "image" || blockType === "document";
|
|
1394
|
-
case "assistant":
|
|
1395
|
-
return blockType === "text" || blockType === "image" || blockType === "document" || blockType === "tool_use" || blockType === "thinking" || blockType === "provider_state";
|
|
1396
|
-
case "tool":
|
|
1397
|
-
return blockType === "tool_result";
|
|
1390
|
+
rerank(r) {
|
|
1391
|
+
return this.inference(AICC_AI_METHODS.RERANK, r);
|
|
1398
1392
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1402
|
-
throw new RPCError("Invalid RPC response format");
|
|
1393
|
+
imageToImage(r) {
|
|
1394
|
+
return this.inference(AICC_AI_METHODS.IMAGE_IMG2IMG, r);
|
|
1403
1395
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
function rejectDeprecatedRequestFields(request) {
|
|
1407
|
-
const requirements = request.requirements;
|
|
1408
|
-
if ("resp_foramt" in requirements) {
|
|
1409
|
-
throw new RPCError("AiccRequirements.resp_foramt is no longer supported; use resp_format");
|
|
1396
|
+
imageInpaint(r) {
|
|
1397
|
+
return this.inference(AICC_AI_METHODS.IMAGE_INPAINT, r);
|
|
1410
1398
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (key in payload) {
|
|
1414
|
-
throw new RPCError(`AiccPayload.${key} is no longer supported; put method fields under payload.input_json`);
|
|
1415
|
-
}
|
|
1399
|
+
imageUpscale(r) {
|
|
1400
|
+
return this.inference(AICC_AI_METHODS.IMAGE_UPSCALE, r);
|
|
1416
1401
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
if (!request.capability || !CAPABILITY_SET.has(request.capability)) {
|
|
1420
|
-
throw new RPCError("AiccMethodRequest.capability is invalid");
|
|
1402
|
+
imageBackgroundRemove(r) {
|
|
1403
|
+
return this.inference(AICC_AI_METHODS.IMAGE_BG_REMOVE, r);
|
|
1421
1404
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1405
|
+
visionOcr(r) {
|
|
1406
|
+
return this.inference(AICC_AI_METHODS.VISION_OCR, r);
|
|
1424
1407
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1408
|
+
visionCaption(r) {
|
|
1409
|
+
return this.inference(AICC_AI_METHODS.VISION_CAPTION, r);
|
|
1427
1410
|
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1411
|
+
visionDetect(r) {
|
|
1412
|
+
return this.inference(AICC_AI_METHODS.VISION_DETECT, r);
|
|
1430
1413
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
...request,
|
|
1434
|
-
payload: {
|
|
1435
|
-
input_json: request.payload.input_json ?? {},
|
|
1436
|
-
resources: request.payload.resources ?? [],
|
|
1437
|
-
options: request.payload.options ?? {}
|
|
1438
|
-
}
|
|
1439
|
-
};
|
|
1440
|
-
}
|
|
1441
|
-
function validateLlmChatPayload(request) {
|
|
1442
|
-
const input = request.payload.input_json;
|
|
1443
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
1444
|
-
throw new RPCError("AiccLlmChatInput must be an object");
|
|
1414
|
+
visionSegment(r) {
|
|
1415
|
+
return this.inference(AICC_AI_METHODS.VISION_SEGMENT, r);
|
|
1445
1416
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
function parseMethodResponse(result) {
|
|
1450
|
-
const record = asRecord$3(result);
|
|
1451
|
-
if (typeof record.task_id !== "string") {
|
|
1452
|
-
throw new RPCError("AiccMethodResponse missing task_id");
|
|
1417
|
+
audioTextToSpeech(r) {
|
|
1418
|
+
return this.inference(AICC_AI_METHODS.AUDIO_TTS, r);
|
|
1453
1419
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1420
|
+
audioSpeechRecognition(r) {
|
|
1421
|
+
return this.inference(AICC_AI_METHODS.AUDIO_ASR, r);
|
|
1456
1422
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1423
|
+
audioMusic(r) {
|
|
1424
|
+
return this.inference(AICC_AI_METHODS.AUDIO_MUSIC, r);
|
|
1459
1425
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
function normalizeModel(model) {
|
|
1463
|
-
if (typeof model === "string") {
|
|
1464
|
-
return { alias: model };
|
|
1426
|
+
audioEnhance(r) {
|
|
1427
|
+
return this.inference(AICC_AI_METHODS.AUDIO_ENHANCE, r);
|
|
1465
1428
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
function buildTypedMethodRequest(capability, request) {
|
|
1469
|
-
return {
|
|
1470
|
-
capability,
|
|
1471
|
-
model: normalizeModel(request.model),
|
|
1472
|
-
requirements: request.requirements ?? {},
|
|
1473
|
-
payload: {
|
|
1474
|
-
input_json: request.input,
|
|
1475
|
-
resources: request.resources ?? [],
|
|
1476
|
-
options: request.options ?? {}
|
|
1477
|
-
},
|
|
1478
|
-
policy: request.policy,
|
|
1479
|
-
idempotency_key: request.idempotency_key,
|
|
1480
|
-
task_options: request.task_options
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
class AiccClient {
|
|
1484
|
-
constructor(rpcClient) {
|
|
1485
|
-
this.rpcClient = rpcClient;
|
|
1429
|
+
videoTextToVideo(r) {
|
|
1430
|
+
return this.inference(AICC_AI_METHODS.VIDEO_TXT2VIDEO, r);
|
|
1486
1431
|
}
|
|
1487
|
-
|
|
1488
|
-
this.
|
|
1432
|
+
videoImageToVideo(r) {
|
|
1433
|
+
return this.inference(AICC_AI_METHODS.VIDEO_IMG2VIDEO, r);
|
|
1489
1434
|
}
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
throw new RPCError(`Unknown AICC AI method: ${method}`);
|
|
1493
|
-
}
|
|
1494
|
-
const normalizedRequest = normalizeMethodRequest(request);
|
|
1495
|
-
if (method === AICC_AI_METHODS.LLM_CHAT) {
|
|
1496
|
-
validateLlmChatPayload(normalizedRequest);
|
|
1497
|
-
}
|
|
1498
|
-
const result = await this.rpcClient.call(method, normalizedRequest);
|
|
1499
|
-
return parseMethodResponse(result);
|
|
1435
|
+
videoToVideo(r) {
|
|
1436
|
+
return this.inference(AICC_AI_METHODS.VIDEO_VIDEO2VIDEO, r);
|
|
1500
1437
|
}
|
|
1501
|
-
|
|
1502
|
-
return this.
|
|
1438
|
+
videoExtend(r) {
|
|
1439
|
+
return this.inference(AICC_AI_METHODS.VIDEO_EXTEND, r);
|
|
1503
1440
|
}
|
|
1504
|
-
|
|
1505
|
-
return this.
|
|
1441
|
+
videoUpscale(r) {
|
|
1442
|
+
return this.inference(AICC_AI_METHODS.VIDEO_UPSCALE, r);
|
|
1506
1443
|
}
|
|
1507
|
-
|
|
1508
|
-
return this.
|
|
1444
|
+
computerUse(r) {
|
|
1445
|
+
return this.inference(AICC_AI_METHODS.AGENT_COMPUTER_USE, r);
|
|
1509
1446
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
);
|
|
1447
|
+
cancel(taskId) {
|
|
1448
|
+
if (!taskId)
|
|
1449
|
+
throw new RPCError("cancel requires non-empty task_id");
|
|
1450
|
+
return this.call(AICC_CORE_METHODS.CANCEL, { task_id: taskId });
|
|
1515
1451
|
}
|
|
1516
|
-
|
|
1517
|
-
return this.
|
|
1452
|
+
reloadSettings() {
|
|
1453
|
+
return this.call(AICC_MANAGEMENT_METHODS.SERVICE_RELOAD_SETTINGS, {});
|
|
1518
1454
|
}
|
|
1519
|
-
|
|
1520
|
-
return this.
|
|
1455
|
+
queryQuota(r = {}) {
|
|
1456
|
+
return this.call(AICC_MANAGEMENT_METHODS.QUOTA_QUERY, r);
|
|
1521
1457
|
}
|
|
1522
|
-
|
|
1523
|
-
return this.
|
|
1458
|
+
queryUsage(r) {
|
|
1459
|
+
return this.call(AICC_MANAGEMENT_METHODS.USAGE_QUERY, r);
|
|
1524
1460
|
}
|
|
1525
|
-
|
|
1526
|
-
return this.
|
|
1461
|
+
queryTrace(r = {}) {
|
|
1462
|
+
return this.call(AICC_MANAGEMENT_METHODS.TRACE_QUERY, r);
|
|
1527
1463
|
}
|
|
1528
|
-
|
|
1529
|
-
return this.
|
|
1464
|
+
previewRouting(r = {}) {
|
|
1465
|
+
return this.call(AICC_MANAGEMENT_METHODS.ROUTING_PREVIEW, r);
|
|
1530
1466
|
}
|
|
1531
|
-
|
|
1532
|
-
return this.
|
|
1467
|
+
getRouting() {
|
|
1468
|
+
return this.call(AICC_MANAGEMENT_METHODS.ROUTING_GET, {});
|
|
1533
1469
|
}
|
|
1534
|
-
|
|
1535
|
-
return this.
|
|
1470
|
+
updateRouting(r) {
|
|
1471
|
+
return this.call(AICC_MANAGEMENT_METHODS.ROUTING_UPDATE, r);
|
|
1536
1472
|
}
|
|
1537
|
-
|
|
1538
|
-
return this.
|
|
1473
|
+
providerCatalog() {
|
|
1474
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_CATALOG, {});
|
|
1539
1475
|
}
|
|
1540
|
-
|
|
1541
|
-
return this.
|
|
1476
|
+
listProtocolAdapters() {
|
|
1477
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROTOCOL_ADAPTER_LIST, {});
|
|
1542
1478
|
}
|
|
1543
|
-
|
|
1544
|
-
return this.
|
|
1479
|
+
validateProvider(r) {
|
|
1480
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_VALIDATE, r);
|
|
1545
1481
|
}
|
|
1546
|
-
|
|
1547
|
-
return this.
|
|
1482
|
+
addProvider(r) {
|
|
1483
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_ADD, r);
|
|
1548
1484
|
}
|
|
1549
|
-
|
|
1550
|
-
return this.
|
|
1485
|
+
listProviders(r = {}) {
|
|
1486
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_LIST, r);
|
|
1551
1487
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1488
|
+
providerHealth(r) {
|
|
1489
|
+
exact(r.exact_model);
|
|
1490
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_HEALTH, r);
|
|
1554
1491
|
}
|
|
1555
|
-
|
|
1556
|
-
return this.
|
|
1492
|
+
updateProvider(r) {
|
|
1493
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_UPDATE, r);
|
|
1557
1494
|
}
|
|
1558
|
-
|
|
1559
|
-
return this.
|
|
1495
|
+
deleteProvider(r) {
|
|
1496
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_DELETE, r);
|
|
1560
1497
|
}
|
|
1561
|
-
|
|
1562
|
-
return this.
|
|
1498
|
+
refreshProviderModels(r) {
|
|
1499
|
+
return this.call(AICC_MANAGEMENT_METHODS.PROVIDER_REFRESH_MODELS, r);
|
|
1563
1500
|
}
|
|
1564
|
-
|
|
1565
|
-
return this.
|
|
1566
|
-
}
|
|
1567
|
-
async videoExtend(request) {
|
|
1568
|
-
return this.callMethod(AICC_AI_METHODS.VIDEO_EXTEND, buildTypedMethodRequest("video", request));
|
|
1569
|
-
}
|
|
1570
|
-
async videoUpscale(request) {
|
|
1571
|
-
return this.callMethod(AICC_AI_METHODS.VIDEO_UPSCALE, buildTypedMethodRequest("video", request));
|
|
1572
|
-
}
|
|
1573
|
-
async agentComputerUse(request) {
|
|
1574
|
-
return this.callMethod(AICC_AI_METHODS.AGENT_COMPUTER_USE, buildTypedMethodRequest("agent", request));
|
|
1575
|
-
}
|
|
1576
|
-
async cancel(taskId) {
|
|
1577
|
-
if (!taskId) {
|
|
1578
|
-
throw new RPCError("AiccClient.cancel requires a non-empty task_id");
|
|
1579
|
-
}
|
|
1580
|
-
const result = await this.rpcClient.call(AICC_CONTROL_METHODS.CANCEL, { task_id: taskId });
|
|
1581
|
-
const record = asRecord$3(result);
|
|
1582
|
-
if (typeof record.task_id !== "string" || typeof record.accepted !== "boolean") {
|
|
1583
|
-
throw new RPCError("Invalid cancel response");
|
|
1584
|
-
}
|
|
1585
|
-
return { task_id: record.task_id, accepted: record.accepted };
|
|
1501
|
+
listModels() {
|
|
1502
|
+
return this.call(AICC_MANAGEMENT_METHODS.MODELS_LIST, {});
|
|
1586
1503
|
}
|
|
1587
|
-
|
|
1588
|
-
return this.
|
|
1504
|
+
getDriverMetadataUpdate() {
|
|
1505
|
+
return this.call(AICC_MANAGEMENT_METHODS.DRIVER_METADATA_UPDATE_GET, {});
|
|
1589
1506
|
}
|
|
1590
|
-
|
|
1591
|
-
return this.
|
|
1507
|
+
setDriverMetadataUpdate(r) {
|
|
1508
|
+
return this.call(AICC_MANAGEMENT_METHODS.DRIVER_METADATA_UPDATE_SET, r);
|
|
1592
1509
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1510
|
+
}
|
|
1511
|
+
function decisionText(value, nonempty = true) {
|
|
1512
|
+
if (typeof value === "string")
|
|
1513
|
+
return !nonempty || value.trim().length > 0;
|
|
1514
|
+
return value !== null && typeof value === "object" && (!nonempty || Object.keys(value).length > 0);
|
|
1515
|
+
}
|
|
1516
|
+
function decisionId(value) {
|
|
1517
|
+
return typeof value === "string" && /^[A-Za-z0-9_.-]{1,128}$/.test(value);
|
|
1518
|
+
}
|
|
1519
|
+
function decisionJson(value) {
|
|
1520
|
+
if (value === null || typeof value !== "object")
|
|
1521
|
+
return JSON.stringify(value);
|
|
1522
|
+
if (Array.isArray(value))
|
|
1523
|
+
return `[${value.map(decisionJson).join(",")}]`;
|
|
1524
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${decisionJson(value[key])}`).join(",")}}`;
|
|
1525
|
+
}
|
|
1526
|
+
function decisionBytes(value) {
|
|
1527
|
+
return new TextEncoder().encode(JSON.stringify(value)).length;
|
|
1528
|
+
}
|
|
1529
|
+
function decisionRequirements(request) {
|
|
1530
|
+
const stateBytes = decisionBytes(request.state);
|
|
1531
|
+
const decision = {
|
|
1532
|
+
question_types: [],
|
|
1533
|
+
structured_state: typeof request.state !== "string",
|
|
1534
|
+
structured_rules: false,
|
|
1535
|
+
question_count: request.questions.length,
|
|
1536
|
+
max_options: 0,
|
|
1537
|
+
max_levels: 0,
|
|
1538
|
+
input_bytes: stateBytes + decisionBytes(request.questions),
|
|
1539
|
+
max_state_question_bytes: 0
|
|
1540
|
+
};
|
|
1541
|
+
for (const question of request.questions) {
|
|
1542
|
+
if (!decision.question_types.includes(question.type))
|
|
1543
|
+
decision.question_types.push(question.type);
|
|
1544
|
+
const rules = [question.instructions];
|
|
1545
|
+
if (question.type === "choice") {
|
|
1546
|
+
decision.max_options = Math.max(decision.max_options, question.options.length);
|
|
1547
|
+
rules.push(...question.options.map((option) => option.description));
|
|
1548
|
+
} else if (question.type === "score") {
|
|
1549
|
+
decision.max_levels = Math.max(decision.max_levels, question.levels.length);
|
|
1550
|
+
rules.push(...question.levels);
|
|
1551
|
+
} else if (question.criteria)
|
|
1552
|
+
rules.push(...Object.values(question.criteria));
|
|
1553
|
+
decision.structured_rules || (decision.structured_rules = rules.some((value) => value !== null && typeof value === "object"));
|
|
1554
|
+
decision.max_state_question_bytes = Math.max(decision.max_state_question_bytes, stateBytes + decisionBytes(question));
|
|
1555
|
+
}
|
|
1556
|
+
return { decision };
|
|
1557
|
+
}
|
|
1558
|
+
function validateDecisionRequest(request) {
|
|
1559
|
+
exact(request.exact_model);
|
|
1560
|
+
strict(request, schemas[AICC_AI_METHODS.DECISION_EVALUATE]);
|
|
1561
|
+
if (!decisionText(request.state, false) || !Array.isArray(request.questions) || !request.questions.length || request.questions.length > 1024) {
|
|
1562
|
+
throw new RPCError("decision requires a text/JSON state and 1..1024 questions");
|
|
1563
|
+
}
|
|
1564
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1565
|
+
for (const question of request.questions) {
|
|
1566
|
+
if (!question || !decisionId(question.id) || ids.has(question.id) || !decisionText(question.instructions))
|
|
1567
|
+
throw new RPCError("invalid decision question");
|
|
1568
|
+
ids.add(question.id);
|
|
1569
|
+
if (question.type === "choice") {
|
|
1570
|
+
strict(question, ["type", "id", "instructions", "options"]);
|
|
1571
|
+
if (!Array.isArray(question.options) || !question.options.length || question.options.length > 1024)
|
|
1572
|
+
throw new RPCError("invalid decision options");
|
|
1573
|
+
const options = /* @__PURE__ */ new Set();
|
|
1574
|
+
for (const option of question.options) {
|
|
1575
|
+
strict(option, ["id", "description"]);
|
|
1576
|
+
if (!decisionId(option.id) || options.has(option.id) || !(option.description === null || decisionText(option.description)))
|
|
1577
|
+
throw new RPCError("invalid decision option");
|
|
1578
|
+
options.add(option.id);
|
|
1579
|
+
}
|
|
1580
|
+
} else if (question.type === "score") {
|
|
1581
|
+
strict(question, ["type", "id", "instructions", "levels"]);
|
|
1582
|
+
if (!Array.isArray(question.levels) || question.levels.length < 2 || question.levels.length > 1024 || question.levels.some((level) => !decisionText(level)) || new Set(question.levels.map(decisionJson)).size !== question.levels.length)
|
|
1583
|
+
throw new RPCError("invalid decision levels");
|
|
1584
|
+
} else if (question.type === "boolean") {
|
|
1585
|
+
strict(question, ["type", "id", "instructions", "criteria"]);
|
|
1586
|
+
if (question.criteria !== void 0) {
|
|
1587
|
+
if (question.criteria === null || typeof question.criteria !== "object" || Array.isArray(question.criteria))
|
|
1588
|
+
throw new RPCError("invalid decision criteria");
|
|
1589
|
+
strict(question.criteria, ["true", "false"]);
|
|
1590
|
+
if (Object.values(question.criteria).some((value) => !decisionText(value)))
|
|
1591
|
+
throw new RPCError("invalid decision criteria");
|
|
1592
|
+
}
|
|
1593
|
+
} else
|
|
1594
|
+
throw new RPCError("invalid decision question type");
|
|
1595
|
+
}
|
|
1596
|
+
if (decisionRequirements(request).decision.input_bytes > 1024 * 1024)
|
|
1597
|
+
throw new RPCError("decision input exceeds 1 MiB");
|
|
1598
|
+
}
|
|
1599
|
+
function validateDecisionAnswers(request, answers) {
|
|
1600
|
+
const probability = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
1601
|
+
const invalid = () => {
|
|
1602
|
+
throw new RPCError("invalid or incomplete decision answers");
|
|
1603
|
+
};
|
|
1604
|
+
if (!Array.isArray(answers) || answers.length !== request.questions.length)
|
|
1605
|
+
invalid();
|
|
1606
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1607
|
+
for (const answer of answers) {
|
|
1608
|
+
if (!answer || ids.has(answer.id))
|
|
1609
|
+
invalid();
|
|
1610
|
+
ids.add(answer.id);
|
|
1611
|
+
const question = request.questions.find((question2) => question2.id === answer.id);
|
|
1612
|
+
if (!question)
|
|
1613
|
+
throw new RPCError("unknown decision question ID");
|
|
1614
|
+
if (question.type !== answer.type || answer.confidence !== void 0 && !probability(answer.confidence))
|
|
1615
|
+
invalid();
|
|
1616
|
+
if (answer.type === "boolean") {
|
|
1617
|
+
strict(answer, ["type", "id", "probability_true", "confidence"]);
|
|
1618
|
+
if (!probability(answer.probability_true))
|
|
1619
|
+
invalid();
|
|
1620
|
+
continue;
|
|
1598
1621
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1622
|
+
strict(answer, answer.type === "choice" ? ["type", "id", "selected", "probabilities", "confidence"] : ["type", "id", "score", "levels", "probabilities", "confidence"]);
|
|
1623
|
+
const keys = question.type === "choice" ? question.options.map((option) => option.id) : question.type === "score" ? question.levels.map((_, i) => String(i)) : [];
|
|
1624
|
+
if (!answer.probabilities || Array.isArray(answer.probabilities) || Object.keys(answer.probabilities).length !== keys.length || keys.some((key) => !Object.prototype.hasOwnProperty.call(answer.probabilities, key) || !probability(answer.probabilities[key])) || Math.abs(Object.values(answer.probabilities).reduce((sum, p) => sum + p, 0) - 1) > 1e-4)
|
|
1625
|
+
invalid();
|
|
1626
|
+
if (answer.type === "choice") {
|
|
1627
|
+
if (!keys.includes(answer.selected) || Object.values(answer.probabilities).some((p) => p > answer.probabilities[answer.selected] + 1e-4))
|
|
1628
|
+
invalid();
|
|
1629
|
+
} else if (answer.type === "score" && question.type === "score") {
|
|
1630
|
+
const expected = keys.reduce((sum, key, i) => sum + i * answer.probabilities[key], 0);
|
|
1631
|
+
if (!Number.isFinite(answer.score) || answer.score < 0 || answer.score > keys.length - 1 || Math.abs(answer.score - expected) > 1e-4 * (keys.length - 1) || decisionJson(answer.levels) !== decisionJson(question.levels))
|
|
1632
|
+
invalid();
|
|
1633
|
+
} else
|
|
1634
|
+
invalid();
|
|
1606
1635
|
}
|
|
1607
1636
|
}
|
|
1608
1637
|
const DEFAULT_QUEUE_CONFIG = {
|
|
@@ -28417,7 +28446,7 @@ export {
|
|
|
28417
28446
|
TASK_ERR_STALE_RUNNER_EPOCH as Z,
|
|
28418
28447
|
TASK_ERR_INVALID_PHASE as _,
|
|
28419
28448
|
ndm_proxy as a,
|
|
28420
|
-
|
|
28449
|
+
BNS_EVM_DEFAULT_MAX_FEE_PER_GAS as a$,
|
|
28421
28450
|
TASK_ERR_CONTROL_ALREADY_PENDING as a0,
|
|
28422
28451
|
TASK_ERR_ALREADY_COMPLETED as a1,
|
|
28423
28452
|
TASK_ERR_INPUT_SCHEMA_MISMATCH as a2,
|
|
@@ -28429,32 +28458,32 @@ export {
|
|
|
28429
28458
|
taskMgrTreeEventPath as a8,
|
|
28430
28459
|
taskMgrErrorCode as a9,
|
|
28431
28460
|
WorkflowClient as aA,
|
|
28432
|
-
|
|
28433
|
-
|
|
28434
|
-
|
|
28435
|
-
|
|
28436
|
-
|
|
28437
|
-
|
|
28438
|
-
|
|
28439
|
-
|
|
28440
|
-
|
|
28441
|
-
|
|
28442
|
-
|
|
28443
|
-
|
|
28444
|
-
|
|
28445
|
-
|
|
28446
|
-
|
|
28447
|
-
|
|
28448
|
-
|
|
28449
|
-
|
|
28450
|
-
|
|
28451
|
-
|
|
28452
|
-
|
|
28453
|
-
|
|
28454
|
-
|
|
28455
|
-
|
|
28456
|
-
|
|
28457
|
-
|
|
28461
|
+
AICC_SERVICE_UNIQUE_ID as aB,
|
|
28462
|
+
AICC_SERVICE_SERVICE_NAME as aC,
|
|
28463
|
+
AICC_SERVICE_SERVICE_PORT as aD,
|
|
28464
|
+
AICC_AI_METHODS as aE,
|
|
28465
|
+
AICC_CORE_METHODS as aF,
|
|
28466
|
+
AICC_MANAGEMENT_METHODS as aG,
|
|
28467
|
+
AICC_METHODS as aH,
|
|
28468
|
+
AICC_FEATURES as aI,
|
|
28469
|
+
AICC_EXECUTION_MODES as aJ,
|
|
28470
|
+
isAiccAiMethod as aK,
|
|
28471
|
+
aiccTextMessage as aL,
|
|
28472
|
+
aiccMessageTextContent as aM,
|
|
28473
|
+
aiccMessageFirstText as aN,
|
|
28474
|
+
validateAiccMessage as aO,
|
|
28475
|
+
AiccClient as aP,
|
|
28476
|
+
decisionRequirements as aQ,
|
|
28477
|
+
validateDecisionRequest as aR,
|
|
28478
|
+
validateDecisionAnswers as aS,
|
|
28479
|
+
KEventReader as aT,
|
|
28480
|
+
KEventClient as aU,
|
|
28481
|
+
appIdFromDid as aV,
|
|
28482
|
+
parseAppId as aW,
|
|
28483
|
+
appDidFromId as aX,
|
|
28484
|
+
createAppInstanceId as aY,
|
|
28485
|
+
parseAppInstanceId as aZ,
|
|
28486
|
+
BNS_EVM_DEFAULT_GAS_LIMIT as a_,
|
|
28458
28487
|
TaskExecutorKind as aa,
|
|
28459
28488
|
TaskPhase as ab,
|
|
28460
28489
|
isTerminalTaskPhase as ac,
|
|
@@ -28482,19 +28511,17 @@ export {
|
|
|
28482
28511
|
WorkflowScheduledTaskMisfirePolicy as ay,
|
|
28483
28512
|
WorkflowScheduledTaskFireStatus as az,
|
|
28484
28513
|
bns_client as b,
|
|
28485
|
-
|
|
28486
|
-
|
|
28487
|
-
|
|
28488
|
-
|
|
28489
|
-
|
|
28490
|
-
|
|
28491
|
-
|
|
28492
|
-
|
|
28493
|
-
|
|
28494
|
-
|
|
28495
|
-
|
|
28496
|
-
walletUserHasSnAccount as bb,
|
|
28497
|
-
BnsTxExecutor as bc,
|
|
28514
|
+
BNS_EVM_DEFAULT_MAX_PRIORITY_FEE_PER_GAS as b0,
|
|
28515
|
+
BNS_MAX_INLINE_DOCUMENT_BYTES as b1,
|
|
28516
|
+
BNS_DNS_TXT_DEFAULT_TTL as b2,
|
|
28517
|
+
BNS_DNS_TXT_DOC_TYPE as b3,
|
|
28518
|
+
BNS_PUBLISH_DOCUMENT_ABI as b4,
|
|
28519
|
+
BnsEvmTxError as b5,
|
|
28520
|
+
BnsEvmTxBuilder as b6,
|
|
28521
|
+
decodeBnsPublishDocumentCalldata as b7,
|
|
28522
|
+
BnsTxExecutorError as b8,
|
|
28523
|
+
walletUserHasSnAccount as b9,
|
|
28524
|
+
BnsTxExecutor as ba,
|
|
28498
28525
|
createSDKModule as c,
|
|
28499
28526
|
BS_SERVICE_TASK_MANAGER as d,
|
|
28500
28527
|
getActiveRuntimeType as e,
|
|
@@ -28520,4 +28547,4 @@ export {
|
|
|
28520
28547
|
WORKFLOW_SCHEDULE_TASK_SCHEMA_ID as y,
|
|
28521
28548
|
WORKFLOW_SEND_MESSAGE_TASK_SCHEMA_ID as z
|
|
28522
28549
|
};
|
|
28523
|
-
//# sourceMappingURL=ndm_proxy-
|
|
28550
|
+
//# sourceMappingURL=ndm_proxy-ebc5a1bf.mjs.map
|