@usabledev/usable-chat 1.219.0 → 1.220.0

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.
Files changed (2) hide show
  1. package/cli.js +58 -13
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -52968,7 +52968,7 @@ var init_model_registry = __esm({
52968
52968
  var version2;
52969
52969
  var init_package = __esm({
52970
52970
  "package.json"() {
52971
- version2 = "1.219.0";
52971
+ version2 = "1.220.0";
52972
52972
  }
52973
52973
  });
52974
52974
 
@@ -98995,6 +98995,7 @@ var require_dist2 = __commonJS({
98995
98995
  // src/core/tools/argument-validation.ts
98996
98996
  var argument_validation_exports = {};
98997
98997
  __export2(argument_validation_exports, {
98998
+ ToolArgumentValidationError: () => ToolArgumentValidationError,
98998
98999
  serializedChatToolSchema: () => serializedChatToolSchema,
98999
99000
  validateChatToolArguments: () => validateChatToolArguments
99000
99001
  });
@@ -99007,19 +99008,30 @@ function serializedChatToolSchema(parameters2) {
99007
99008
  return parameters2;
99008
99009
  }
99009
99010
  function validateChatToolArguments(parameters2, args) {
99011
+ if (parameters2 && typeof parameters2 === "object" && "safeParse" in parameters2 && typeof parameters2.safeParse === "function") {
99012
+ const result = parameters2.safeParse(args);
99013
+ if (!result.success) throw new ToolArgumentValidationError(result.error.issues.slice(0, 4).map((issue2) => `${issue2.path.join(".") || "arguments"}: ${issue2.message}`).join("; "));
99014
+ return;
99015
+ }
99010
99016
  const validator3 = new import_ajv.default({ strict: false, allErrors: false, allowUnionTypes: true });
99011
99017
  (0, import_ajv_formats.default)(validator3);
99012
99018
  const { $schema: _dialect, ...schema } = serializedChatToolSchema(parameters2);
99013
99019
  const validate4 = validator3.compile(schema);
99014
- if (!validate4(args)) throw new Error("Tool arguments do not match the authorized schema");
99020
+ if (!validate4(args)) throw new ToolArgumentValidationError((validate4.errors ?? []).slice(0, 4).map((issue2) => `${issue2.instancePath || "arguments"} ${issue2.message}`).join("; "));
99015
99021
  }
99016
- var import_ajv, import_ajv_formats;
99022
+ var import_ajv, import_ajv_formats, ToolArgumentValidationError;
99017
99023
  var init_argument_validation = __esm({
99018
99024
  "src/core/tools/argument-validation.ts"() {
99019
99025
  "use strict";
99020
99026
  import_ajv = __toESM(require_ajv());
99021
99027
  import_ajv_formats = __toESM(require_dist2());
99022
99028
  init_esm2();
99029
+ ToolArgumentValidationError = class extends Error {
99030
+ constructor(detail) {
99031
+ super(`Tool arguments are invalid: ${detail.slice(0, 1e3)}`);
99032
+ this.name = "ToolArgumentValidationError";
99033
+ }
99034
+ };
99023
99035
  }
99024
99036
  });
99025
99037
 
@@ -99036,9 +99048,10 @@ function preparedToolScope(tools, guards) {
99036
99048
  },
99037
99049
  async validate(name18, args) {
99038
99050
  const { tool: tool2 } = lookup3(name18);
99051
+ await guards.authorize(name18, args);
99039
99052
  const { validateChatToolArguments: validateChatToolArguments2 } = await Promise.resolve().then(() => (init_argument_validation(), argument_validation_exports));
99040
99053
  validateChatToolArguments2(tool2.parameters ?? { type: "object" }, args);
99041
- await guards.authorize(name18, args);
99054
+ tool2.validateArguments?.(args);
99042
99055
  },
99043
99056
  async invoke(name18, args, invocationId) {
99044
99057
  const { map: map5 } = lookup3(name18);
@@ -172645,7 +172658,7 @@ var init_schema_hooks = __esm({
172645
172658
  });
172646
172659
 
172647
172660
  // src/lib/db/schema-chat-collaboration.ts
172648
- var chatConversationScopes, chatConversationCollaborators;
172661
+ var chatConversationScopes, chatConversationCollaborators, chatConversationInvitations;
172649
172662
  var init_schema_chat_collaboration = __esm({
172650
172663
  "src/lib/db/schema-chat-collaboration.ts"() {
172651
172664
  "use strict";
@@ -172675,6 +172688,7 @@ var init_schema_chat_collaboration = __esm({
172675
172688
  userId: uuid3("user_id").notNull(),
172676
172689
  role: text2("role").$type().notNull(),
172677
172690
  invitedBy: uuid3("invited_by").notNull(),
172691
+ invitationId: uuid3("invitation_id"),
172678
172692
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
172679
172693
  revokedAt: timestamp("revoked_at", { withTimezone: true })
172680
172694
  },
@@ -172690,6 +172704,29 @@ var init_schema_chat_collaboration = __esm({
172690
172704
  )
172691
172705
  })
172692
172706
  );
172707
+ chatConversationInvitations = pgTable(
172708
+ "chat_conversation_invitations",
172709
+ {
172710
+ id: uuid3("id").primaryKey(),
172711
+ conversationId: uuid3("conversation_id").notNull(),
172712
+ userId: uuid3("user_id").notNull(),
172713
+ invitedBy: uuid3("invited_by").notNull(),
172714
+ role: text2("role").$type().notNull(),
172715
+ status: text2("status").$type().notNull(),
172716
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
172717
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
172718
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull()
172719
+ },
172720
+ (table) => ({
172721
+ recipientIndex: index("chat_invitations_recipient_idx").on(table.userId),
172722
+ conversationIndex: index("chat_invitations_conversation_idx").on(table.conversationId),
172723
+ roleCheck: check2("chat_invitation_role_check", sql`${table.role} IN ('viewer', 'participant')`),
172724
+ statusCheck: check2(
172725
+ "chat_invitation_status_check",
172726
+ sql`${table.status} IN ('pending', 'accepted', 'declined', 'revoked')`
172727
+ )
172728
+ })
172729
+ );
172693
172730
  }
172694
172731
  });
172695
172732
 
@@ -172703,6 +172740,7 @@ __export2(schema_exports3, {
172703
172740
  browserSessions: () => browserSessions,
172704
172741
  chatConfigs: () => chatConfigs,
172705
172742
  chatConversationCollaborators: () => chatConversationCollaborators,
172743
+ chatConversationInvitations: () => chatConversationInvitations,
172706
172744
  chatConversationScopes: () => chatConversationScopes,
172707
172745
  configCollaborators: () => configCollaborators,
172708
172746
  conversationContext: () => conversationContext,
@@ -185953,7 +185991,7 @@ function prepareSubagentRuntime(options2) {
185953
185991
  model: options2.model,
185954
185992
  tools: options2.tools,
185955
185993
  maxSteps: options2.maxSteps ?? SUBAGENT_DEFAULTS.maxSteps,
185956
- timeoutMs: options2.timeoutMs ?? SUBAGENT_DEFAULTS.timeoutMs,
185994
+ timeoutMs: options2.timeoutMs,
185957
185995
  maxTokens: options2.maxTokens ?? SUBAGENT_DEFAULTS.maxTokens,
185958
185996
  temperature: options2.temperature ?? SUBAGENT_DEFAULTS.temperature,
185959
185997
  providerPrivacy: options2.providerPrivacy,
@@ -185983,7 +186021,6 @@ var init_prepare_subagent_runtime = __esm({
185983
186021
  init_subagent_tool_dispatch();
185984
186022
  SUBAGENT_DEFAULTS = {
185985
186023
  maxSteps: 10,
185986
- timeoutMs: 6e4,
185987
186024
  maxTokens: 4096,
185988
186025
  temperature: 0.3
185989
186026
  };
@@ -251135,8 +251172,9 @@ async function getOrCreateUser(userId, options2) {
251135
251172
  }
251136
251173
  async function getUserByEmail(email3) {
251137
251174
  const normalizedEmail = email3.toLowerCase().trim();
251138
- const [user] = await db.select().from(users).where(eq(users.email, normalizedEmail)).limit(1);
251139
- return user ?? null;
251175
+ const matches = await db.select().from(users).where(sql`lower(trim(${users.email})) = ${normalizedEmail}`).limit(2);
251176
+ if (matches.length > 1) throw new Error("AMBIGUOUS_USER_EMAIL");
251177
+ return matches[0] ?? null;
251140
251178
  }
251141
251179
  var init_user_service = __esm({
251142
251180
  "src/lib/services/user.service.ts"() {
@@ -299144,8 +299182,6 @@ ${effectiveSystemPrompt}`;
299144
299182
  // Pass token provider for MCP tool authentication
299145
299183
  maxSteps: subAgent.maxTurns ?? 10,
299146
299184
  // Allow multi-step tool calling; expert maxTurns overrides default
299147
- timeoutMs: 6e4,
299148
- // 60 second timeout
299149
299185
  temperature,
299150
299186
  maxTokens,
299151
299187
  abortSignal: options2.abortSignal,
@@ -300589,7 +300625,7 @@ HOW TO USE THIS:
300589
300625
  }
300590
300626
  let modelId;
300591
300627
  try {
300592
- modelId = mapModeToModel(params.model);
300628
+ modelId = mapModeToModel(params.model === "auto" && context3.autoSubagentModel ? context3.selectedModelId ?? params.model : params.model);
300593
300629
  if (!isValidModel(modelId) && !isValidModel(params.model)) {
300594
300630
  return {
300595
300631
  success: false,
@@ -378178,6 +378214,9 @@ async function buildAgentRuntime(request, preparation) {
378178
378214
  return {
378179
378215
  description: todoTool.description,
378180
378216
  parameters: parameters2,
378217
+ validateArguments: (args) => {
378218
+ validateChatToolArguments(todoTool.parameters, args);
378219
+ },
378181
378220
  execute: async (args, options2) => {
378182
378221
  const toolContext = options2?.executionContext;
378183
378222
  if (!toolContext) throw new Error("Todo tool execution context is unavailable");
@@ -378385,6 +378424,7 @@ async function buildAgentRuntime(request, preparation) {
378385
378424
  selectedModelId,
378386
378425
  providerPrivacy,
378387
378426
  chatMode,
378427
+ autoSubagentModel: Boolean(preparation?.startSubagent && config3.autoModelRouting),
378388
378428
  imageGenModel: context3.metadata?.imageGenModel,
378389
378429
  imageGenThinking: context3.metadata?.imageGenThinking,
378390
378430
  registeredParentToolSchemas: context3.registeredParentToolSchemas,
@@ -378395,7 +378435,9 @@ async function buildAgentRuntime(request, preparation) {
378395
378435
  const researchWorkerBudget = researchLimits ? createResearchWorkerBudget(researchLimits) : null;
378396
378436
  if (!config3.localFilesystem) {
378397
378437
  aiTools["spawn_subagent"] = {
378398
- description: spawnSubagentTool.description,
378438
+ description: preparation?.startSubagent && config3.autoModelRouting ? `${spawnSubagentTool.description}
378439
+
378440
+ This conversation uses Auto. Pass model: "auto". Each child task is routed independently through the user's Auto choices; a concrete tool argument does not override this policy.` : spawnSubagentTool.description,
378399
378441
  parameters: spawnSubagentSchema,
378400
378442
  execute: async (args, options2) => {
378401
378443
  const spawnArgs = args;
@@ -381010,6 +381052,8 @@ function createOrchestratorRequest(messages4, context3, config3, persona, apiKey
381010
381052
  },
381011
381053
  config: {
381012
381054
  model: config3.model || "anthropic/claude-sonnet-4",
381055
+ autoModelNotice: config3.autoModelNotice,
381056
+ autoModelRouting: config3.autoModelRouting,
381013
381057
  maxSteps: config3.maxSteps ?? 200,
381014
381058
  temperature: config3.temperature ?? 0.7,
381015
381059
  maxTokens: config3.maxTokens ?? 4e4,
@@ -381065,6 +381109,7 @@ var init_orchestrator = __esm({
381065
381109
  init_interactive_capabilities_prompt();
381066
381110
  init_tool_authorization();
381067
381111
  init_persist_injected_pause();
381112
+ init_argument_validation();
381068
381113
  init_language_prompt();
381069
381114
  init_visualization_prompt();
381070
381115
  init_data_staging_prompt();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usabledev/usable-chat",
3
- "version": "1.219.0",
3
+ "version": "1.220.0",
4
4
  "description": "usable-chat — terminal harness for usable-chat (headless + TUI)",
5
5
  "type": "module",
6
6
  "bin": {