@bpinhosilva/agent-orchestrator 1.0.0-alpha.27 → 1.0.0-alpha.29

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 (39) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +18 -5
  3. package/dist/agents/default-provider-models.d.ts +11 -0
  4. package/dist/agents/default-provider-models.js +17 -0
  5. package/dist/agents/implementations/claude.agent.js +2 -1
  6. package/dist/agents/implementations/gemini.agent.js +2 -1
  7. package/dist/cli/index.js +4 -13
  8. package/dist/database/migration-sql.utils.d.ts +2 -0
  9. package/dist/database/migration-sql.utils.js +11 -0
  10. package/dist/database/migration-state.d.ts +0 -1
  11. package/dist/database/migration-state.js +14 -27
  12. package/dist/main.js +1 -1
  13. package/dist/migrations/{1775260737095-BaselineSchema.d.ts → 1775266979821-InitialSchema.d.ts} +2 -1
  14. package/dist/migrations/1775266979821-InitialSchema.js +57 -0
  15. package/dist/migrations/1775268200000-SeedDefaultProvidersAndModels.d.ts +8 -0
  16. package/dist/migrations/1775268200000-SeedDefaultProvidersAndModels.js +45 -0
  17. package/dist/migrations/1775269500000-BackfillDefaultModelProviderIds.d.ts +9 -0
  18. package/dist/migrations/1775269500000-BackfillDefaultModelProviderIds.js +51 -0
  19. package/dist/ui/assets/AgentFleet-BK16qSVb.js +1 -0
  20. package/dist/ui/assets/{ConfirmDialog-C1bkNgZT.js → ConfirmDialog-CAb4bA6D.js} +2 -2
  21. package/dist/ui/assets/Profile-CR2v0N6L.js +1 -0
  22. package/dist/ui/assets/{ProjectDetail-U4T3kwT6.js → ProjectDetail-KyqWvAT1.js} +1 -1
  23. package/dist/ui/assets/Providers-CUSKu0A6.js +1 -0
  24. package/dist/ui/assets/Scheduler-DLC1PTRB.js +1 -0
  25. package/dist/ui/assets/{TaskDetail-CEKuDv4W.js → TaskDetail-O6ZsA0nQ.js} +1 -1
  26. package/dist/ui/assets/{TaskManager-vYV5vdM4.js → TaskManager-CDN6O6Yh.js} +2 -2
  27. package/dist/ui/assets/index-BfqRKMgT.css +2 -0
  28. package/dist/ui/assets/index-tztXTZhU.js +2 -0
  29. package/dist/ui/assets/providers-CVpZdX9Z.js +1 -0
  30. package/dist/ui/index.html +2 -2
  31. package/package.json +2 -2
  32. package/dist/migrations/1775260737095-BaselineSchema.js +0 -215
  33. package/dist/ui/assets/AgentFleet-2bUM5tS8.js +0 -1
  34. package/dist/ui/assets/Profile-GA-ikEkL.js +0 -1
  35. package/dist/ui/assets/Providers-Dr8fFIru.js +0 -1
  36. package/dist/ui/assets/Scheduler-D1seGplm.js +0 -1
  37. package/dist/ui/assets/index-CVlXsOAm.js +0 -2
  38. package/dist/ui/assets/index-CoqfjJsB.css +0 -2
  39. package/dist/ui/assets/providers-_o5m2NEh.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [1.0.0-alpha.29](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.28...v1.0.0-alpha.29) (2026-04-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * **migrations:** add seed and backfill migrations ([5991146](https://github.com/bpinhosilva/agent-orchestrator/commit/5991146cbb3bc971bddf73295dcf7dbd3e2b74e4))
7
+
8
+ # [1.0.0-alpha.28](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.27...v1.0.0-alpha.28) (2026-04-04)
9
+
10
+
11
+ ### Features
12
+
13
+ * **migrations:** add initial schema with users, providers, models, agents, projects, tasks ([e08e338](https://github.com/bpinhosilva/agent-orchestrator/commit/e08e3388794e8a556be3584daedd30252a8904fb))
14
+ * **migrations:** db schema ([a0a98b7](https://github.com/bpinhosilva/agent-orchestrator/commit/a0a98b725e09f6d3a9a8fc2305704772195fe2d8))
15
+
1
16
  # [1.0.0-alpha.27](https://github.com/bpinhosilva/agent-orchestrator/compare/v1.0.0-alpha.26...v1.0.0-alpha.27) (2026-04-04)
2
17
 
3
18
 
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Agent Orchestrator
2
2
 
3
3
  <p align="center">
4
- <img src="docs/assets/lupy-mascot.webp" alt="Lupy, the Agent Orchestrator mascot" width="500" />
4
+ <img src="https://raw.githubusercontent.com/bpinhosilva/agent-orchestrator/main/docs/assets/lupy-mascot.webp" alt="Lupy, the Agent Orchestrator mascot" width="500" />
5
5
  </p>
6
6
 
7
7
  <p align="center"><em>Lupy, the project mascot, inspired by Bruno's dog and companion of 10 years.</em></p>
@@ -66,7 +66,7 @@ agent-orchestrator run
66
66
  agent-orchestrator status
67
67
  ```
68
68
 
69
- `setup` can create the runtime `.env`, run migrations, and seed an admin user. The default runtime home is `~/.agent-orchestrator`, or `${AGENT_ORCHESTRATOR_HOME}` if you set it explicitly.
69
+ `setup` can create the runtime `.env`, run migrations, seed an admin user, and prompt you to apply pending migrations after package updates. `run` does not upgrade the database automatically. The default runtime home is `~/.agent-orchestrator`, or `${AGENT_ORCHESTRATOR_HOME}` if you set it explicitly.
70
70
 
71
71
  For deeper CLI usage, see [docs/CLI.md](docs/CLI.md).
72
72
 
@@ -188,11 +188,13 @@ When running the packaged app or a production build with static UI enabled, the
188
188
 
189
189
  The repository ships three Compose entrypoints:
190
190
 
191
+ All Compose stacks now require the database variables in the project `.env` file: `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`, and `POSTGRES_TEST_DB` for the integration stack.
192
+
191
193
  | File | Purpose |
192
194
  | --- | --- |
193
195
  | `docker-compose.yml` | Production-style stack with PostgreSQL, API, and Caddy-served UI |
194
196
  | `docker-compose.dev.yml` | Development stack with API hot reload and Vite UI dev server |
195
- | `docker-compose-test.yml` | Integration stack for migration, CLI/runtime, API, and UI checks |
197
+ | `docker-compose.test.yml` | Integration stack for migration, CLI/runtime, API, and UI checks |
196
198
 
197
199
  ### Production-style stack
198
200
 
@@ -204,7 +206,7 @@ docker compose run --rm api dist/cli/index.js migrate --yes
204
206
  Endpoints:
205
207
 
206
208
  - UI: `https://localhost` or `https://agent-orchestrator.localhost`
207
- - API: `http://localhost:3000/api/v1`
209
+ - API: `https://localhost/api/v1` or `https://agent-orchestrator.localhost/api/v1`
208
210
 
209
211
  In this stack the UI is served by **Caddy**, not by the Nest app. Docker explicitly sets `SERVE_STATIC_UI=false` so the backend only serves the API.
210
212
 
@@ -222,7 +224,18 @@ Endpoints:
222
224
 
223
225
  ### Integration stack
224
226
 
225
- Use `docker-compose-test.yml` when you want to exercise migration behavior, packaged CLI/runtime flows, API startup, and UI reachability together.
227
+ Use `docker-compose.test.yml` when you want to exercise migration behavior, packaged CLI/runtime flows, API startup, and UI reachability together.
228
+
229
+ ```bash
230
+ npm run docker:test
231
+ docker compose -f docker-compose.test.yml --profile tools run --rm migrate
232
+ docker compose -f docker-compose.test.yml --profile tools run --rm cli
233
+ ```
234
+
235
+ Endpoints:
236
+
237
+ - UI: `https://localhost:8444` or `https://agent-orchestrator.localhost:8444`
238
+ - API: `https://localhost:8444/api/v1` or `https://agent-orchestrator.localhost:8444/api/v1`
226
239
 
227
240
  ## Development workflow
228
241
 
@@ -0,0 +1,11 @@
1
+ export declare const DEFAULT_PROVIDER_MODELS: readonly [{
2
+ readonly providerName: "google";
3
+ readonly models: readonly ["gemini-2.5-flash-lite", "gemini-2.5-flash-image"];
4
+ }, {
5
+ readonly providerName: "anthropic";
6
+ readonly models: readonly ["claude-opus-4-6", "claude-sonnet-4-6", "claude-haiku-4-5"];
7
+ }];
8
+ export declare const DEFAULT_MODEL_BY_PROVIDER: {
9
+ readonly google: "gemini-2.5-flash-lite";
10
+ readonly anthropic: "claude-opus-4-6";
11
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MODEL_BY_PROVIDER = exports.DEFAULT_PROVIDER_MODELS = void 0;
4
+ exports.DEFAULT_PROVIDER_MODELS = [
5
+ {
6
+ providerName: 'google',
7
+ models: ['gemini-2.5-flash-lite', 'gemini-2.5-flash-image'],
8
+ },
9
+ {
10
+ providerName: 'anthropic',
11
+ models: ['claude-opus-4-6', 'claude-sonnet-4-6', 'claude-haiku-4-5'],
12
+ },
13
+ ];
14
+ exports.DEFAULT_MODEL_BY_PROVIDER = {
15
+ google: exports.DEFAULT_PROVIDER_MODELS[0].models[0],
16
+ anthropic: exports.DEFAULT_PROVIDER_MODELS[1].models[0],
17
+ };
@@ -17,6 +17,7 @@ exports.ClaudeAgent = void 0;
17
17
  const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
18
18
  const common_1 = require("@nestjs/common");
19
19
  const config_1 = require("@nestjs/config");
20
+ const default_provider_models_1 = require("../default-provider-models");
20
21
  const agent_registry_1 = require("../registry/agent.registry");
21
22
  let ClaudeAgent = ClaudeAgent_1 = class ClaudeAgent {
22
23
  configService;
@@ -27,7 +28,7 @@ let ClaudeAgent = ClaudeAgent_1 = class ClaudeAgent {
27
28
  role;
28
29
  provider = 'anthropic';
29
30
  model;
30
- constructor(configService, model = 'claude-opus-4-6') {
31
+ constructor(configService, model = default_provider_models_1.DEFAULT_MODEL_BY_PROVIDER.anthropic) {
31
32
  this.configService = configService;
32
33
  this.model = model;
33
34
  }
@@ -17,6 +17,7 @@ exports.GeminiAgent = void 0;
17
17
  const genai_1 = require("@google/genai");
18
18
  const common_1 = require("@nestjs/common");
19
19
  const config_1 = require("@nestjs/config");
20
+ const default_provider_models_1 = require("../default-provider-models");
20
21
  const agent_registry_1 = require("../registry/agent.registry");
21
22
  let GeminiAgent = GeminiAgent_1 = class GeminiAgent {
22
23
  configService;
@@ -29,7 +30,7 @@ let GeminiAgent = GeminiAgent_1 = class GeminiAgent {
29
30
  provider = 'google';
30
31
  model;
31
32
  enableGrounding = true;
32
- constructor(configService, model = 'gemini-2.5-flash-lite') {
33
+ constructor(configService, model = default_provider_models_1.DEFAULT_MODEL_BY_PROVIDER.google) {
33
34
  this.configService = configService;
34
35
  this.model = model;
35
36
  }
package/dist/cli/index.js CHANGED
@@ -473,6 +473,7 @@ function buildEnvContent(currentEnv, basicConfig, databaseUrl, geminiKey, anthro
473
473
  PORT: basicConfig.port,
474
474
  DB_TYPE: basicConfig.dbType,
475
475
  DB_LOGGING: `${basicConfig.dbLogging}`,
476
+ CHECK_PENDING_MIGRATIONS_ON_STARTUP: currentEnv.CHECK_PENDING_MIGRATIONS_ON_STARTUP || 'true',
476
477
  JWT_SECRET: jwtSecret,
477
478
  };
478
479
  if (databaseUrl) {
@@ -492,6 +493,7 @@ function buildEnvContent(currentEnv, basicConfig, databaseUrl, geminiKey, anthro
492
493
  'PORT',
493
494
  'DB_TYPE',
494
495
  'DB_LOGGING',
496
+ 'CHECK_PENDING_MIGRATIONS_ON_STARTUP',
495
497
  'DATABASE_URL',
496
498
  'GEMINI_API_KEY',
497
499
  'ANTHROPIC_API_KEY',
@@ -617,7 +619,7 @@ async function handleSetup(options) {
617
619
  const envContent = buildEnvContent(currentEnv, basicConfig, databaseUrl, geminiKey, anthropicKey, jwtSecret);
618
620
  writePrivateFile(exports.ENV_PATH, envContent);
619
621
  console.log(`Configuration saved to ${exports.ENV_PATH} with mode 600.`);
620
- const { hasPending, isEmpty, requiresBaselineBootstrap } = await (0, migration_state_1.checkPendingMigrations)({
622
+ const { hasPending, isEmpty } = await (0, migration_state_1.checkPendingMigrations)({
621
623
  assumePendingOnError: true,
622
624
  });
623
625
  if (isEmpty) {
@@ -626,12 +628,6 @@ async function handleSetup(options) {
626
628
  await maybeSetupAdmin(options, interactive);
627
629
  return;
628
630
  }
629
- if (requiresBaselineBootstrap) {
630
- console.log('Existing database detected without recorded baseline migration. Recording the baseline migration metadata...');
631
- await (0, migration_state_1.runMigrations)();
632
- await maybeSetupAdmin(options, interactive);
633
- return;
634
- }
635
631
  if (hasPending) {
636
632
  const confirmMigration = await confirmAction('Pending migrations detected on an existing database. Do you want to run them?', options.yes);
637
633
  if (confirmMigration) {
@@ -838,7 +834,7 @@ function defineCommands() {
838
834
  }
839
835
  return;
840
836
  }
841
- const { hasPending, isEmpty, requiresBaselineBootstrap } = await (0, migration_state_1.checkPendingMigrations)({
837
+ const { hasPending, isEmpty } = await (0, migration_state_1.checkPendingMigrations)({
842
838
  assumePendingOnError: true,
843
839
  });
844
840
  if (isEmpty) {
@@ -846,11 +842,6 @@ function defineCommands() {
846
842
  await (0, migration_state_1.runMigrations)();
847
843
  return;
848
844
  }
849
- if (requiresBaselineBootstrap) {
850
- console.log('Existing database detected without recorded baseline migration. Recording the baseline migration metadata...');
851
- await (0, migration_state_1.runMigrations)();
852
- return;
853
- }
854
845
  if (!hasPending) {
855
846
  console.log('Database is already up to date.');
856
847
  return;
@@ -0,0 +1,2 @@
1
+ import { QueryRunner } from 'typeorm';
2
+ export declare function normalizeMigrationSqlForDriver(driverType: QueryRunner['connection']['options']['type'], sql: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMigrationSqlForDriver = normalizeMigrationSqlForDriver;
4
+ function normalizeMigrationSqlForDriver(driverType, sql) {
5
+ if (driverType !== 'postgres') {
6
+ return sql;
7
+ }
8
+ return sql
9
+ .replace(/DEFAULT\s+\(datetime\('now'\)\)/g, 'DEFAULT CURRENT_TIMESTAMP')
10
+ .replace(/\bdatetime\b/g, 'timestamp');
11
+ }
@@ -1,7 +1,6 @@
1
1
  export interface MigrationStatus {
2
2
  hasPending: boolean;
3
3
  isEmpty: boolean;
4
- requiresBaselineBootstrap: boolean;
5
4
  }
6
5
  interface CheckPendingMigrationsOptions {
7
6
  assumePendingOnError?: boolean;
@@ -3,22 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkPendingMigrations = checkPendingMigrations;
4
4
  exports.runMigrations = runMigrations;
5
5
  const typeorm_1 = require("../config/typeorm");
6
+ async function getMigrationContext(dataSource) {
7
+ const hasPending = await dataSource.showMigrations();
8
+ const tables = await dataSource.query((0, typeorm_1.isSqliteDriver)(dataSource.options.type)
9
+ ? "SELECT name FROM sqlite_master WHERE type='table' AND name NOT IN ('migrations', 'sqlite_sequence')"
10
+ : "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name != 'migrations'");
11
+ return {
12
+ hasPending,
13
+ isEmpty: tables.length === 0,
14
+ };
15
+ }
6
16
  async function checkPendingMigrations(options = {}) {
7
17
  const dataSource = (0, typeorm_1.createDataSource)();
8
18
  try {
9
19
  await dataSource.initialize();
10
- const hasPending = await dataSource.showMigrations();
11
- const tables = await dataSource.query((0, typeorm_1.isSqliteDriver)(dataSource.options.type)
12
- ? "SELECT name FROM sqlite_master WHERE type='table' AND name NOT IN ('migrations', 'sqlite_sequence')"
13
- : "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name != 'migrations'");
14
- const isEmpty = tables.length === 0;
15
- const registeredMigrationNames = dataSource.migrations.map((migration) => migration.name || migration.constructor.name);
16
- const requiresBaselineBootstrap = !isEmpty &&
17
- hasPending &&
18
- registeredMigrationNames.length === 1 &&
19
- registeredMigrationNames[0]?.startsWith('BaselineSchema') === true;
20
+ const { hasPending, isEmpty } = await getMigrationContext(dataSource);
20
21
  await dataSource.destroy();
21
- return { hasPending, isEmpty, requiresBaselineBootstrap };
22
+ return { hasPending, isEmpty };
22
23
  }
23
24
  catch (err) {
24
25
  if (dataSource.isInitialized) {
@@ -28,7 +29,6 @@ async function checkPendingMigrations(options = {}) {
28
29
  return {
29
30
  hasPending: true,
30
31
  isEmpty: true,
31
- requiresBaselineBootstrap: false,
32
32
  };
33
33
  }
34
34
  const errorMessage = err instanceof Error ? err.message : String(err);
@@ -44,22 +44,9 @@ async function runMigrations(force = false) {
44
44
  await dataSource.dropDatabase();
45
45
  console.log('Schema dropped successfully.');
46
46
  }
47
- const hasPending = await dataSource.showMigrations();
48
- const tables = await dataSource.query((0, typeorm_1.isSqliteDriver)(dataSource.options.type)
49
- ? "SELECT name FROM sqlite_master WHERE type='table' AND name NOT IN ('migrations', 'sqlite_sequence')"
50
- : "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name != 'migrations'");
51
- const isEmpty = tables.length === 0;
52
- const registeredMigrationNames = dataSource.migrations.map((migration) => migration.name || migration.constructor.name);
53
- const shouldBootstrapBaseline = !force &&
54
- !isEmpty &&
55
- hasPending &&
56
- registeredMigrationNames.length === 1 &&
57
- registeredMigrationNames[0]?.startsWith('BaselineSchema') === true;
47
+ await getMigrationContext(dataSource);
58
48
  console.log('Running database migrations...');
59
- const result = await dataSource.runMigrations(shouldBootstrapBaseline ? { fake: true } : undefined);
60
- if (shouldBootstrapBaseline) {
61
- console.log('Existing database schema detected without recorded baseline migration. Recorded the baseline migration without changing the schema.');
62
- }
49
+ const result = await dataSource.runMigrations();
63
50
  if (result.length > 0) {
64
51
  console.log(`Successfully executed ${result.length} migrations.`);
65
52
  }
package/dist/main.js CHANGED
@@ -26,7 +26,7 @@ async function ensureDatabaseIsReadyForStartup() {
26
26
  }
27
27
  throw new Error([
28
28
  'Pending database migrations were detected.',
29
- 'Run `npm run migration:run` locally or `docker compose run --rm api dist/cli/index.js migrate --yes` in the Docker stack, then start the server again.',
29
+ 'Run `agent-orchestrator setup` or `agent-orchestrator migrate --yes` for packaged installs, `npm run migration:run` for local source development, or `docker compose run --rm api dist/cli/index.js migrate --yes` in the Docker stack, then start the server again.',
30
30
  ].join(' '));
31
31
  }
32
32
  async function bootstrap() {
@@ -1,6 +1,7 @@
1
1
  import { MigrationInterface, QueryRunner } from 'typeorm';
2
- export declare class BaselineSchema1775260737095 implements MigrationInterface {
2
+ export declare class InitialSchema1775266979821 implements MigrationInterface {
3
3
  name: string;
4
+ private execute;
4
5
  up(queryRunner: QueryRunner): Promise<void>;
5
6
  down(queryRunner: QueryRunner): Promise<void>;
6
7
  }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InitialSchema1775266979821 = void 0;
4
+ const migration_sql_utils_1 = require("../database/migration-sql.utils");
5
+ class InitialSchema1775266979821 {
6
+ name = 'InitialSchema1775266979821';
7
+ async execute(queryRunner, sql) {
8
+ await queryRunner.query((0, migration_sql_utils_1.normalizeMigrationSqlForDriver)(queryRunner.connection.options.type, sql));
9
+ }
10
+ async up(queryRunner) {
11
+ await this.execute(queryRunner, `CREATE TABLE "users" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "last_name" varchar NOT NULL, "email" varchar NOT NULL, "password" varchar, "role" varchar NOT NULL DEFAULT ('user'), "avatar" varchar NOT NULL DEFAULT ('avatar-01'), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"))`);
12
+ await this.execute(queryRunner, `CREATE TABLE "providers" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_d735474e539e674ba3702eddc44" UNIQUE ("name"))`);
13
+ await this.execute(queryRunner, `CREATE TABLE "models" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "providerId" varchar, CONSTRAINT "FK_2ce64b8d909a4385f26bcd363b3" FOREIGN KEY ("providerId") REFERENCES "providers" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
14
+ await this.execute(queryRunner, `CREATE INDEX "IDX_2ce64b8d909a4385f26bcd363b" ON "models" ("providerId") `);
15
+ await this.execute(queryRunner, `CREATE TABLE "agents" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "systemInstructions" text, "role" text, "status" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "providerId" varchar, "modelId" varchar, CONSTRAINT "UQ_1ea6b2ce044724d3254d19ab922" UNIQUE ("name"), CONSTRAINT "FK_e927e225423f493fb58dc146cf0" FOREIGN KEY ("providerId") REFERENCES "providers" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_ef998451a458221d3c409b37923" FOREIGN KEY ("modelId") REFERENCES "models" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`);
16
+ await this.execute(queryRunner, `CREATE INDEX "IDX_e927e225423f493fb58dc146cf" ON "agents" ("providerId") `);
17
+ await this.execute(queryRunner, `CREATE INDEX "IDX_ef998451a458221d3c409b3792" ON "agents" ("modelId") `);
18
+ await this.execute(queryRunner, `CREATE TABLE "projects" ("id" varchar PRIMARY KEY NOT NULL, "title" varchar NOT NULL, "description" text NOT NULL, "status" varchar CHECK( "status" IN ('planning','active','on_hold','completed','archived') ) NOT NULL DEFAULT ('planning'), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "ownerAgentId" varchar, CONSTRAINT "FK_6cb68059ab1223de4f03f9a7268" FOREIGN KEY ("ownerAgentId") REFERENCES "agents" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`);
19
+ await this.execute(queryRunner, `CREATE INDEX "IDX_6cb68059ab1223de4f03f9a726" ON "projects" ("ownerAgentId") `);
20
+ await this.execute(queryRunner, `CREATE INDEX "IDX_a27865a7be17886e3088f4a650" ON "projects" ("status") `);
21
+ await this.execute(queryRunner, `CREATE TABLE "project_members" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL DEFAULT ('member'), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "projectId" varchar, "userId" varchar, CONSTRAINT "UQ_326b2a901eb18ac24eabc9b0581" UNIQUE ("projectId", "userId"), CONSTRAINT "FK_d19892d8f03928e5bfc7313780c" FOREIGN KEY ("projectId") REFERENCES "projects" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_08d1346ff91abba68e5a637cfdb" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
22
+ await this.execute(queryRunner, `CREATE INDEX "IDX_d19892d8f03928e5bfc7313780" ON "project_members" ("projectId") `);
23
+ await this.execute(queryRunner, `CREATE INDEX "IDX_08d1346ff91abba68e5a637cfd" ON "project_members" ("userId") `);
24
+ await this.execute(queryRunner, `CREATE TABLE "tasks" ("id" varchar PRIMARY KEY NOT NULL, "title" varchar NOT NULL, "description" text NOT NULL, "status" varchar CHECK( "status" IN ('backlog','in-progress','review','done','archived') ) NOT NULL DEFAULT ('backlog'), "priority" varchar CHECK( "priority" IN ('0','1','2','3') ) NOT NULL DEFAULT (2), "cost_estimate" float NOT NULL DEFAULT (0), "llm_latency" integer NOT NULL DEFAULT (0), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "assigneeId" varchar, "projectId" varchar NOT NULL, CONSTRAINT "FK_9a16d2c86252529f622fa53f1e3" FOREIGN KEY ("assigneeId") REFERENCES "agents" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_e08fca67ca8966e6b9914bf2956" FOREIGN KEY ("projectId") REFERENCES "projects" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
25
+ await this.execute(queryRunner, `CREATE INDEX "IDX_9a16d2c86252529f622fa53f1e" ON "tasks" ("assigneeId") `);
26
+ await this.execute(queryRunner, `CREATE INDEX "IDX_7a097552fe4fba313996835706" ON "tasks" ("projectId", "updatedAt") `);
27
+ await this.execute(queryRunner, `CREATE INDEX "IDX_4105de371d2c7ca094a830e5cd" ON "tasks" ("projectId", "status", "updatedAt") `);
28
+ await this.execute(queryRunner, `CREATE TABLE "task_comments" ("id" varchar PRIMARY KEY NOT NULL, "content" text NOT NULL, "authorType" varchar CHECK( "authorType" IN ('user','agent') ) NOT NULL, "artifacts" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "taskId" varchar NOT NULL, "authorUserId" varchar, "authorAgentId" varchar, CONSTRAINT "FK_ba265816ca1d93f51083e06c520" FOREIGN KEY ("taskId") REFERENCES "tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_70a6d3ec52a15e0ff43d4ad3532" FOREIGN KEY ("authorUserId") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_c2d5d4e5e1e33278318fa6b2b05" FOREIGN KEY ("authorAgentId") REFERENCES "agents" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`);
29
+ await this.execute(queryRunner, `CREATE INDEX "IDX_70a6d3ec52a15e0ff43d4ad353" ON "task_comments" ("authorUserId") `);
30
+ await this.execute(queryRunner, `CREATE INDEX "IDX_c2d5d4e5e1e33278318fa6b2b0" ON "task_comments" ("authorAgentId") `);
31
+ await this.execute(queryRunner, `CREATE INDEX "IDX_0a2203f600be90963a165d1432" ON "task_comments" ("taskId", "createdAt") `);
32
+ await this.execute(queryRunner, `CREATE TABLE "recurrent_tasks" ("id" varchar PRIMARY KEY NOT NULL, "title" varchar NOT NULL, "description" text NOT NULL, "status" varchar CHECK( "status" IN ('active','paused','error') ) NOT NULL DEFAULT ('active'), "priority" varchar CHECK( "priority" IN ('0','1','2','3') ) NOT NULL DEFAULT (2), "cronExpression" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "assigneeId" varchar NOT NULL, "projectId" varchar, CONSTRAINT "FK_9ec101b70a5f9612b0757d87c83" FOREIGN KEY ("assigneeId") REFERENCES "agents" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_0f9f543bd40419122e69aeff006" FOREIGN KEY ("projectId") REFERENCES "projects" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
33
+ await this.execute(queryRunner, `CREATE INDEX "IDX_0f9f543bd40419122e69aeff00" ON "recurrent_tasks" ("projectId") `);
34
+ await this.execute(queryRunner, `CREATE INDEX "IDX_a03520bcf60ada1a46bf548e22" ON "recurrent_tasks" ("status") `);
35
+ await this.execute(queryRunner, `CREATE TABLE "recurrent_task_execs" ("id" varchar PRIMARY KEY NOT NULL, "status" varchar CHECK( "status" IN ('running','success','failure','canceled') ) NOT NULL DEFAULT ('running'), "result" text, "latencyMs" integer, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "recurrentTaskId" varchar NOT NULL, CONSTRAINT "FK_f5bb7be33ddb87ac0f04807b4ab" FOREIGN KEY ("recurrentTaskId") REFERENCES "recurrent_tasks" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
36
+ await this.execute(queryRunner, `CREATE INDEX "IDX_f5bb7be33ddb87ac0f04807b4a" ON "recurrent_task_execs" ("recurrentTaskId") `);
37
+ await this.execute(queryRunner, `CREATE TABLE "artifacts" ("id" varchar PRIMARY KEY NOT NULL, "originalName" varchar NOT NULL, "mimeType" varchar NOT NULL, "filePath" varchar NOT NULL, "metadata" text)`);
38
+ await this.execute(queryRunner, `CREATE TABLE "refresh_tokens" ("id" varchar PRIMARY KEY NOT NULL, "userId" varchar NOT NULL, "token" text NOT NULL, "issuedAt" datetime NOT NULL DEFAULT (datetime('now')), "expiresAt" datetime NOT NULL, "absoluteExpiry" datetime NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "revokedAt" datetime, CONSTRAINT "FK_610102b60fea1455310ccd299de" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`);
39
+ await this.execute(queryRunner, `CREATE INDEX "IDX_070d648bde98d061fd6e9d176d" ON "refresh_tokens" ("userId", "revokedAt") `);
40
+ await this.execute(queryRunner, `CREATE INDEX "IDX_ec511b89bba27b211e32a2a12f" ON "refresh_tokens" ("userId", "expiresAt") `);
41
+ }
42
+ async down(queryRunner) {
43
+ await this.execute(queryRunner, `DROP TABLE "refresh_tokens"`);
44
+ await this.execute(queryRunner, `DROP TABLE "artifacts"`);
45
+ await this.execute(queryRunner, `DROP TABLE "recurrent_task_execs"`);
46
+ await this.execute(queryRunner, `DROP TABLE "recurrent_tasks"`);
47
+ await this.execute(queryRunner, `DROP TABLE "task_comments"`);
48
+ await this.execute(queryRunner, `DROP TABLE "tasks"`);
49
+ await this.execute(queryRunner, `DROP TABLE "project_members"`);
50
+ await this.execute(queryRunner, `DROP TABLE "projects"`);
51
+ await this.execute(queryRunner, `DROP TABLE "agents"`);
52
+ await this.execute(queryRunner, `DROP TABLE "models"`);
53
+ await this.execute(queryRunner, `DROP TABLE "providers"`);
54
+ await this.execute(queryRunner, `DROP TABLE "users"`);
55
+ }
56
+ }
57
+ exports.InitialSchema1775266979821 = InitialSchema1775266979821;
@@ -0,0 +1,8 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+ export declare class SeedDefaultProvidersAndModels1775268200000 implements MigrationInterface {
3
+ name: string;
4
+ private escapeSqlLiteral;
5
+ private getIdRow;
6
+ up(queryRunner: QueryRunner): Promise<void>;
7
+ down(queryRunner: QueryRunner): Promise<void>;
8
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeedDefaultProvidersAndModels1775268200000 = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const default_provider_models_1 = require("../agents/default-provider-models");
6
+ class SeedDefaultProvidersAndModels1775268200000 {
7
+ name = 'SeedDefaultProvidersAndModels1775268200000';
8
+ escapeSqlLiteral(value) {
9
+ return `'${value.replace(/'/g, "''")}'`;
10
+ }
11
+ async getIdRow(queryRunner, sql) {
12
+ const rows = (await queryRunner.query(sql));
13
+ return rows[0] ?? null;
14
+ }
15
+ async up(queryRunner) {
16
+ for (const seed of default_provider_models_1.DEFAULT_PROVIDER_MODELS) {
17
+ const existingProvider = await this.getIdRow(queryRunner, `SELECT "id" FROM "providers" WHERE "name" = ${this.escapeSqlLiteral(seed.providerName)}`);
18
+ const providerId = existingProvider?.id ?? (0, crypto_1.randomUUID)();
19
+ if (!existingProvider) {
20
+ await queryRunner.query(`INSERT INTO "providers" ("id", "name") VALUES (${this.escapeSqlLiteral(providerId)}, ${this.escapeSqlLiteral(seed.providerName)})`);
21
+ }
22
+ for (const modelName of seed.models) {
23
+ const existingModel = await this.getIdRow(queryRunner, `SELECT "id" FROM "models" WHERE "name" = ${this.escapeSqlLiteral(modelName)} AND "providerId" = ${this.escapeSqlLiteral(providerId)}`);
24
+ if (existingModel) {
25
+ continue;
26
+ }
27
+ await queryRunner.query(`INSERT INTO "models" ("id", "name", "providerId") VALUES (${this.escapeSqlLiteral((0, crypto_1.randomUUID)())}, ${this.escapeSqlLiteral(modelName)}, ${this.escapeSqlLiteral(providerId)})`);
28
+ }
29
+ }
30
+ }
31
+ async down(queryRunner) {
32
+ const providerNames = default_provider_models_1.DEFAULT_PROVIDER_MODELS.map((seed) => seed.providerName);
33
+ const modelNames = default_provider_models_1.DEFAULT_PROVIDER_MODELS.flatMap((seed) => seed.models);
34
+ const providerNamesList = providerNames.map((name) => this.escapeSqlLiteral(name));
35
+ const modelNamesList = modelNames.map((name) => this.escapeSqlLiteral(name));
36
+ const providers = (await queryRunner.query(`SELECT "id" FROM "providers" WHERE "name" IN (${providerNamesList.join(', ')})`));
37
+ const providerIds = providers.map((provider) => provider.id);
38
+ const providerIdsList = providerIds.map((id) => this.escapeSqlLiteral(id));
39
+ if (providerIds.length > 0) {
40
+ await queryRunner.query(`DELETE FROM "models" WHERE "providerId" IN (${providerIdsList.join(', ')}) AND "name" IN (${modelNamesList.join(', ')})`);
41
+ }
42
+ await queryRunner.query(`DELETE FROM "providers" WHERE "name" IN (${providerNamesList.join(', ')})`);
43
+ }
44
+ }
45
+ exports.SeedDefaultProvidersAndModels1775268200000 = SeedDefaultProvidersAndModels1775268200000;
@@ -0,0 +1,9 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+ export declare class BackfillDefaultModelProviderIds1775269500000 implements MigrationInterface {
3
+ name: string;
4
+ private escapeSqlLiteral;
5
+ private isIdRow;
6
+ private getProviderIdsByName;
7
+ up(queryRunner: QueryRunner): Promise<void>;
8
+ down(queryRunner: QueryRunner): Promise<void>;
9
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BackfillDefaultModelProviderIds1775269500000 = void 0;
4
+ const default_provider_models_1 = require("../agents/default-provider-models");
5
+ class BackfillDefaultModelProviderIds1775269500000 {
6
+ name = 'BackfillDefaultModelProviderIds1775269500000';
7
+ escapeSqlLiteral(value) {
8
+ return `'${value.replace(/'/g, "''")}'`;
9
+ }
10
+ isIdRow(row) {
11
+ return (typeof row === 'object' &&
12
+ row !== null &&
13
+ 'id' in row &&
14
+ typeof row.id === 'string');
15
+ }
16
+ async getProviderIdsByName(queryRunner, providerName) {
17
+ const rows = await queryRunner.query(`SELECT "id" FROM "providers" WHERE "name" = ${this.escapeSqlLiteral(providerName)}`);
18
+ if (!Array.isArray(rows)) {
19
+ return [];
20
+ }
21
+ const providerIds = [];
22
+ for (const row of rows) {
23
+ if (this.isIdRow(row)) {
24
+ providerIds.push(row.id);
25
+ }
26
+ }
27
+ return providerIds;
28
+ }
29
+ async up(queryRunner) {
30
+ for (const seed of default_provider_models_1.DEFAULT_PROVIDER_MODELS) {
31
+ const [providerId] = await this.getProviderIdsByName(queryRunner, seed.providerName);
32
+ if (!providerId) {
33
+ continue;
34
+ }
35
+ const modelNames = seed.models.map((modelName) => this.escapeSqlLiteral(modelName));
36
+ await queryRunner.query(`UPDATE "models"
37
+ SET "providerId" = ${this.escapeSqlLiteral(providerId)}
38
+ WHERE "providerId" IS NULL
39
+ AND "name" IN (${modelNames.join(', ')})`);
40
+ }
41
+ }
42
+ async down(queryRunner) {
43
+ const modelNames = default_provider_models_1.DEFAULT_PROVIDER_MODELS
44
+ .flatMap((seed) => seed.models)
45
+ .map((modelName) => this.escapeSqlLiteral(modelName));
46
+ await queryRunner.query(`UPDATE "models"
47
+ SET "providerId" = NULL
48
+ WHERE "name" IN (${modelNames.join(', ')})`);
49
+ }
50
+ }
51
+ exports.BackfillDefaultModelProviderIds1775269500000 = BackfillDefaultModelProviderIds1775269500000;
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-COnpUsM8.js";import{g as t}from"./vendor-dnd-CxfOy4-Z.js";import{i as n,n as r,t as i}from"./vendor-query-DQlZ8h7P.js";import{r as a}from"./vendor-markdown-Dl_1qnne.js";import{o,t as s}from"./useNotification-DK-pV16c.js";import{t as c}from"./activity-CIlCK2jL.js";import{t as l}from"./box-CsCoq7gr.js";import{t as u}from"./brain-_N041Xks.js";import{t as d}from"./check-DgCfni6J.js";import{t as f}from"./chevron-down-g12gVicW.js";import{n as p,t as m}from"./sparkles-DfBrsYtR.js";import{i as h,r as g,t as _}from"./providers-CVpZdX9Z.js";import{t as v}from"./layers-DmKVnI8y.js";import{t as y}from"./send-CaBqcm_I.js";import{t as b}from"./trash-2-Dj3ML80c.js";import{i as x,n as S,t as C}from"./ConfirmDialog-CAb4bA6D.js";import{n as w,t as T}from"./vendor-motion-CYM51UOz.js";import{b as E,c as D,g as O,m as k,p as A,y as j}from"./index-tztXTZhU.js";import{t as M}from"./MarkdownField-CYto7bYs.js";import{a as N,c as P,o as F,s as I}from"./vendor-forms-BhyC9zH1.js";import"./tasks-9h6EhJqU.js";var L=o(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),R=o(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),z=o(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),B=o(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),V=o(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),H=o(`pen`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),ee=o(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),U=o(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),W=e(t(),1),G=a(),K=({id:e,name:t,expertise:n,model:r,status:i,metricLabel:a,metricValue:o,onProbe:s,onConfigure:l,onDelete:d,onActivate:f})=>{let[p,h]=(0,W.useState)(!1),_=(0,W.useRef)(null),v={active:{color:`text-secondary`,bg:`bg-secondary/10`,dot:`bg-secondary`,animate:`animate-pulse`,icon:u},idle:{color:`text-on-surface-variant`,bg:`bg-on-surface-variant/10`,dot:`bg-on-surface-variant`,animate:``,icon:m},updating:{color:`text-primary`,bg:`bg-primary/10`,dot:`bg-primary`,animate:`animate-ping`,icon:c},inactive:{color:`text-error/60`,bg:`bg-error/5`,dot:`bg-error/40`,animate:``,icon:L}}[i];return(0,W.useEffect)(()=>{let e=e=>{_.current&&!_.current.contains(e.target)&&h(!1)};return p&&document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]),(0,G.jsxs)(`div`,{className:`group relative bg-surface-container-low rounded-xl p-6 transition-all duration-300 hover:translate-y-[-4px] shadow-lg border border-transparent hover:border-outline-variant/20`,children:[(0,G.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1.5 px-2.5 py-1 rounded-full ${v.bg} ${v.color} text-[10px] font-bold tracking-widest uppercase`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${v.dot} ${v.animate}`}),i]}),(0,G.jsxs)(`div`,{className:`flex gap-5`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-xl bg-surface-container-high flex items-center justify-center ring-1 ring-outline-variant/30 group-hover:ring-primary/50 transition-all`,children:(0,G.jsx)(v.icon,{className:`text-3xl ${v.color}`,size:32})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-bold font-headline text-white`,children:t}),(0,G.jsx)(`p`,{className:`text-on-surface-variant text-xs mt-1`,children:n}),(0,G.jsxs)(`div`,{className:`mt-4 flex items-center gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-on-surface-variant/60 uppercase tracking-tighter`,children:`Model`}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:r})]}),(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-on-surface-variant/60 uppercase tracking-tighter`,children:a}),(0,G.jsx)(`span`,{className:`text-xs font-semibold ${v.color}`,children:o})]})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),l?.(e)},className:`flex-1 py-2 rounded bg-surface-container-high text-xs font-semibold text-on-surface hover:bg-surface-container-highest transition-colors`,children:`Configure`}),(0,G.jsxs)(`div`,{className:`relative`,ref:_,children:[(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(!p)},"aria-label":`Agent actions menu`,className:`px-3 py-2 rounded bg-surface-container-high text-on-surface-variant hover:text-white transition-colors h-full ${p?`bg-surface-container-highest text-white`:``}`,children:(0,G.jsx)(g,{size:16,"aria-hidden":`true`})}),p&&(0,G.jsxs)(`div`,{className:`absolute bottom-full right-0 mb-2 w-48 bg-surface-container-highest rounded-lg shadow-2xl py-2 ring-1 ring-outline-variant/20 animate-in fade-in slide-in-from-bottom-2 duration-200 z-20`,children:[(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),s?.(e),h(!1)},disabled:i===`inactive`,className:`w-full flex items-center gap-3 px-4 py-2.5 text-xs text-on-surface-variant hover:text-white hover:bg-primary/10 transition-colors group disabled:opacity-30 disabled:grayscale disabled:cursor-not-allowed`,children:[(0,G.jsx)(U,{size:14,className:`group-hover:text-primary`}),`Probe Agent`]}),(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),l?.(e),h(!1)},className:`w-full flex items-center gap-3 px-4 py-2.5 text-xs text-on-surface-variant hover:text-white hover:bg-white/5 transition-colors`,children:[(0,G.jsx)(k,{size:14}),`Control Matrix`]}),(0,G.jsx)(`div`,{className:`my-1 border-t border-outline-variant/10`}),i===`inactive`?(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),f?.(e),h(!1)},className:`w-full flex items-center gap-3 px-4 py-2.5 text-xs text-secondary/60 hover:text-secondary hover:bg-secondary/10 transition-colors`,children:[(0,G.jsx)(u,{size:14}),`Activate Node`]}):(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),d?.(e),h(!1)},className:`w-full flex items-center gap-3 px-4 py-2.5 text-xs text-error/60 hover:text-error hover:bg-error/10 transition-colors`,children:[(0,G.jsx)(b,{size:14}),`Decommission`]})]})]})]})]})},q=({isOpen:e,onClose:t,onUpdated:n,agent:r})=>{let{notifyError:i,notifySuccess:a}=s(),[o,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),[g,v]=(0,W.useState)(!1),[y,b]=(0,W.useState)(``),[x,S]=(0,W.useState)(``),[C,w]=(0,W.useState)(``),[T,E]=(0,W.useState)(``),[O,k]=(0,W.useState)([]),[j,N]=(0,W.useState)(``),[P,F]=(0,W.useState)([]),[I,L]=(0,W.useState)(``);(0,W.useEffect)(()=>{e&&r&&(b(r.name||``),S(r.role||``),w(r.description||``),E(r.systemInstructions||``),L(r.model?.id||``),N(r.provider?.id??r.model?.provider?.id??``))},[e,r]),(0,W.useEffect)(()=>{e&&(async()=>{try{m(!0);let{data:e}=await _.findAll();k(e)}catch{}finally{m(!1)}})()},[e]),(0,W.useEffect)(()=>{if(!j){F([]);return}(async()=>{try{u(!0);let{data:e}=await _.findModels(j);F(e),I&&!e.find(e=>e.id===I)&&L(e[0]?.id??``)}catch{F([])}finally{u(!1)}})()},[j,I]);let R=()=>{r?.id&&(navigator.clipboard.writeText(r.id),v(!0),a(`Copied`,`Agent ID copied to clipboard`),setTimeout(()=>v(!1),2e3))},z=async()=>{if(r?.id)try{c(!0),await D.update(r.id,{name:y,role:x,description:C,systemInstructions:T,providerId:j||void 0,modelId:I||void 0}),n?.(),t()}catch{i(`Update Failed`,`An error occurred while saving the configuration.`)}finally{c(!1)}};return(0,W.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()};return e&&window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,G.jsxs)(`div`,{className:`fixed inset-y-0 right-0 w-[420px] bg-surface-container-low shadow-2xl z-[60] flex flex-col ring-1 ring-outline-variant/10 animate-in slide-in-from-right duration-300`,children:[(0,G.jsxs)(`div`,{className:`p-6 border-b border-outline-variant/10 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-bold font-headline text-white`,children:`Agent Configuration`}),(0,G.jsxs)(`p`,{className:`text-[10px] text-on-surface-variant uppercase tracking-widest mt-0.5`,children:[`Edit Profile: `,r?.name||`Logic Specialist`]})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-on-surface-variant hover:text-white transition-colors`,children:(0,G.jsx)(A,{size:20})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6 space-y-8 scrollbar-hide`,children:[(0,G.jsxs)(`section`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsxs)(`div`,{className:`relative w-20 h-20 rounded-2xl bg-surface-container-high ring-1 ring-outline-variant/50 flex items-center justify-center overflow-hidden`,children:[(0,G.jsx)(`span`,{className:`text-4xl text-secondary`,children:`🧠`}),(0,G.jsx)(`button`,{className:`absolute inset-0 bg-black/60 opacity-0 hover:opacity-100 transition-opacity flex items-center justify-center text-white`,children:(0,G.jsx)(H,{size:16})})]}),(0,G.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Agent Name`}),(0,G.jsx)(`input`,{className:`w-full bg-surface-container-lowest border-none rounded-md text-sm text-on-surface focus:ring-1 focus:ring-primary h-9 px-3`,type:`text`,value:y,onChange:e=>b(e.target.value)})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Agent ID`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{className:`flex-1 bg-surface-container-lowest/50 border-none rounded-md text-[10px] font-mono text-on-surface-variant focus:ring-0 h-8 px-3 cursor-default`,type:`text`,value:r?.id||``,readOnly:!0}),(0,G.jsx)(`button`,{onClick:R,className:`p-1.5 rounded bg-surface-container-highest hover:bg-surface-container-highest/80 text-on-surface-variant transition-colors flex items-center justify-center aspect-square h-8`,title:`Copy ID`,children:g?(0,G.jsx)(d,{size:14,className:`text-primary`}):(0,G.jsx)(h,{size:14})})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Role`}),(0,G.jsx)(`input`,{className:`w-full bg-surface-container-lowest border-none rounded-md text-sm text-on-surface focus:ring-1 focus:ring-primary h-9 px-3 placeholder:text-on-surface-variant/30`,type:`text`,placeholder:`e.g. Researcher, Developer...`,value:x,onChange:e=>S(e.target.value)})]})]}),(0,G.jsx)(M,{label:`Description`,value:C,onChange:w,placeholder:`Detailed agent profile...`,height:`h-32`,maxLength:1e3}),(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Provider`}),p&&(0,G.jsx)(V,{size:12,className:`animate-spin text-primary`})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{className:`w-full bg-surface-container-lowest border-none rounded-md text-sm text-on-surface focus:ring-1 focus:ring-primary h-11 appearance-none px-4 disabled:opacity-50`,value:j,onChange:e=>N(e.target.value),disabled:p,children:[(0,G.jsx)(`option`,{value:``,children:`Select a provider...`}),O.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(f,{className:`absolute right-3 top-3 pointer-events-none text-on-surface-variant/60`,size:18})]})]}),(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Model Engine`}),l&&(0,G.jsx)(V,{size:12,className:`animate-spin text-primary`})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{className:`w-full bg-surface-container-lowest border-none rounded-md text-sm text-on-surface focus:ring-1 focus:ring-primary h-11 appearance-none px-4 disabled:opacity-50`,value:I,onChange:e=>L(e.target.value),disabled:l||P.length===0,children:[P.length===0&&!l&&(0,G.jsx)(`option`,{value:``,children:`No models available for this provider`}),P.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(f,{className:`absolute right-3 top-3 pointer-events-none text-on-surface-variant/60`,size:18})]})]}),(0,G.jsxs)(`section`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-bold uppercase tracking-tight text-on-surface-variant/60`,children:`Personality Matrix`}),(0,G.jsx)(`span`,{className:`text-[10px] text-tertiary px-2 py-0.5 rounded bg-tertiary/10`,children:`AI Optimized`})]}),(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-on-surface-variant`,children:`Creativity`}),(0,G.jsx)(`span`,{className:`text-primary font-mono font-bold`,children:`0.42`})]}),(0,G.jsx)(`input`,{type:`range`,className:`w-full accent-primary h-1 bg-surface-container-highest rounded-full appearance-none cursor-pointer`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-on-surface-variant`,children:`Strictness`}),(0,G.jsx)(`span`,{className:`text-secondary font-mono font-bold`,children:`0.85`})]}),(0,G.jsx)(`input`,{type:`range`,className:`w-full accent-secondary h-1 bg-surface-container-highest rounded-full appearance-none cursor-pointer`})]})]})]}),(0,G.jsx)(M,{label:`System Instructions`,value:T,onChange:E,placeholder:`Define operational logic...`,height:`h-64`,maxLength:2e3})]}),(0,G.jsxs)(`div`,{className:`p-6 bg-surface-container-high border-t border-outline-variant/10 flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>{z()},disabled:o,className:`flex-1 bg-primary text-on-primary py-2.5 rounded font-bold text-sm shadow-lg shadow-primary/10 hover:shadow-primary/20 transition-all flex items-center justify-center gap-2 active:scale-95 disabled:opacity-50`,children:o?(0,G.jsx)(`span`,{className:`w-4 h-4 border-2 border-on-primary/30 border-t-on-primary rounded-full animate-spin`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d,{size:16}),`Save Changes`]})}),(0,G.jsx)(`button`,{onClick:t,className:`px-4 py-2.5 rounded border border-outline-variant text-on-surface-variant hover:text-white transition-all`,children:`Reset`})]})]}):null},J={name:``,role:``,description:``,providerId:``,modelId:``,instructions:S},te=[{id:1,title:`Essential Config`,subtitle:`ID, ROLE & MODEL`},{id:2,title:`Intelligence Tuning`,subtitle:`COGNITIVE MATRIX`},{id:3,title:`Instructions`,subtitle:`KNOWLEDGE BASE`}],Y=({isOpen:e,onClose:t,onCreated:a})=>{let o=n(),{notifyApiError:c,notifyError:u,notifySuccess:d}=s(),[h,g]=(0,W.useState)(1),y=(0,W.useId)(),b=(0,W.useId)(),S=(0,W.useId)(),C=(0,W.useId)(),E=(0,W.useId)(),O=(0,W.useId)(),k=(0,W.useId)(),A=(0,W.useId)(),{control:j,formState:{errors:L},handleSubmit:R,register:z,reset:B,setValue:V}=I({resolver:N(x),defaultValues:J,mode:`onBlur`}),H=P({control:j,name:`providerId`}),U=P({control:j,name:`modelId`}),K=r({queryKey:[`providers`],enabled:e,queryFn:async()=>(await _.findAll()).data}),q=r({queryKey:[`provider-models`,H],enabled:e&&!!H,queryFn:async()=>(await _.findModels(H)).data});(0,W.useEffect)(()=>{if(!e){B(J);return}let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t,B]),(0,W.useEffect)(()=>{e&&K.error&&c(K.error,`Providers Load Failed`)},[e,c,K.error]),(0,W.useEffect)(()=>{e&&q.error&&c(q.error,`Models Load Failed`)},[e,q.error,c]);let Y=(0,W.useMemo)(()=>K.data??[],[K.data]),X=(0,W.useMemo)(()=>q.data??[],[q.data]);(0,W.useEffect)(()=>{if(e){if(Y.length===0){H&&V(`providerId`,``,{shouldDirty:!1,shouldValidate:!0});return}(!H||!Y.some(e=>e.id===H))&&V(`providerId`,Y[0].id,{shouldDirty:!1,shouldValidate:!0})}},[e,H,Y,V]),(0,W.useEffect)(()=>{if(e){if(!H){U&&V(`modelId`,``,{shouldDirty:!1,shouldValidate:!0});return}if(X.length===0){U&&V(`modelId`,``,{shouldDirty:!1,shouldValidate:!0});return}(!U||!X.some(e=>e.id===U))&&V(`modelId`,X[0].id,{shouldDirty:!1,shouldValidate:!0})}},[X,e,U,H,V]);let Z=i({mutationFn:async e=>(await D.create({name:e.name,role:e.role,description:e.description,systemInstructions:e.instructions,providerId:e.providerId,modelId:e.modelId,status:`active`}),e),onSuccess:e=>{o.invalidateQueries({queryKey:[`agents`]}),d(`Agent Deployed`,`Successfully commissioned ${e.name} into the fleet.`),a?.(),t(),B(J),g(1)},onError:e=>{c(e,`Deployment Failed`)}}),Q=Z.isPending,$=K.isPending||q.isPending,ne=R(async e=>{await Z.mutateAsync(e)},()=>{u(`Validation Error`,`Please review the highlighted fields before deploying the agent.`)}),re=()=>{Q||(g(1),t())};return e?(0,G.jsx)(w,{children:(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4 md:p-8`,children:[(0,G.jsx)(T.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:re,className:`absolute inset-0 bg-surface/80 backdrop-blur-xl`,"aria-hidden":`true`}),(0,G.jsxs)(T.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},role:`dialog`,"aria-modal":`true`,"aria-labelledby":y,"aria-describedby":b,"aria-busy":Q||$,className:`relative w-full max-w-5xl h-full max-h-[850px] bg-surface-container-low rounded-2xl shadow-2xl overflow-hidden flex flex-col ring-1 ring-outline-variant/10`,children:[(0,G.jsxs)(`div`,{className:`px-8 py-6 border-b border-outline-variant/10 flex items-center justify-between bg-surface-container-low/50 backdrop-blur-md sticky top-0 z-10`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{id:y,className:`text-2xl font-black font-headline text-white tracking-tight`,children:`Create New Agent`}),(0,G.jsx)(`p`,{id:b,className:`text-sm text-on-surface-variant/80 mt-1`,children:`Configure a specialized AI persona to handle specific nodes in your automation flows.`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:re,disabled:Q,className:`px-6 py-2.5 rounded-md text-sm font-bold text-on-surface-variant hover:text-white transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,onClick:ne,disabled:Q||Y.length===0||X.length===0,className:`px-8 py-2.5 rounded-md bg-primary text-on-primary text-sm font-bold shadow-lg shadow-primary/20 hover:scale-[1.02] active:scale-[0.98] transition-all disabled:opacity-50 disabled:grayscale disabled:cursor-not-allowed disabled:hover:scale-100`,children:Q?`Deploying...`:`Deploy Agent`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`w-72 bg-surface-container-low/30 border-r border-outline-variant/5 p-8 flex flex-col gap-10`,children:[(0,G.jsx)(`div`,{className:`space-y-8`,children:te.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`flex gap-4 group cursor-pointer text-left w-full`,onClick:()=>g(e.id),"aria-pressed":h===e.id,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center text-[10px] font-black transition-all ${h===e.id?`bg-secondary text-surface`:`bg-surface-container-highest text-on-surface-variant`}`,children:e.id.toString().padStart(2,`0`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`text-xs font-bold font-headline transition-colors ${h===e.id?`text-white`:`text-on-surface-variant`}`,children:e.title}),(0,G.jsx)(`p`,{className:`text-[9px] font-bold tracking-widest text-on-surface-variant/50 mt-0.5`,children:e.subtitle})]})]},e.id))}),(0,G.jsxs)(`div`,{className:`mt-auto bg-tertiary/10 rounded-xl p-5 ring-1 ring-tertiary/20 backdrop-blur-sm relative overflow-hidden group`,children:[(0,G.jsx)(`div`,{className:`absolute -right-4 -top-4 w-16 h-16 bg-tertiary/10 rounded-full blur-2xl group-hover:bg-tertiary/20 transition-all duration-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-tertiary`,children:[(0,G.jsx)(m,{size:14,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`AI Suggestion`})]}),(0,G.jsxs)(`p`,{className:`text-[11px] text-on-surface-variant leading-relaxed italic`,children:[`"Try selecting `,(0,G.jsx)(`span`,{className:`text-tertiary font-bold`,children:`Researcher`}),` role for high-depth data synthesis tasks."`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-10 space-y-12 custom-scrollbar`,children:[(0,G.jsxs)(`section`,{className:`space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-1 bg-secondary h-6 rounded-full`}),(0,G.jsx)(`h3`,{className:`text-lg font-bold font-headline text-white`,children:`Basic Configuration`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`label`,{htmlFor:`create-agent-name`,className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Agent Name`}),(0,G.jsx)(`div`,{className:`bg-surface-container-highest/30 rounded-lg p-0.5 ring-1 ring-outline-variant/10 focus-within:ring-primary/40 transition-all`,children:(0,G.jsx)(`input`,{id:`create-agent-name`,type:`text`,placeholder:`e.g. Researcher-X`,"aria-invalid":!!L.name,"aria-describedby":L.name?S:void 0,className:`w-full bg-transparent border-none text-sm text-on-surface h-10 px-3 focus:outline-none placeholder:text-on-surface-variant/30`,...z(`name`)})}),L.name&&(0,G.jsx)(`p`,{id:S,className:`text-xs text-error font-semibold`,children:L.name.message})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`label`,{htmlFor:`create-agent-role`,className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Primary Role`}),(0,G.jsx)(`div`,{className:`bg-surface-container-highest/30 rounded-lg p-0.5 ring-1 ring-outline-variant/10 focus-within:ring-primary/40 transition-all text-on-surface`,children:(0,G.jsx)(`input`,{id:`create-agent-role`,type:`text`,placeholder:`e.g. Researcher`,"aria-invalid":!!L.role,"aria-describedby":L.role?C:void 0,className:`w-full bg-transparent border-none text-sm text-on-surface h-10 px-4 focus:outline-none placeholder:text-on-surface-variant/30`,...z(`role`)})}),L.role&&(0,G.jsx)(`p`,{id:C,className:`text-xs text-error font-semibold`,children:L.role.message})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(F,{control:j,name:`description`,render:({field:e})=>(0,G.jsx)(M,{label:`Description`,value:e.value,onChange:e.onChange,placeholder:`Define what this agent aims to achieve... You can use markdown for formatting.`,height:`h-32`,maxLength:1e3})}),L.description&&(0,G.jsx)(`p`,{id:E,className:`text-xs text-error font-semibold`,children:L.description.message})]}),(0,G.jsxs)(`div`,{className:`pt-4 space-y-8 border-t border-outline-variant/10`,children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Select Provider`}),$&&(0,G.jsx)(`span`,{className:`text-[10px] text-primary animate-pulse font-bold uppercase tracking-widest`,children:`Updating...`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-4 gap-4`,children:[Y.map(e=>(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":H===e.id,onClick:()=>{H!==e.id&&(V(`providerId`,e.id,{shouldDirty:!0,shouldValidate:!0}),V(`modelId`,``,{shouldDirty:!0,shouldValidate:!1}))},className:`p-4 rounded-xl flex flex-col items-center gap-3 transition-all ${H===e.id?`bg-primary/10 ring-2 ring-primary shadow-[0_0_20px_rgba(173,198,255,0.15)]`:`bg-surface-container-highest/30 ring-1 ring-outline-variant/10 hover:bg-surface-container-highest/50`}`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-lg flex items-center justify-center transition-colors ${H===e.id?`bg-primary text-surface`:`bg-surface-container-high text-on-surface-variant`}`,children:(0,G.jsx)(l,{size:20,"aria-hidden":`true`})}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`h4`,{className:`text-xs font-black uppercase tracking-wider ${H===e.id?`text-white`:`text-on-surface-variant`}`,children:e.name})})]},e.id)),Y.length===0&&!K.isPending&&(0,G.jsxs)(`div`,{className:`col-span-4 py-8 border-2 border-dashed border-outline-variant/10 rounded-xl flex flex-col items-center justify-center text-on-surface-variant/40 gap-2`,children:[(0,G.jsx)(v,{size:24,"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest`,children:`No providers registered`})]})]}),L.providerId&&(0,G.jsx)(`p`,{id:O,className:`text-xs text-error font-semibold`,children:L.providerId.message})]}),(0,G.jsx)(w,{mode:`wait`,children:H&&(0,G.jsxs)(T.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`space-y-4 pt-4 border-t border-outline-variant/5`,children:[(0,G.jsx)(`label`,{htmlFor:`create-agent-model`,className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Model Variant Selection`}),(0,G.jsxs)(`div`,{className:`bg-surface-container-highest/30 rounded-lg p-0.5 ring-1 ring-outline-variant/10 focus-within:ring-primary/40 transition-all relative`,children:[(0,G.jsxs)(`select`,{id:`create-agent-model`,value:U,onChange:e=>V(`modelId`,e.target.value,{shouldDirty:!0,shouldValidate:!0}),"aria-invalid":!!L.modelId,"aria-describedby":L.modelId?k:void 0,className:`w-full bg-transparent border-none text-sm text-on-surface h-10 px-3 focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,disabled:!0,className:`bg-surface-container-low text-on-surface`,children:`Select a model...`}),X.map(e=>(0,G.jsx)(`option`,{value:e.id,className:`bg-surface-container-low text-on-surface`,children:e.name},e.id))]}),(0,G.jsx)(`div`,{className:`absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-on-surface-variant/60`,children:(0,G.jsx)(f,{size:18,"aria-hidden":`true`})})]}),L.modelId&&(0,G.jsx)(`p`,{id:k,className:`text-xs text-error font-semibold`,children:L.modelId.message}),X.length===0&&!q.isPending&&(0,G.jsx)(`div`,{className:`py-6 text-center bg-error/5 rounded-xl border border-error/10`,children:(0,G.jsx)(`span`,{className:`text-[10px] font-bold text-error uppercase tracking-widest opacity-60`,children:`No model variants found for this provider`})})]},H)})]})]}),(0,G.jsxs)(`section`,{className:`space-y-10`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-1 bg-primary h-6 rounded-full`}),(0,G.jsx)(`h3`,{className:`text-lg font-bold font-headline text-white`,children:`Intelligence Tuning`})]}),(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Personality Matrix`}),[{label:`Precision`,min:`0.00`,max:`1.00`,value:.72,color:`accent-secondary`},{label:`Lement`,min:`0.00`,max:`1.00`,value:.45,color:`accent-primary`},{label:`Casual`,min:`0.00`,max:`1.00`,value:.9,color:`accent-tertiary`}].map(e=>(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-[10px] font-bold tracking-tighter uppercase`,children:[(0,G.jsxs)(`span`,{className:`text-on-surface-variant/50`,children:[e.label,` (`,e.min,`)`]}),(0,G.jsx)(`span`,{className:`text-white font-mono text-xs`,children:e.value.toFixed(2)}),(0,G.jsxs)(`span`,{className:`text-on-surface-variant/50`,children:[`Creativity (`,e.max,`)`]})]}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`100`,defaultValue:e.value*100,className:`w-full h-1 bg-surface-container-highest rounded-full appearance-none cursor-pointer ${e.color}`,"aria-label":`${e.label} tuning slider`})]},e.label))]})]}),(0,G.jsxs)(`section`,{className:`space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-1 bg-tertiary h-6 rounded-full`}),(0,G.jsx)(`h3`,{className:`text-lg font-bold font-headline text-white`,children:`Operational Directives`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(F,{control:j,name:`instructions`,render:({field:e})=>(0,G.jsx)(M,{label:`System Instructions`,value:e.value,onChange:e.onChange,height:`h-64`,helperText:`Prompt Engineering Active`,maxLength:1e3})}),L.instructions&&(0,G.jsx)(`p`,{id:A,className:`text-xs text-error font-semibold`,children:L.instructions.message})]}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60`,children:`Knowledge Integration`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`border-2 border-dashed border-outline-variant/10 rounded-xl p-6 flex flex-col items-center justify-center gap-2 group cursor-pointer hover:border-primary/30 transition-all`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-surface-container-high flex items-center justify-center text-on-surface-variant group-hover:text-primary transition-colors`,children:(0,G.jsx)(p,{size:18,"aria-hidden":`true`})}),(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-on-surface-variant`,children:`Connect Repo`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`border-2 border-dashed border-outline-variant/10 rounded-xl p-6 flex flex-col items-center justify-center gap-2 group cursor-pointer hover:border-primary/30 transition-all`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-surface-container-high flex items-center justify-center text-on-surface-variant group-hover:text-primary transition-colors`,children:(0,G.jsx)(ee,{size:18,"aria-hidden":`true`})}),(0,G.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-on-surface-variant`,children:`Access Policies`})]})]})]})]})]})]})]})]})}):null},X=({isOpen:e,onClose:t,agent:n})=>{let r=`Wake up, who are you?`,[i,a]=(0,W.useState)(r),[o,s]=(0,W.useState)(``),[l,d]=(0,W.useState)(),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)(`idle`);return(0,W.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()};return e&&(window.addEventListener(`keydown`,n),s(``),d(void 0),h(`idle`),a(r)),()=>window.removeEventListener(`keydown`,n)},[e,t]),e?(0,G.jsx)(w,{children:(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,G.jsx)(T.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:t,className:`absolute inset-0 bg-surface/80 backdrop-blur-xl`}),(0,G.jsxs)(T.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:`relative w-full max-w-2xl bg-surface-container-low rounded-2xl shadow-2xl overflow-hidden flex flex-col ring-1 ring-outline-variant/10`,children:[(0,G.jsxs)(`div`,{className:`px-6 py-4 border-b border-outline-variant/10 flex items-center justify-between bg-surface-container-low/50 backdrop-blur-md`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center text-primary`,children:(0,G.jsx)(u,{size:20})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-xl font-black font-headline text-white tracking-tight`,children:[`Probe: `,n?.name]}),(0,G.jsx)(`p`,{className:`text-[10px] text-on-surface-variant uppercase tracking-widest font-bold`,children:`Neural Direct Message`})]})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-on-surface-variant hover:text-white transition-colors p-2`,children:(0,G.jsx)(A,{size:20})})]}),(0,G.jsxs)(`div`,{className:`p-6 space-y-6 max-h-[80vh] overflow-y-auto scrollbar-hide`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60 flex items-center gap-2`,children:[(0,G.jsx)(U,{size:12}),`Command Input`]}),(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Type your command...`,className:`w-full bg-surface-container-highest/30 rounded-xl p-4 text-sm text-on-surface h-32 focus:outline-none focus:ring-2 focus:ring-primary/40 transition-all resize-none border border-outline-variant/10 group-hover:border-outline-variant/30`}),(0,G.jsx)(`button`,{onClick:async()=>{if(!(!n?.id||!i.trim()))try{p(!0),h(`idle`),s(`Awaiting response from neural node...`),d(void 0);let{data:e}=await D.probe(n.id,i);s(e.content),d(e.image),h(`success`)}catch(e){console.error(`Probe failed:`,e);let t=`An unexpected error occurred during the probe.`;if(e&&typeof e==`object`&&`response`in e){let n=e;t=n.response?.data?.message||n.message||t}else e instanceof Error&&(t=e.message);s(`ERROR: ${t}`),h(`error`)}finally{p(!1)}},disabled:f||!i.trim(),className:`absolute bottom-3 right-3 p-2.5 rounded-lg bg-primary text-on-primary shadow-lg shadow-primary/20 hover:scale-[1.05] active:scale-[0.95] transition-all disabled:opacity-50 disabled:grayscale disabled:cursor-not-allowed group`,children:f?(0,G.jsx)(V,{size:18,className:`animate-spin`}):(0,G.jsx)(y,{size:18})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60 flex items-center gap-2`,children:[(0,G.jsx)(c,{size:12,className:f?`animate-pulse`:``}),`Neural Response`]}),m===`success`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-[9px] font-black text-secondary uppercase bg-secondary/10 px-2 py-0.5 rounded`,children:[(0,G.jsx)(j,{size:10}),` Sync Complete`]}),m===`error`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-[9px] font-black text-error uppercase bg-error/10 px-2 py-0.5 rounded`,children:[(0,G.jsx)(E,{size:10}),` Link Severed`]})]}),(0,G.jsx)(`div`,{className:`w-full min-h-[100px] bg-black/40 rounded-xl p-5 border border-outline-variant/5 font-mono text-sm leading-relaxed transition-all duration-500 whitespace-pre-wrap ${m===`error`?`text-error/80 border-error/20`:m===`success`?`text-secondary/90 border-secondary/20 shadow-[inset_0_0_20px_rgba(102,231,175,0.05)]`:`text-on-surface-variant/60`}`,children:o||`Enter a command and initiate the probe to see the agent response.`}),(0,G.jsx)(w,{children:l&&(0,G.jsxs)(T.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`text-[10px] font-black uppercase tracking-widest text-on-surface-variant/60 flex items-center gap-2`,children:[(0,G.jsx)(z,{size:12}),`Visual Output`]}),(0,G.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden border border-outline-variant/10 bg-surface-container-highest/20 group`,children:[(0,G.jsx)(`img`,{src:`data:image/png;base64,${l}`,alt:`Neural Output`,className:`w-full h-auto max-h-[400px] object-contain mx-auto`}),(0,G.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 p-3 bg-gradient-to-t from-black/60 to-transparent opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(`span`,{className:`text-[10px] font-bold text-white uppercase tracking-wider`,children:`Generated Content`})})]})]})})]})]}),(0,G.jsx)(`div`,{className:`px-6 py-4 bg-surface-container-high/50 border-t border-outline-variant/10 flex justify-end`,children:(0,G.jsx)(`button`,{onClick:t,className:`px-6 py-2 rounded-lg text-sm font-bold text-on-surface hover:bg-surface-container-highest transition-all`,children:`Close Terminal`})})]})]})}):null},Z=()=>{let{notifySuccess:e,notifyApiError:t}=s(),a=n(),[o,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(`grid`),{data:y=[],isLoading:b}=r({queryKey:[`agents`],queryFn:async()=>{let{data:e}=await D.findAll();return e}}),x=()=>a.invalidateQueries({queryKey:[`agents`]}),S=i({mutationFn:e=>D.delete(e),onSuccess:()=>{e(`Agent Inactivated`,`Neural node has been marked as inactive.`),g(!1),x()},onError:e=>t(e,`Operation Failed`)}),w=i({mutationFn:e=>D.update(e,{status:`active`}),onSuccess:()=>{e(`Neural Link Restored`,`The agent has been reactivated and synchronized.`),x()},onError:e=>t(e,`Activation Failed`)}),T=e=>{c(e),u(!0)},E=e=>{c(e),m(!0)},k=e=>{c(e),g(!0)},A=()=>{o&&S.mutate(o.id)},j=e=>{w.mutate(e)};return(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-4xl font-extrabold font-headline tracking-tight text-white`,children:`Agent Fleet`}),(0,G.jsxs)(`p`,{className:`text-on-surface-variant mt-2 font-body text-sm`,children:[`Commanding `,(0,G.jsx)(`span`,{className:`text-secondary font-bold`,children:y.filter(e=>e.status!==`inactive`).length}),` active neural nodes across the network.`]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>v(`grid`),"aria-label":`Grid view`,"aria-pressed":_===`grid`,className:`p-2 rounded transition-colors ${_===`grid`?`bg-surface-container-high text-white`:`text-on-surface-variant hover:text-white`}`,children:(0,G.jsx)(R,{size:20,"aria-hidden":`true`})}),(0,G.jsx)(`button`,{onClick:()=>v(`list`),"aria-label":`List view`,"aria-pressed":_===`list`,className:`p-2 rounded transition-colors ${_===`list`?`bg-surface-container-high text-white`:`text-on-surface-variant hover:text-white`}`,children:(0,G.jsx)(B,{size:20,"aria-hidden":`true`})})]})]}),b?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(V,{className:`w-12 h-12 text-primary animate-spin`})}):(0,G.jsxs)(`div`,{className:_===`grid`?`grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-6`:`flex flex-col gap-4`,children:[y.map(e=>(0,G.jsx)(`div`,{onClick:()=>T(e),className:e.status===`inactive`?`opacity-50 grayscale hover:grayscale-0 transition-all`:``,children:(0,G.jsx)(K,{id:e.id,name:e.name,expertise:e.role||`General Assistant`,model:e.model?.name||`Unknown`,status:e.status||`active`,metricLabel:`Provider`,metricValue:e.provider?.name||`Unknown`,onConfigure:()=>T(e),onProbe:()=>E(e),onDelete:()=>k(e),onActivate:()=>j(e.id)})},e.id)),(0,G.jsxs)(`div`,{onClick:()=>f(!0),className:`border-2 border-dashed border-outline-variant/30 rounded-xl p-6 flex flex-col items-center justify-center text-center group cursor-pointer hover:border-primary/50 transition-all hover:bg-primary/5`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-surface-container-low flex items-center justify-center mb-4 group-hover:scale-110 transition-transform`,children:(0,G.jsx)(O,{size:24,className:`text-primary`})}),(0,G.jsx)(`span`,{className:`text-sm font-bold font-headline text-on-surface-variant group-hover:text-on-surface`,children:`Deploy New Agent`}),(0,G.jsx)(`p`,{className:`text-xs text-on-surface-variant/60 mt-1 max-w-[200px]`,children:`Expand your fleet with specialized intelligence units.`})]})]}),(0,G.jsx)(q,{isOpen:l,onClose:()=>u(!1),onUpdated:x,agent:o},o?.id||`none`),(0,G.jsx)(X,{isOpen:p,onClose:()=>m(!1),agent:o}),(0,G.jsx)(Y,{isOpen:d,onClose:()=>f(!1),onCreated:x}),(0,G.jsx)(C,{isOpen:h,onClose:()=>g(!1),onConfirm:A,title:`Decommission Neural Node?`,message:`This will mark ${o?.name} as inactive. The agent will remain in the database but will no longer be available for automated tasks or direct neural connection.`,confirmText:`Decommission`,variant:`danger`})]})};export{Z as default};