@usabledev/usable-chat 1.219.1 → 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 +57 -9
  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.1";
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,
@@ -251134,8 +251172,9 @@ async function getOrCreateUser(userId, options2) {
251134
251172
  }
251135
251173
  async function getUserByEmail(email3) {
251136
251174
  const normalizedEmail = email3.toLowerCase().trim();
251137
- const [user] = await db.select().from(users).where(eq(users.email, normalizedEmail)).limit(1);
251138
- 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;
251139
251178
  }
251140
251179
  var init_user_service = __esm({
251141
251180
  "src/lib/services/user.service.ts"() {
@@ -300586,7 +300625,7 @@ HOW TO USE THIS:
300586
300625
  }
300587
300626
  let modelId;
300588
300627
  try {
300589
- modelId = mapModeToModel(params.model);
300628
+ modelId = mapModeToModel(params.model === "auto" && context3.autoSubagentModel ? context3.selectedModelId ?? params.model : params.model);
300590
300629
  if (!isValidModel(modelId) && !isValidModel(params.model)) {
300591
300630
  return {
300592
300631
  success: false,
@@ -378175,6 +378214,9 @@ async function buildAgentRuntime(request, preparation) {
378175
378214
  return {
378176
378215
  description: todoTool.description,
378177
378216
  parameters: parameters2,
378217
+ validateArguments: (args) => {
378218
+ validateChatToolArguments(todoTool.parameters, args);
378219
+ },
378178
378220
  execute: async (args, options2) => {
378179
378221
  const toolContext = options2?.executionContext;
378180
378222
  if (!toolContext) throw new Error("Todo tool execution context is unavailable");
@@ -378382,6 +378424,7 @@ async function buildAgentRuntime(request, preparation) {
378382
378424
  selectedModelId,
378383
378425
  providerPrivacy,
378384
378426
  chatMode,
378427
+ autoSubagentModel: Boolean(preparation?.startSubagent && config3.autoModelRouting),
378385
378428
  imageGenModel: context3.metadata?.imageGenModel,
378386
378429
  imageGenThinking: context3.metadata?.imageGenThinking,
378387
378430
  registeredParentToolSchemas: context3.registeredParentToolSchemas,
@@ -378392,7 +378435,9 @@ async function buildAgentRuntime(request, preparation) {
378392
378435
  const researchWorkerBudget = researchLimits ? createResearchWorkerBudget(researchLimits) : null;
378393
378436
  if (!config3.localFilesystem) {
378394
378437
  aiTools["spawn_subagent"] = {
378395
- 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,
378396
378441
  parameters: spawnSubagentSchema,
378397
378442
  execute: async (args, options2) => {
378398
378443
  const spawnArgs = args;
@@ -381007,6 +381052,8 @@ function createOrchestratorRequest(messages4, context3, config3, persona, apiKey
381007
381052
  },
381008
381053
  config: {
381009
381054
  model: config3.model || "anthropic/claude-sonnet-4",
381055
+ autoModelNotice: config3.autoModelNotice,
381056
+ autoModelRouting: config3.autoModelRouting,
381010
381057
  maxSteps: config3.maxSteps ?? 200,
381011
381058
  temperature: config3.temperature ?? 0.7,
381012
381059
  maxTokens: config3.maxTokens ?? 4e4,
@@ -381062,6 +381109,7 @@ var init_orchestrator = __esm({
381062
381109
  init_interactive_capabilities_prompt();
381063
381110
  init_tool_authorization();
381064
381111
  init_persist_injected_pause();
381112
+ init_argument_validation();
381065
381113
  init_language_prompt();
381066
381114
  init_visualization_prompt();
381067
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.1",
3
+ "version": "1.220.0",
4
4
  "description": "usable-chat — terminal harness for usable-chat (headless + TUI)",
5
5
  "type": "module",
6
6
  "bin": {