@usabledev/usable-chat 1.236.0 → 1.236.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.
- package/cli.js +435 -417
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -53353,7 +53353,7 @@ var init_model_registry = __esm({
|
|
|
53353
53353
|
var version2;
|
|
53354
53354
|
var init_package = __esm({
|
|
53355
53355
|
"package.json"() {
|
|
53356
|
-
version2 = "1.236.
|
|
53356
|
+
version2 = "1.236.2";
|
|
53357
53357
|
}
|
|
53358
53358
|
});
|
|
53359
53359
|
|
|
@@ -185747,9 +185747,9 @@ var init_model_tiers = __esm({
|
|
|
185747
185747
|
zdr: true
|
|
185748
185748
|
},
|
|
185749
185749
|
{
|
|
185750
|
-
id: "google/gemini-
|
|
185751
|
-
displayName: "Gemini
|
|
185752
|
-
description: "
|
|
185750
|
+
id: "google/gemini-3.8-flash",
|
|
185751
|
+
displayName: "Gemini 3.8 Flash",
|
|
185752
|
+
description: "Fast multilingual responses, 1M context, native multimodal",
|
|
185753
185753
|
provider: "Google",
|
|
185754
185754
|
multiLingual: true,
|
|
185755
185755
|
zdr: true,
|
|
@@ -185763,6 +185763,15 @@ var init_model_tiers = __esm({
|
|
|
185763
185763
|
multiLingual: true,
|
|
185764
185764
|
zdr: true,
|
|
185765
185765
|
effort: "medium"
|
|
185766
|
+
},
|
|
185767
|
+
{
|
|
185768
|
+
id: "google/gemini-4-neon",
|
|
185769
|
+
displayName: "Gemini 4 Neon",
|
|
185770
|
+
description: "Coding and agentic workflows, 1M context, native multimodal",
|
|
185771
|
+
provider: "Google",
|
|
185772
|
+
multiLingual: true,
|
|
185773
|
+
zdr: true,
|
|
185774
|
+
effort: "medium"
|
|
185766
185775
|
}
|
|
185767
185776
|
]
|
|
185768
185777
|
},
|
|
@@ -185877,8 +185886,6 @@ var init_model_tiers = __esm({
|
|
|
185877
185886
|
"openai/gpt-5.6-terra": "medium",
|
|
185878
185887
|
// Left General Purpose when Gemini 3.8 Flash replaced it.
|
|
185879
185888
|
"google/gemini-3.7-flash": "medium",
|
|
185880
|
-
// Left General Purpose when Gemini 4 Neon replaced it.
|
|
185881
|
-
"google/gemini-3.8-flash": "medium",
|
|
185882
185889
|
// Left Heavy Reasoning when GPT-6.1 Sol replaced it.
|
|
185883
185890
|
"openai/gpt-6-sol": "medium"
|
|
185884
185891
|
};
|
|
@@ -187209,7 +187216,7 @@ function mapModeToModel(modeId) {
|
|
|
187209
187216
|
standard: "anthropic/claude-haiku-5.5",
|
|
187210
187217
|
"quick-thinking": "anthropic/claude-haiku-5.5",
|
|
187211
187218
|
"deep-thinking": "anthropic/claude-sonnet-5.5",
|
|
187212
|
-
"multi-lingual": "google/gemini-
|
|
187219
|
+
"multi-lingual": "google/gemini-3.8-flash",
|
|
187213
187220
|
"standard-fallback": "openai/gpt-5-mini"
|
|
187214
187221
|
};
|
|
187215
187222
|
const mapped = modeMap[modeId.toLowerCase()];
|
|
@@ -255166,6 +255173,414 @@ var init_embed_key = __esm({
|
|
|
255166
255173
|
}
|
|
255167
255174
|
});
|
|
255168
255175
|
|
|
255176
|
+
// src/lib/rich-fragment-prompt.ts
|
|
255177
|
+
var RICH_FRAGMENT_RENDERING_PROMPT;
|
|
255178
|
+
var init_rich_fragment_prompt = __esm({
|
|
255179
|
+
"src/lib/rich-fragment-prompt.ts"() {
|
|
255180
|
+
"use strict";
|
|
255181
|
+
RICH_FRAGMENT_RENDERING_PROMPT = `## Fragment Rich Content Rendering
|
|
255182
|
+
|
|
255183
|
+
When creating or updating Usable fragment markdown:
|
|
255184
|
+
- Do NOT write raw inline HTML or SVG directly into markdown. Raw HTML/SVG is blocked by the canvas renderer.
|
|
255185
|
+
- To render SVG, use an explicit fenced block:
|
|
255186
|
+
|
|
255187
|
+
\`\`\`svg render
|
|
255188
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 250">
|
|
255189
|
+
<!-- SVG content -->
|
|
255190
|
+
</svg>
|
|
255191
|
+
\`\`\`
|
|
255192
|
+
|
|
255193
|
+
- To render HTML, use an explicit fenced block:
|
|
255194
|
+
|
|
255195
|
+
\`\`\`html render
|
|
255196
|
+
<div>HTML content</div>
|
|
255197
|
+
\`\`\`
|
|
255198
|
+
|
|
255199
|
+
- Plain \`svg\`, \`html\`, or other code fences stay code blocks. Only \`svg render\` and \`html render\` are rendered in the canvas sandbox.
|
|
255200
|
+
- Images in fragments should use \`usable://files/<full-file-id>\` for attached files or \`https://\` for external images. Other image URL schemes are blocked.
|
|
255201
|
+
- Chat file ids are not Usable file ids, and Chat's \`https://usable.dev/files/<id>\` image links only work inside the chat: never put either into fragment content.`;
|
|
255202
|
+
}
|
|
255203
|
+
});
|
|
255204
|
+
|
|
255205
|
+
// src/core/types/system-prompt-source.ts
|
|
255206
|
+
function getPromptUnavailableBehavior(source) {
|
|
255207
|
+
return source?.type === "fragment" ? source.unavailableBehavior ?? "error" : "fallback";
|
|
255208
|
+
}
|
|
255209
|
+
var systemPromptSourceSchema;
|
|
255210
|
+
var init_system_prompt_source = __esm({
|
|
255211
|
+
"src/core/types/system-prompt-source.ts"() {
|
|
255212
|
+
"use strict";
|
|
255213
|
+
init_zod();
|
|
255214
|
+
systemPromptSourceSchema = external_exports.discriminatedUnion("type", [
|
|
255215
|
+
external_exports.object({
|
|
255216
|
+
type: external_exports.literal("inline")
|
|
255217
|
+
}),
|
|
255218
|
+
external_exports.object({
|
|
255219
|
+
type: external_exports.literal("fragment"),
|
|
255220
|
+
fragmentId: external_exports.string().uuid(),
|
|
255221
|
+
workspaceId: external_exports.string().uuid().optional(),
|
|
255222
|
+
unavailableBehavior: external_exports.enum(["error", "fallback"]).optional()
|
|
255223
|
+
})
|
|
255224
|
+
]);
|
|
255225
|
+
}
|
|
255226
|
+
});
|
|
255227
|
+
|
|
255228
|
+
// src/core/types/custom-expert.ts
|
|
255229
|
+
var custom_expert_exports = {};
|
|
255230
|
+
__export2(custom_expert_exports, {
|
|
255231
|
+
BUILT_IN_TOOLS: () => BUILT_IN_TOOLS,
|
|
255232
|
+
FEATURE_GATED_TOOLS: () => FEATURE_GATED_TOOLS,
|
|
255233
|
+
MAX_PARENT_TOOLS: () => MAX_PARENT_TOOLS,
|
|
255234
|
+
convertCustomExpertToSubAgent: () => convertCustomExpertToSubAgent,
|
|
255235
|
+
createCustomExpertSchema: () => createCustomExpertSchema,
|
|
255236
|
+
expertConfigSchema: () => expertConfigSchema,
|
|
255237
|
+
expertRoutingSchema: () => expertRoutingSchema,
|
|
255238
|
+
getAvailableToolsForExpert: () => getAvailableToolsForExpert,
|
|
255239
|
+
getParentToolName: () => getParentToolName,
|
|
255240
|
+
isParentToolComplete: () => isParentToolComplete,
|
|
255241
|
+
mergeParentToolSchemas: () => mergeParentToolSchemas,
|
|
255242
|
+
normalizeParentToolConfig: () => normalizeParentToolConfig,
|
|
255243
|
+
parentToolDefinitionSchema: () => parentToolDefinitionSchema,
|
|
255244
|
+
parentToolFullDefinitionSchema: () => parentToolFullDefinitionSchema,
|
|
255245
|
+
parentToolNameSchema: () => parentToolNameSchema,
|
|
255246
|
+
parentToolSchemaSchema: () => parentToolSchemaSchema,
|
|
255247
|
+
updateCustomExpertSchema: () => updateCustomExpertSchema
|
|
255248
|
+
});
|
|
255249
|
+
function convertCustomExpertToSubAgent(expert, options2 = {}) {
|
|
255250
|
+
const { enabledFeatures = {} } = options2;
|
|
255251
|
+
const filteredTools = filterToolsByFeatures(expert.enabledTools, enabledFeatures);
|
|
255252
|
+
const ui2 = buildUIMetadata(expert);
|
|
255253
|
+
const canHandle = buildCanHandleFunction(expert.routing, expert.excludeKeywords);
|
|
255254
|
+
const parentToolConfigs = expert.parentTools;
|
|
255255
|
+
const normalizedParentTools = parentToolConfigs?.map(normalizeParentToolConfig);
|
|
255256
|
+
return {
|
|
255257
|
+
id: expert.id,
|
|
255258
|
+
displayName: expert.name,
|
|
255259
|
+
description: expert.description,
|
|
255260
|
+
systemPrompt: withRichFragmentRenderingPrompt(expert.systemPrompt),
|
|
255261
|
+
tools: filteredTools,
|
|
255262
|
+
ui: ui2,
|
|
255263
|
+
modelPreference: expert.modelPreference,
|
|
255264
|
+
directModelId: expert.directModelId,
|
|
255265
|
+
temperature: expert.temperature,
|
|
255266
|
+
maxTokens: expert.maxTokens,
|
|
255267
|
+
priority: expert.priority,
|
|
255268
|
+
maxTurns: expert.maxTurns,
|
|
255269
|
+
canHandle,
|
|
255270
|
+
// Include normalized parent tools if defined
|
|
255271
|
+
parentTools: normalizedParentTools
|
|
255272
|
+
};
|
|
255273
|
+
}
|
|
255274
|
+
function withRichFragmentRenderingPrompt(systemPrompt) {
|
|
255275
|
+
if (systemPrompt.includes("## Fragment Rich Content Rendering")) {
|
|
255276
|
+
return systemPrompt;
|
|
255277
|
+
}
|
|
255278
|
+
return `${systemPrompt.trim()}
|
|
255279
|
+
|
|
255280
|
+
${RICH_FRAGMENT_RENDERING_PROMPT}`;
|
|
255281
|
+
}
|
|
255282
|
+
function filterToolsByFeatures(requestedTools, enabledFeatures = {}) {
|
|
255283
|
+
const availableTools = new Set(BUILT_IN_TOOLS);
|
|
255284
|
+
if (enabledFeatures.webSearch) {
|
|
255285
|
+
FEATURE_GATED_TOOLS.webSearch.forEach((tool2) => availableTools.add(tool2));
|
|
255286
|
+
}
|
|
255287
|
+
if (enabledFeatures.imageGeneration) {
|
|
255288
|
+
FEATURE_GATED_TOOLS.imageGeneration.forEach((tool2) => availableTools.add(tool2));
|
|
255289
|
+
}
|
|
255290
|
+
if (enabledFeatures.documentation) {
|
|
255291
|
+
FEATURE_GATED_TOOLS.documentation.forEach((tool2) => availableTools.add(tool2));
|
|
255292
|
+
}
|
|
255293
|
+
if (enabledFeatures.codeExecution) {
|
|
255294
|
+
for (const tool2 of ["execute_code", "clone_repo", "file_to_sandbox"]) availableTools.add(tool2);
|
|
255295
|
+
}
|
|
255296
|
+
return requestedTools.filter((tool2) => availableTools.has(tool2));
|
|
255297
|
+
}
|
|
255298
|
+
function buildUIMetadata(expert) {
|
|
255299
|
+
const color = expert.uiColor || "purple-500";
|
|
255300
|
+
return {
|
|
255301
|
+
color,
|
|
255302
|
+
bgColor: `bg-${color}/10`,
|
|
255303
|
+
textColor: `text-${color}`,
|
|
255304
|
+
borderColor: `border-${color}`,
|
|
255305
|
+
avatar: expert.avatarUrl || "/experts/custom-expert-placeholder.svg",
|
|
255306
|
+
emoji: expert.uiEmoji || "\u{1F916}",
|
|
255307
|
+
shortName: expert.uiShortName || expert.name.slice(0, 10)
|
|
255308
|
+
};
|
|
255309
|
+
}
|
|
255310
|
+
function buildCanHandleFunction(routing, excludeKeywords) {
|
|
255311
|
+
return (query) => {
|
|
255312
|
+
const lowerQuery = query.toLowerCase();
|
|
255313
|
+
if (excludeKeywords && excludeKeywords.length > 0) {
|
|
255314
|
+
for (const excluded of excludeKeywords) {
|
|
255315
|
+
if (lowerQuery.includes(excluded.toLowerCase())) {
|
|
255316
|
+
return false;
|
|
255317
|
+
}
|
|
255318
|
+
}
|
|
255319
|
+
}
|
|
255320
|
+
for (const keyword of routing.keywords) {
|
|
255321
|
+
if (lowerQuery.includes(keyword.toLowerCase())) {
|
|
255322
|
+
return true;
|
|
255323
|
+
}
|
|
255324
|
+
}
|
|
255325
|
+
if (routing.patterns && routing.patterns.length > 0) {
|
|
255326
|
+
for (const pattern of routing.patterns) {
|
|
255327
|
+
try {
|
|
255328
|
+
if (new RegExp(pattern, "i").test(query)) {
|
|
255329
|
+
return true;
|
|
255330
|
+
}
|
|
255331
|
+
} catch {
|
|
255332
|
+
console.warn(`Invalid regex pattern in expert routing: ${pattern}`);
|
|
255333
|
+
}
|
|
255334
|
+
}
|
|
255335
|
+
}
|
|
255336
|
+
return false;
|
|
255337
|
+
};
|
|
255338
|
+
}
|
|
255339
|
+
function getAvailableToolsForExpert(enabledFeatures) {
|
|
255340
|
+
return [
|
|
255341
|
+
{
|
|
255342
|
+
category: "Usable (Built-in)",
|
|
255343
|
+
tools: [...BUILT_IN_TOOLS],
|
|
255344
|
+
available: true
|
|
255345
|
+
},
|
|
255346
|
+
{
|
|
255347
|
+
category: "Web Search",
|
|
255348
|
+
tools: [...FEATURE_GATED_TOOLS.webSearch],
|
|
255349
|
+
available: enabledFeatures.webSearch ?? false
|
|
255350
|
+
},
|
|
255351
|
+
{
|
|
255352
|
+
category: "Image Generation",
|
|
255353
|
+
tools: [...FEATURE_GATED_TOOLS.imageGeneration],
|
|
255354
|
+
available: enabledFeatures.imageGeneration ?? false
|
|
255355
|
+
},
|
|
255356
|
+
{
|
|
255357
|
+
category: "Documentation",
|
|
255358
|
+
tools: [...FEATURE_GATED_TOOLS.documentation],
|
|
255359
|
+
available: enabledFeatures.documentation ?? false
|
|
255360
|
+
}
|
|
255361
|
+
];
|
|
255362
|
+
}
|
|
255363
|
+
function normalizeParentToolConfig(config3) {
|
|
255364
|
+
if (typeof config3 === "string") {
|
|
255365
|
+
return { name: config3 };
|
|
255366
|
+
}
|
|
255367
|
+
return config3;
|
|
255368
|
+
}
|
|
255369
|
+
function getParentToolName(config3) {
|
|
255370
|
+
if (typeof config3 === "string") {
|
|
255371
|
+
return config3;
|
|
255372
|
+
}
|
|
255373
|
+
return config3.name;
|
|
255374
|
+
}
|
|
255375
|
+
function mergeParentToolSchemas(parentTools, registeredSchemas) {
|
|
255376
|
+
return parentTools.map((config3) => {
|
|
255377
|
+
const normalized = normalizeParentToolConfig(config3);
|
|
255378
|
+
const toolName = normalized.name;
|
|
255379
|
+
if (normalized.description) {
|
|
255380
|
+
return normalized;
|
|
255381
|
+
}
|
|
255382
|
+
const schema = registeredSchemas?.get(toolName);
|
|
255383
|
+
if (schema) {
|
|
255384
|
+
return {
|
|
255385
|
+
name: toolName,
|
|
255386
|
+
description: schema.description,
|
|
255387
|
+
parameters: schema.parameters || normalized.parameters
|
|
255388
|
+
};
|
|
255389
|
+
}
|
|
255390
|
+
return normalized;
|
|
255391
|
+
});
|
|
255392
|
+
}
|
|
255393
|
+
function isParentToolComplete(tool2) {
|
|
255394
|
+
return !!(tool2.name && tool2.description);
|
|
255395
|
+
}
|
|
255396
|
+
var BUILT_IN_TOOLS, FEATURE_GATED_TOOLS, expertRoutingSchema, parentToolNameSchema, parentToolFullDefinitionSchema, parentToolDefinitionSchema, parentToolSchemaSchema, MAX_PARENT_TOOLS, expertConfigSchema, createCustomExpertSchema, updateCustomExpertSchema;
|
|
255397
|
+
var init_custom_expert = __esm({
|
|
255398
|
+
"src/core/types/custom-expert.ts"() {
|
|
255399
|
+
"use strict";
|
|
255400
|
+
init_zod();
|
|
255401
|
+
init_rich_fragment_prompt();
|
|
255402
|
+
init_system_prompt_source();
|
|
255403
|
+
BUILT_IN_TOOLS = [
|
|
255404
|
+
"agentic-search-fragments",
|
|
255405
|
+
"search-memory-fragments",
|
|
255406
|
+
"list-memory-fragments",
|
|
255407
|
+
"get-memory-fragment-content",
|
|
255408
|
+
"create-memory-fragment",
|
|
255409
|
+
"update-memory-fragment",
|
|
255410
|
+
"list-workspaces",
|
|
255411
|
+
"get-fragment-types"
|
|
255412
|
+
];
|
|
255413
|
+
FEATURE_GATED_TOOLS = {
|
|
255414
|
+
webSearch: [
|
|
255415
|
+
"exa-search",
|
|
255416
|
+
"exa-find-similar",
|
|
255417
|
+
"exa-get-contents",
|
|
255418
|
+
"WebFetch",
|
|
255419
|
+
"WebSearch"
|
|
255420
|
+
],
|
|
255421
|
+
imageGeneration: ["generate-image", "view-image"],
|
|
255422
|
+
documentation: ["resolve-library-id", "query-docs"]
|
|
255423
|
+
};
|
|
255424
|
+
expertRoutingSchema = external_exports.object({
|
|
255425
|
+
keywords: external_exports.array(external_exports.string().min(1).max(100)).min(1, "At least one keyword is required for routing"),
|
|
255426
|
+
patterns: external_exports.array(external_exports.string().max(500)).optional()
|
|
255427
|
+
});
|
|
255428
|
+
parentToolNameSchema = external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens");
|
|
255429
|
+
parentToolFullDefinitionSchema = external_exports.object({
|
|
255430
|
+
name: external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens"),
|
|
255431
|
+
description: external_exports.string().min(1).max(1e3).optional(),
|
|
255432
|
+
parameters: external_exports.record(external_exports.unknown()).optional()
|
|
255433
|
+
});
|
|
255434
|
+
parentToolDefinitionSchema = external_exports.union([
|
|
255435
|
+
parentToolNameSchema,
|
|
255436
|
+
parentToolFullDefinitionSchema
|
|
255437
|
+
]);
|
|
255438
|
+
parentToolSchemaSchema = external_exports.object({
|
|
255439
|
+
name: external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens"),
|
|
255440
|
+
description: external_exports.string().min(1).max(1e3),
|
|
255441
|
+
parameters: external_exports.object({
|
|
255442
|
+
type: external_exports.literal("object"),
|
|
255443
|
+
properties: external_exports.record(external_exports.unknown()),
|
|
255444
|
+
required: external_exports.array(external_exports.string()).optional()
|
|
255445
|
+
}).optional(),
|
|
255446
|
+
skill: external_exports.object({
|
|
255447
|
+
id: external_exports.string().min(1).max(100).optional(),
|
|
255448
|
+
title: external_exports.string().min(1).max(200).optional(),
|
|
255449
|
+
summary: external_exports.string().max(1e3).optional(),
|
|
255450
|
+
tags: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
255451
|
+
scope: external_exports.enum(["global", "page"]).optional()
|
|
255452
|
+
}).optional()
|
|
255453
|
+
});
|
|
255454
|
+
MAX_PARENT_TOOLS = 32;
|
|
255455
|
+
expertConfigSchema = external_exports.object({
|
|
255456
|
+
systemPrompt: external_exports.string().min(1).max(5e4),
|
|
255457
|
+
systemPromptSource: systemPromptSourceSchema.nullable().optional(),
|
|
255458
|
+
enabledTools: external_exports.array(external_exports.string()),
|
|
255459
|
+
routing: expertRoutingSchema,
|
|
255460
|
+
modelPreference: external_exports.enum(["inherit", "quick-thinking", "deep-thinking", "multi-lingual"]),
|
|
255461
|
+
directModelId: external_exports.string().regex(
|
|
255462
|
+
/^[a-z0-9-]+\/[a-z0-9.-]+$/,
|
|
255463
|
+
"Must be a valid model ID (e.g., anthropic/claude-sonnet-4.5)"
|
|
255464
|
+
).optional().nullable(),
|
|
255465
|
+
temperature: external_exports.number().min(0).max(1).optional(),
|
|
255466
|
+
maxTokens: external_exports.number().min(100).max(32e3).optional(),
|
|
255467
|
+
uiColor: external_exports.string().max(50).optional(),
|
|
255468
|
+
uiEmoji: external_exports.string().max(10).optional(),
|
|
255469
|
+
avatarUrl: external_exports.string().refine(
|
|
255470
|
+
(val) => val.startsWith("data:") || val.startsWith("http://") || val.startsWith("https://") || val.startsWith("/"),
|
|
255471
|
+
"Must be a valid URL, data URL, or path"
|
|
255472
|
+
).optional(),
|
|
255473
|
+
parentTools: external_exports.array(parentToolDefinitionSchema).max(MAX_PARENT_TOOLS).optional(),
|
|
255474
|
+
excludeKeywords: external_exports.array(external_exports.string().min(1).max(50)).max(20).optional(),
|
|
255475
|
+
priority: external_exports.number().int().min(0).max(100).optional(),
|
|
255476
|
+
maxTurns: external_exports.number().int().min(1).max(50).optional(),
|
|
255477
|
+
uiShortName: external_exports.string().max(30).optional()
|
|
255478
|
+
});
|
|
255479
|
+
createCustomExpertSchema = external_exports.object({
|
|
255480
|
+
key: external_exports.string().min(1).max(100).regex(/^[a-z0-9-]+$/, "Key must be lowercase alphanumeric with hyphens").optional(),
|
|
255481
|
+
workspaceId: external_exports.string().uuid().optional(),
|
|
255482
|
+
name: external_exports.string().min(1).max(255),
|
|
255483
|
+
description: external_exports.string().min(1).max(1e3),
|
|
255484
|
+
expertConfig: expertConfigSchema
|
|
255485
|
+
});
|
|
255486
|
+
updateCustomExpertSchema = external_exports.object({
|
|
255487
|
+
name: external_exports.string().min(1).max(255).optional(),
|
|
255488
|
+
description: external_exports.string().min(1).max(1e3).optional(),
|
|
255489
|
+
expertConfig: expertConfigSchema.partial().optional(),
|
|
255490
|
+
status: external_exports.enum(["active", "archived", "draft"]).optional()
|
|
255491
|
+
});
|
|
255492
|
+
}
|
|
255493
|
+
});
|
|
255494
|
+
|
|
255495
|
+
// src/lib/services/expert-permission.service.ts
|
|
255496
|
+
async function checkExpertPermission(expertId, userId) {
|
|
255497
|
+
const [collaborator] = await db.select({ role: expertCollaborators.role }).from(expertCollaborators).where(
|
|
255498
|
+
and(
|
|
255499
|
+
eq(expertCollaborators.expertId, expertId),
|
|
255500
|
+
eq(expertCollaborators.userId, userId),
|
|
255501
|
+
isNull(expertCollaborators.deletedAt)
|
|
255502
|
+
)
|
|
255503
|
+
).limit(1);
|
|
255504
|
+
if (collaborator) {
|
|
255505
|
+
const role = collaborator.role;
|
|
255506
|
+
return {
|
|
255507
|
+
hasAccess: true,
|
|
255508
|
+
role,
|
|
255509
|
+
isOwner: role === "owner",
|
|
255510
|
+
isViewer: role === "viewer" || role === "subscriber"
|
|
255511
|
+
};
|
|
255512
|
+
}
|
|
255513
|
+
const [expert] = await db.select({ createdBy: customExperts.createdBy }).from(customExperts).where(eq(customExperts.id, expertId)).limit(1);
|
|
255514
|
+
if (expert && expert.createdBy === userId) {
|
|
255515
|
+
return {
|
|
255516
|
+
hasAccess: true,
|
|
255517
|
+
role: "owner",
|
|
255518
|
+
isOwner: true,
|
|
255519
|
+
isViewer: false
|
|
255520
|
+
};
|
|
255521
|
+
}
|
|
255522
|
+
return {
|
|
255523
|
+
hasAccess: false,
|
|
255524
|
+
role: "none",
|
|
255525
|
+
isOwner: false,
|
|
255526
|
+
isViewer: false
|
|
255527
|
+
};
|
|
255528
|
+
}
|
|
255529
|
+
async function canViewExpert(expertId, userId) {
|
|
255530
|
+
const permission = await checkExpertPermission(expertId, userId);
|
|
255531
|
+
return permission.hasAccess;
|
|
255532
|
+
}
|
|
255533
|
+
async function checkConfigPermission(configId, userId) {
|
|
255534
|
+
const [collaborator] = await db.select({ role: configCollaborators.role }).from(configCollaborators).where(
|
|
255535
|
+
and(
|
|
255536
|
+
eq(configCollaborators.configId, configId),
|
|
255537
|
+
eq(configCollaborators.userId, userId),
|
|
255538
|
+
isNull(configCollaborators.deletedAt)
|
|
255539
|
+
)
|
|
255540
|
+
).limit(1);
|
|
255541
|
+
if (collaborator) {
|
|
255542
|
+
const role = collaborator.role;
|
|
255543
|
+
return {
|
|
255544
|
+
hasAccess: true,
|
|
255545
|
+
role,
|
|
255546
|
+
isOwner: role === "owner",
|
|
255547
|
+
isViewer: role === "viewer"
|
|
255548
|
+
};
|
|
255549
|
+
}
|
|
255550
|
+
const [config3] = await db.select({ createdBy: chatConfigs.createdBy }).from(chatConfigs).where(eq(chatConfigs.id, configId)).limit(1);
|
|
255551
|
+
if (config3 && config3.createdBy === userId) {
|
|
255552
|
+
return {
|
|
255553
|
+
hasAccess: true,
|
|
255554
|
+
role: "owner",
|
|
255555
|
+
isOwner: true,
|
|
255556
|
+
isViewer: false
|
|
255557
|
+
};
|
|
255558
|
+
}
|
|
255559
|
+
return {
|
|
255560
|
+
hasAccess: false,
|
|
255561
|
+
role: "none",
|
|
255562
|
+
isOwner: false,
|
|
255563
|
+
isViewer: false
|
|
255564
|
+
};
|
|
255565
|
+
}
|
|
255566
|
+
async function canEditConfig(configId, userId) {
|
|
255567
|
+
const permission = await checkConfigPermission(configId, userId);
|
|
255568
|
+
return permission.isOwner;
|
|
255569
|
+
}
|
|
255570
|
+
async function canManageConfigCollaborators(configId, userId) {
|
|
255571
|
+
const permission = await checkConfigPermission(configId, userId);
|
|
255572
|
+
return permission.isOwner;
|
|
255573
|
+
}
|
|
255574
|
+
var init_expert_permission_service = __esm({
|
|
255575
|
+
"src/lib/services/expert-permission.service.ts"() {
|
|
255576
|
+
"use strict";
|
|
255577
|
+
init_client7();
|
|
255578
|
+
init_schema4();
|
|
255579
|
+
init_drizzle_orm();
|
|
255580
|
+
init_custom_expert();
|
|
255581
|
+
}
|
|
255582
|
+
});
|
|
255583
|
+
|
|
255169
255584
|
// src/lib/services/embed-key.service.ts
|
|
255170
255585
|
var embed_key_service_exports = {};
|
|
255171
255586
|
__export2(embed_key_service_exports, {
|
|
@@ -255280,6 +255695,9 @@ async function createEmbedKey(sessionPathway, input, userId, options2) {
|
|
|
255280
255695
|
if (options2?.serviceAccount && options2.usablePatEncrypted !== void 0) {
|
|
255281
255696
|
throw new Error("An embed key holds either an API key or a service account, not both");
|
|
255282
255697
|
}
|
|
255698
|
+
if (options2?.serviceAccount && !await canManageConfigCollaborators(input.configId, userId)) {
|
|
255699
|
+
throw new Error("Only embed owners can change service account credentials");
|
|
255700
|
+
}
|
|
255283
255701
|
const keyId = randomUUID7();
|
|
255284
255702
|
const token = generateEmbedToken();
|
|
255285
255703
|
const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -255454,10 +255872,9 @@ function nextEmbedKeyMutationTimestamp(observedUpdatedAt) {
|
|
|
255454
255872
|
async function updateEmbedKey(sessionPathway, keyId, configId, input, userId) {
|
|
255455
255873
|
const [key3] = await db.select().from(embedKeys).where(and(eq(embedKeys.id, keyId), eq(embedKeys.configId, configId))).limit(1);
|
|
255456
255874
|
if (!key3) return false;
|
|
255457
|
-
if ((key3.serviceAccountSecretEncrypted || key3.serviceAccountBinding) && ("usablePatEncrypted" in input || "usablePatMetadata" in input
|
|
255458
|
-
|
|
255459
|
-
|
|
255460
|
-
throw new Error("Only the config creator can bind or disconnect a service account");
|
|
255875
|
+
if (input.serviceAccount !== void 0 || (key3.serviceAccountSecretEncrypted || key3.serviceAccountBinding) && ("usablePatEncrypted" in input || "usablePatMetadata" in input)) {
|
|
255876
|
+
if (!await canManageConfigCollaborators(configId, userId)) {
|
|
255877
|
+
throw new Error("Only embed owners can change service account credentials");
|
|
255461
255878
|
}
|
|
255462
255879
|
}
|
|
255463
255880
|
const accessPolicy = embedKeyAccessPolicySchema.parse({
|
|
@@ -255517,6 +255934,7 @@ var init_embed_key_service = __esm({
|
|
|
255517
255934
|
init_drizzle_orm();
|
|
255518
255935
|
init_origin_matcher();
|
|
255519
255936
|
init_redis();
|
|
255937
|
+
init_expert_permission_service();
|
|
255520
255938
|
init_logger3();
|
|
255521
255939
|
EMBED_KEY_CACHE_TTL_MS = 6e4;
|
|
255522
255940
|
EMBED_KEY_CACHE_MAX_ENTRIES = 1e3;
|
|
@@ -255742,7 +256160,7 @@ var init_embed_service_account = __esm({
|
|
|
255742
256160
|
* before it are refused, so a rebind never continues another account's runs.
|
|
255743
256161
|
*/
|
|
255744
256162
|
accountBoundAt: external_exports.string().datetime().optional(),
|
|
255745
|
-
/** Authenticated
|
|
256163
|
+
/** Authenticated embed owner who authorized this binding, set only by the server. */
|
|
255746
256164
|
boundByUserId: external_exports.string().min(1).max(255).optional(),
|
|
255747
256165
|
/** Display-only snapshot at verifiedAt. Runtime never authorizes from it. */
|
|
255748
256166
|
grantsSnapshot: external_exports.array(serviceAccountGrantSnapshotSchema).max(500)
|
|
@@ -256337,7 +256755,10 @@ async function resolveEmbedAuth(request, options2 = {}) {
|
|
|
256337
256755
|
}
|
|
256338
256756
|
const { key: key3, config: config3 } = result.data;
|
|
256339
256757
|
if (key3.serviceAccountSecretEncrypted) {
|
|
256340
|
-
if (!
|
|
256758
|
+
if (!await canManageConfigCollaborators(
|
|
256759
|
+
config3.id,
|
|
256760
|
+
key3.serviceAccountBinding?.boundByUserId ?? key3.createdBy
|
|
256761
|
+
)) return null;
|
|
256341
256762
|
return resolveServiceAccountEmbedAuth(request, key3, config3.id, config3.configData);
|
|
256342
256763
|
}
|
|
256343
256764
|
if (!key3.usablePatEncrypted) {
|
|
@@ -256503,6 +256924,7 @@ var init_embed_auth = __esm({
|
|
|
256503
256924
|
init_config();
|
|
256504
256925
|
init_logger();
|
|
256505
256926
|
init_env2();
|
|
256927
|
+
init_expert_permission_service();
|
|
256506
256928
|
init_visitor_proof();
|
|
256507
256929
|
init_embed_service_account_service();
|
|
256508
256930
|
}
|
|
@@ -256872,410 +257294,6 @@ var init_config_error = __esm({
|
|
|
256872
257294
|
}
|
|
256873
257295
|
});
|
|
256874
257296
|
|
|
256875
|
-
// src/lib/rich-fragment-prompt.ts
|
|
256876
|
-
var RICH_FRAGMENT_RENDERING_PROMPT;
|
|
256877
|
-
var init_rich_fragment_prompt = __esm({
|
|
256878
|
-
"src/lib/rich-fragment-prompt.ts"() {
|
|
256879
|
-
"use strict";
|
|
256880
|
-
RICH_FRAGMENT_RENDERING_PROMPT = `## Fragment Rich Content Rendering
|
|
256881
|
-
|
|
256882
|
-
When creating or updating Usable fragment markdown:
|
|
256883
|
-
- Do NOT write raw inline HTML or SVG directly into markdown. Raw HTML/SVG is blocked by the canvas renderer.
|
|
256884
|
-
- To render SVG, use an explicit fenced block:
|
|
256885
|
-
|
|
256886
|
-
\`\`\`svg render
|
|
256887
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 250">
|
|
256888
|
-
<!-- SVG content -->
|
|
256889
|
-
</svg>
|
|
256890
|
-
\`\`\`
|
|
256891
|
-
|
|
256892
|
-
- To render HTML, use an explicit fenced block:
|
|
256893
|
-
|
|
256894
|
-
\`\`\`html render
|
|
256895
|
-
<div>HTML content</div>
|
|
256896
|
-
\`\`\`
|
|
256897
|
-
|
|
256898
|
-
- Plain \`svg\`, \`html\`, or other code fences stay code blocks. Only \`svg render\` and \`html render\` are rendered in the canvas sandbox.
|
|
256899
|
-
- Images in fragments should use \`usable://files/<full-file-id>\` for attached files or \`https://\` for external images. Other image URL schemes are blocked.
|
|
256900
|
-
- Chat file ids are not Usable file ids, and Chat's \`https://usable.dev/files/<id>\` image links only work inside the chat: never put either into fragment content.`;
|
|
256901
|
-
}
|
|
256902
|
-
});
|
|
256903
|
-
|
|
256904
|
-
// src/core/types/system-prompt-source.ts
|
|
256905
|
-
function getPromptUnavailableBehavior(source) {
|
|
256906
|
-
return source?.type === "fragment" ? source.unavailableBehavior ?? "error" : "fallback";
|
|
256907
|
-
}
|
|
256908
|
-
var systemPromptSourceSchema;
|
|
256909
|
-
var init_system_prompt_source = __esm({
|
|
256910
|
-
"src/core/types/system-prompt-source.ts"() {
|
|
256911
|
-
"use strict";
|
|
256912
|
-
init_zod();
|
|
256913
|
-
systemPromptSourceSchema = external_exports.discriminatedUnion("type", [
|
|
256914
|
-
external_exports.object({
|
|
256915
|
-
type: external_exports.literal("inline")
|
|
256916
|
-
}),
|
|
256917
|
-
external_exports.object({
|
|
256918
|
-
type: external_exports.literal("fragment"),
|
|
256919
|
-
fragmentId: external_exports.string().uuid(),
|
|
256920
|
-
workspaceId: external_exports.string().uuid().optional(),
|
|
256921
|
-
unavailableBehavior: external_exports.enum(["error", "fallback"]).optional()
|
|
256922
|
-
})
|
|
256923
|
-
]);
|
|
256924
|
-
}
|
|
256925
|
-
});
|
|
256926
|
-
|
|
256927
|
-
// src/core/types/custom-expert.ts
|
|
256928
|
-
var custom_expert_exports = {};
|
|
256929
|
-
__export2(custom_expert_exports, {
|
|
256930
|
-
BUILT_IN_TOOLS: () => BUILT_IN_TOOLS,
|
|
256931
|
-
FEATURE_GATED_TOOLS: () => FEATURE_GATED_TOOLS,
|
|
256932
|
-
MAX_PARENT_TOOLS: () => MAX_PARENT_TOOLS,
|
|
256933
|
-
convertCustomExpertToSubAgent: () => convertCustomExpertToSubAgent,
|
|
256934
|
-
createCustomExpertSchema: () => createCustomExpertSchema,
|
|
256935
|
-
expertConfigSchema: () => expertConfigSchema,
|
|
256936
|
-
expertRoutingSchema: () => expertRoutingSchema,
|
|
256937
|
-
getAvailableToolsForExpert: () => getAvailableToolsForExpert,
|
|
256938
|
-
getParentToolName: () => getParentToolName,
|
|
256939
|
-
isParentToolComplete: () => isParentToolComplete,
|
|
256940
|
-
mergeParentToolSchemas: () => mergeParentToolSchemas,
|
|
256941
|
-
normalizeParentToolConfig: () => normalizeParentToolConfig,
|
|
256942
|
-
parentToolDefinitionSchema: () => parentToolDefinitionSchema,
|
|
256943
|
-
parentToolFullDefinitionSchema: () => parentToolFullDefinitionSchema,
|
|
256944
|
-
parentToolNameSchema: () => parentToolNameSchema,
|
|
256945
|
-
parentToolSchemaSchema: () => parentToolSchemaSchema,
|
|
256946
|
-
updateCustomExpertSchema: () => updateCustomExpertSchema
|
|
256947
|
-
});
|
|
256948
|
-
function convertCustomExpertToSubAgent(expert, options2 = {}) {
|
|
256949
|
-
const { enabledFeatures = {} } = options2;
|
|
256950
|
-
const filteredTools = filterToolsByFeatures(expert.enabledTools, enabledFeatures);
|
|
256951
|
-
const ui2 = buildUIMetadata(expert);
|
|
256952
|
-
const canHandle = buildCanHandleFunction(expert.routing, expert.excludeKeywords);
|
|
256953
|
-
const parentToolConfigs = expert.parentTools;
|
|
256954
|
-
const normalizedParentTools = parentToolConfigs?.map(normalizeParentToolConfig);
|
|
256955
|
-
return {
|
|
256956
|
-
id: expert.id,
|
|
256957
|
-
displayName: expert.name,
|
|
256958
|
-
description: expert.description,
|
|
256959
|
-
systemPrompt: withRichFragmentRenderingPrompt(expert.systemPrompt),
|
|
256960
|
-
tools: filteredTools,
|
|
256961
|
-
ui: ui2,
|
|
256962
|
-
modelPreference: expert.modelPreference,
|
|
256963
|
-
directModelId: expert.directModelId,
|
|
256964
|
-
temperature: expert.temperature,
|
|
256965
|
-
maxTokens: expert.maxTokens,
|
|
256966
|
-
priority: expert.priority,
|
|
256967
|
-
maxTurns: expert.maxTurns,
|
|
256968
|
-
canHandle,
|
|
256969
|
-
// Include normalized parent tools if defined
|
|
256970
|
-
parentTools: normalizedParentTools
|
|
256971
|
-
};
|
|
256972
|
-
}
|
|
256973
|
-
function withRichFragmentRenderingPrompt(systemPrompt) {
|
|
256974
|
-
if (systemPrompt.includes("## Fragment Rich Content Rendering")) {
|
|
256975
|
-
return systemPrompt;
|
|
256976
|
-
}
|
|
256977
|
-
return `${systemPrompt.trim()}
|
|
256978
|
-
|
|
256979
|
-
${RICH_FRAGMENT_RENDERING_PROMPT}`;
|
|
256980
|
-
}
|
|
256981
|
-
function filterToolsByFeatures(requestedTools, enabledFeatures = {}) {
|
|
256982
|
-
const availableTools = new Set(BUILT_IN_TOOLS);
|
|
256983
|
-
if (enabledFeatures.webSearch) {
|
|
256984
|
-
FEATURE_GATED_TOOLS.webSearch.forEach((tool2) => availableTools.add(tool2));
|
|
256985
|
-
}
|
|
256986
|
-
if (enabledFeatures.imageGeneration) {
|
|
256987
|
-
FEATURE_GATED_TOOLS.imageGeneration.forEach((tool2) => availableTools.add(tool2));
|
|
256988
|
-
}
|
|
256989
|
-
if (enabledFeatures.documentation) {
|
|
256990
|
-
FEATURE_GATED_TOOLS.documentation.forEach((tool2) => availableTools.add(tool2));
|
|
256991
|
-
}
|
|
256992
|
-
if (enabledFeatures.codeExecution) {
|
|
256993
|
-
for (const tool2 of ["execute_code", "clone_repo", "file_to_sandbox"]) availableTools.add(tool2);
|
|
256994
|
-
}
|
|
256995
|
-
return requestedTools.filter((tool2) => availableTools.has(tool2));
|
|
256996
|
-
}
|
|
256997
|
-
function buildUIMetadata(expert) {
|
|
256998
|
-
const color = expert.uiColor || "purple-500";
|
|
256999
|
-
return {
|
|
257000
|
-
color,
|
|
257001
|
-
bgColor: `bg-${color}/10`,
|
|
257002
|
-
textColor: `text-${color}`,
|
|
257003
|
-
borderColor: `border-${color}`,
|
|
257004
|
-
avatar: expert.avatarUrl || "/experts/custom-expert-placeholder.svg",
|
|
257005
|
-
emoji: expert.uiEmoji || "\u{1F916}",
|
|
257006
|
-
shortName: expert.uiShortName || expert.name.slice(0, 10)
|
|
257007
|
-
};
|
|
257008
|
-
}
|
|
257009
|
-
function buildCanHandleFunction(routing, excludeKeywords) {
|
|
257010
|
-
return (query) => {
|
|
257011
|
-
const lowerQuery = query.toLowerCase();
|
|
257012
|
-
if (excludeKeywords && excludeKeywords.length > 0) {
|
|
257013
|
-
for (const excluded of excludeKeywords) {
|
|
257014
|
-
if (lowerQuery.includes(excluded.toLowerCase())) {
|
|
257015
|
-
return false;
|
|
257016
|
-
}
|
|
257017
|
-
}
|
|
257018
|
-
}
|
|
257019
|
-
for (const keyword of routing.keywords) {
|
|
257020
|
-
if (lowerQuery.includes(keyword.toLowerCase())) {
|
|
257021
|
-
return true;
|
|
257022
|
-
}
|
|
257023
|
-
}
|
|
257024
|
-
if (routing.patterns && routing.patterns.length > 0) {
|
|
257025
|
-
for (const pattern of routing.patterns) {
|
|
257026
|
-
try {
|
|
257027
|
-
if (new RegExp(pattern, "i").test(query)) {
|
|
257028
|
-
return true;
|
|
257029
|
-
}
|
|
257030
|
-
} catch {
|
|
257031
|
-
console.warn(`Invalid regex pattern in expert routing: ${pattern}`);
|
|
257032
|
-
}
|
|
257033
|
-
}
|
|
257034
|
-
}
|
|
257035
|
-
return false;
|
|
257036
|
-
};
|
|
257037
|
-
}
|
|
257038
|
-
function getAvailableToolsForExpert(enabledFeatures) {
|
|
257039
|
-
return [
|
|
257040
|
-
{
|
|
257041
|
-
category: "Usable (Built-in)",
|
|
257042
|
-
tools: [...BUILT_IN_TOOLS],
|
|
257043
|
-
available: true
|
|
257044
|
-
},
|
|
257045
|
-
{
|
|
257046
|
-
category: "Web Search",
|
|
257047
|
-
tools: [...FEATURE_GATED_TOOLS.webSearch],
|
|
257048
|
-
available: enabledFeatures.webSearch ?? false
|
|
257049
|
-
},
|
|
257050
|
-
{
|
|
257051
|
-
category: "Image Generation",
|
|
257052
|
-
tools: [...FEATURE_GATED_TOOLS.imageGeneration],
|
|
257053
|
-
available: enabledFeatures.imageGeneration ?? false
|
|
257054
|
-
},
|
|
257055
|
-
{
|
|
257056
|
-
category: "Documentation",
|
|
257057
|
-
tools: [...FEATURE_GATED_TOOLS.documentation],
|
|
257058
|
-
available: enabledFeatures.documentation ?? false
|
|
257059
|
-
}
|
|
257060
|
-
];
|
|
257061
|
-
}
|
|
257062
|
-
function normalizeParentToolConfig(config3) {
|
|
257063
|
-
if (typeof config3 === "string") {
|
|
257064
|
-
return { name: config3 };
|
|
257065
|
-
}
|
|
257066
|
-
return config3;
|
|
257067
|
-
}
|
|
257068
|
-
function getParentToolName(config3) {
|
|
257069
|
-
if (typeof config3 === "string") {
|
|
257070
|
-
return config3;
|
|
257071
|
-
}
|
|
257072
|
-
return config3.name;
|
|
257073
|
-
}
|
|
257074
|
-
function mergeParentToolSchemas(parentTools, registeredSchemas) {
|
|
257075
|
-
return parentTools.map((config3) => {
|
|
257076
|
-
const normalized = normalizeParentToolConfig(config3);
|
|
257077
|
-
const toolName = normalized.name;
|
|
257078
|
-
if (normalized.description) {
|
|
257079
|
-
return normalized;
|
|
257080
|
-
}
|
|
257081
|
-
const schema = registeredSchemas?.get(toolName);
|
|
257082
|
-
if (schema) {
|
|
257083
|
-
return {
|
|
257084
|
-
name: toolName,
|
|
257085
|
-
description: schema.description,
|
|
257086
|
-
parameters: schema.parameters || normalized.parameters
|
|
257087
|
-
};
|
|
257088
|
-
}
|
|
257089
|
-
return normalized;
|
|
257090
|
-
});
|
|
257091
|
-
}
|
|
257092
|
-
function isParentToolComplete(tool2) {
|
|
257093
|
-
return !!(tool2.name && tool2.description);
|
|
257094
|
-
}
|
|
257095
|
-
var BUILT_IN_TOOLS, FEATURE_GATED_TOOLS, expertRoutingSchema, parentToolNameSchema, parentToolFullDefinitionSchema, parentToolDefinitionSchema, parentToolSchemaSchema, MAX_PARENT_TOOLS, expertConfigSchema, createCustomExpertSchema, updateCustomExpertSchema;
|
|
257096
|
-
var init_custom_expert = __esm({
|
|
257097
|
-
"src/core/types/custom-expert.ts"() {
|
|
257098
|
-
"use strict";
|
|
257099
|
-
init_zod();
|
|
257100
|
-
init_rich_fragment_prompt();
|
|
257101
|
-
init_system_prompt_source();
|
|
257102
|
-
BUILT_IN_TOOLS = [
|
|
257103
|
-
"agentic-search-fragments",
|
|
257104
|
-
"search-memory-fragments",
|
|
257105
|
-
"list-memory-fragments",
|
|
257106
|
-
"get-memory-fragment-content",
|
|
257107
|
-
"create-memory-fragment",
|
|
257108
|
-
"update-memory-fragment",
|
|
257109
|
-
"list-workspaces",
|
|
257110
|
-
"get-fragment-types"
|
|
257111
|
-
];
|
|
257112
|
-
FEATURE_GATED_TOOLS = {
|
|
257113
|
-
webSearch: [
|
|
257114
|
-
"exa-search",
|
|
257115
|
-
"exa-find-similar",
|
|
257116
|
-
"exa-get-contents",
|
|
257117
|
-
"WebFetch",
|
|
257118
|
-
"WebSearch"
|
|
257119
|
-
],
|
|
257120
|
-
imageGeneration: ["generate-image", "view-image"],
|
|
257121
|
-
documentation: ["resolve-library-id", "query-docs"]
|
|
257122
|
-
};
|
|
257123
|
-
expertRoutingSchema = external_exports.object({
|
|
257124
|
-
keywords: external_exports.array(external_exports.string().min(1).max(100)).min(1, "At least one keyword is required for routing"),
|
|
257125
|
-
patterns: external_exports.array(external_exports.string().max(500)).optional()
|
|
257126
|
-
});
|
|
257127
|
-
parentToolNameSchema = external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens");
|
|
257128
|
-
parentToolFullDefinitionSchema = external_exports.object({
|
|
257129
|
-
name: external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens"),
|
|
257130
|
-
description: external_exports.string().min(1).max(1e3).optional(),
|
|
257131
|
-
parameters: external_exports.record(external_exports.unknown()).optional()
|
|
257132
|
-
});
|
|
257133
|
-
parentToolDefinitionSchema = external_exports.union([
|
|
257134
|
-
parentToolNameSchema,
|
|
257135
|
-
parentToolFullDefinitionSchema
|
|
257136
|
-
]);
|
|
257137
|
-
parentToolSchemaSchema = external_exports.object({
|
|
257138
|
-
name: external_exports.string().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/i, "Tool name must start with a letter and contain only alphanumeric, underscores, or hyphens"),
|
|
257139
|
-
description: external_exports.string().min(1).max(1e3),
|
|
257140
|
-
parameters: external_exports.object({
|
|
257141
|
-
type: external_exports.literal("object"),
|
|
257142
|
-
properties: external_exports.record(external_exports.unknown()),
|
|
257143
|
-
required: external_exports.array(external_exports.string()).optional()
|
|
257144
|
-
}).optional(),
|
|
257145
|
-
skill: external_exports.object({
|
|
257146
|
-
id: external_exports.string().min(1).max(100).optional(),
|
|
257147
|
-
title: external_exports.string().min(1).max(200).optional(),
|
|
257148
|
-
summary: external_exports.string().max(1e3).optional(),
|
|
257149
|
-
tags: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
|
|
257150
|
-
scope: external_exports.enum(["global", "page"]).optional()
|
|
257151
|
-
}).optional()
|
|
257152
|
-
});
|
|
257153
|
-
MAX_PARENT_TOOLS = 32;
|
|
257154
|
-
expertConfigSchema = external_exports.object({
|
|
257155
|
-
systemPrompt: external_exports.string().min(1).max(5e4),
|
|
257156
|
-
systemPromptSource: systemPromptSourceSchema.nullable().optional(),
|
|
257157
|
-
enabledTools: external_exports.array(external_exports.string()),
|
|
257158
|
-
routing: expertRoutingSchema,
|
|
257159
|
-
modelPreference: external_exports.enum(["inherit", "quick-thinking", "deep-thinking", "multi-lingual"]),
|
|
257160
|
-
directModelId: external_exports.string().regex(
|
|
257161
|
-
/^[a-z0-9-]+\/[a-z0-9.-]+$/,
|
|
257162
|
-
"Must be a valid model ID (e.g., anthropic/claude-sonnet-4.5)"
|
|
257163
|
-
).optional().nullable(),
|
|
257164
|
-
temperature: external_exports.number().min(0).max(1).optional(),
|
|
257165
|
-
maxTokens: external_exports.number().min(100).max(32e3).optional(),
|
|
257166
|
-
uiColor: external_exports.string().max(50).optional(),
|
|
257167
|
-
uiEmoji: external_exports.string().max(10).optional(),
|
|
257168
|
-
avatarUrl: external_exports.string().refine(
|
|
257169
|
-
(val) => val.startsWith("data:") || val.startsWith("http://") || val.startsWith("https://") || val.startsWith("/"),
|
|
257170
|
-
"Must be a valid URL, data URL, or path"
|
|
257171
|
-
).optional(),
|
|
257172
|
-
parentTools: external_exports.array(parentToolDefinitionSchema).max(MAX_PARENT_TOOLS).optional(),
|
|
257173
|
-
excludeKeywords: external_exports.array(external_exports.string().min(1).max(50)).max(20).optional(),
|
|
257174
|
-
priority: external_exports.number().int().min(0).max(100).optional(),
|
|
257175
|
-
maxTurns: external_exports.number().int().min(1).max(50).optional(),
|
|
257176
|
-
uiShortName: external_exports.string().max(30).optional()
|
|
257177
|
-
});
|
|
257178
|
-
createCustomExpertSchema = external_exports.object({
|
|
257179
|
-
key: external_exports.string().min(1).max(100).regex(/^[a-z0-9-]+$/, "Key must be lowercase alphanumeric with hyphens").optional(),
|
|
257180
|
-
workspaceId: external_exports.string().uuid().optional(),
|
|
257181
|
-
name: external_exports.string().min(1).max(255),
|
|
257182
|
-
description: external_exports.string().min(1).max(1e3),
|
|
257183
|
-
expertConfig: expertConfigSchema
|
|
257184
|
-
});
|
|
257185
|
-
updateCustomExpertSchema = external_exports.object({
|
|
257186
|
-
name: external_exports.string().min(1).max(255).optional(),
|
|
257187
|
-
description: external_exports.string().min(1).max(1e3).optional(),
|
|
257188
|
-
expertConfig: expertConfigSchema.partial().optional(),
|
|
257189
|
-
status: external_exports.enum(["active", "archived", "draft"]).optional()
|
|
257190
|
-
});
|
|
257191
|
-
}
|
|
257192
|
-
});
|
|
257193
|
-
|
|
257194
|
-
// src/lib/services/expert-permission.service.ts
|
|
257195
|
-
async function checkExpertPermission(expertId, userId) {
|
|
257196
|
-
const [collaborator] = await db.select({ role: expertCollaborators.role }).from(expertCollaborators).where(
|
|
257197
|
-
and(
|
|
257198
|
-
eq(expertCollaborators.expertId, expertId),
|
|
257199
|
-
eq(expertCollaborators.userId, userId),
|
|
257200
|
-
isNull(expertCollaborators.deletedAt)
|
|
257201
|
-
)
|
|
257202
|
-
).limit(1);
|
|
257203
|
-
if (collaborator) {
|
|
257204
|
-
const role = collaborator.role;
|
|
257205
|
-
return {
|
|
257206
|
-
hasAccess: true,
|
|
257207
|
-
role,
|
|
257208
|
-
isOwner: role === "owner",
|
|
257209
|
-
isViewer: role === "viewer" || role === "subscriber"
|
|
257210
|
-
};
|
|
257211
|
-
}
|
|
257212
|
-
const [expert] = await db.select({ createdBy: customExperts.createdBy }).from(customExperts).where(eq(customExperts.id, expertId)).limit(1);
|
|
257213
|
-
if (expert && expert.createdBy === userId) {
|
|
257214
|
-
return {
|
|
257215
|
-
hasAccess: true,
|
|
257216
|
-
role: "owner",
|
|
257217
|
-
isOwner: true,
|
|
257218
|
-
isViewer: false
|
|
257219
|
-
};
|
|
257220
|
-
}
|
|
257221
|
-
return {
|
|
257222
|
-
hasAccess: false,
|
|
257223
|
-
role: "none",
|
|
257224
|
-
isOwner: false,
|
|
257225
|
-
isViewer: false
|
|
257226
|
-
};
|
|
257227
|
-
}
|
|
257228
|
-
async function canViewExpert(expertId, userId) {
|
|
257229
|
-
const permission = await checkExpertPermission(expertId, userId);
|
|
257230
|
-
return permission.hasAccess;
|
|
257231
|
-
}
|
|
257232
|
-
async function checkConfigPermission(configId, userId) {
|
|
257233
|
-
const [collaborator] = await db.select({ role: configCollaborators.role }).from(configCollaborators).where(
|
|
257234
|
-
and(
|
|
257235
|
-
eq(configCollaborators.configId, configId),
|
|
257236
|
-
eq(configCollaborators.userId, userId),
|
|
257237
|
-
isNull(configCollaborators.deletedAt)
|
|
257238
|
-
)
|
|
257239
|
-
).limit(1);
|
|
257240
|
-
if (collaborator) {
|
|
257241
|
-
const role = collaborator.role;
|
|
257242
|
-
return {
|
|
257243
|
-
hasAccess: true,
|
|
257244
|
-
role,
|
|
257245
|
-
isOwner: role === "owner",
|
|
257246
|
-
isViewer: role === "viewer"
|
|
257247
|
-
};
|
|
257248
|
-
}
|
|
257249
|
-
const [config3] = await db.select({ createdBy: chatConfigs.createdBy }).from(chatConfigs).where(eq(chatConfigs.id, configId)).limit(1);
|
|
257250
|
-
if (config3 && config3.createdBy === userId) {
|
|
257251
|
-
return {
|
|
257252
|
-
hasAccess: true,
|
|
257253
|
-
role: "owner",
|
|
257254
|
-
isOwner: true,
|
|
257255
|
-
isViewer: false
|
|
257256
|
-
};
|
|
257257
|
-
}
|
|
257258
|
-
return {
|
|
257259
|
-
hasAccess: false,
|
|
257260
|
-
role: "none",
|
|
257261
|
-
isOwner: false,
|
|
257262
|
-
isViewer: false
|
|
257263
|
-
};
|
|
257264
|
-
}
|
|
257265
|
-
async function canEditConfig(configId, userId) {
|
|
257266
|
-
const permission = await checkConfigPermission(configId, userId);
|
|
257267
|
-
return permission.isOwner;
|
|
257268
|
-
}
|
|
257269
|
-
var init_expert_permission_service = __esm({
|
|
257270
|
-
"src/lib/services/expert-permission.service.ts"() {
|
|
257271
|
-
"use strict";
|
|
257272
|
-
init_client7();
|
|
257273
|
-
init_schema4();
|
|
257274
|
-
init_drizzle_orm();
|
|
257275
|
-
init_custom_expert();
|
|
257276
|
-
}
|
|
257277
|
-
});
|
|
257278
|
-
|
|
257279
257297
|
// node_modules/.pnpm/parse5@8.0.1/node_modules/parse5/dist/common/unicode.js
|
|
257280
257298
|
function isSurrogate(cp) {
|
|
257281
257299
|
return cp >= 55296 && cp <= 57343;
|