@ai-matrx/chat 0.3.23 → 0.3.25

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 (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/agents/components/chat/ChatConversationSurface.js +2 -2
  3. package/dist/agents/components/chat/ChatRunHeader.js +3 -5
  4. package/dist/agents/components/chat/PinnedAgentsSection.js +2 -2
  5. package/dist/agents/components/context-preview/ContextCompareView.js +5 -12
  6. package/dist/agents/components/inputs/smart-input/composer/useComposerAgent.js +4 -5
  7. package/dist/agents/components/run/AgentRunnerPage.js +3 -3
  8. package/dist/agents/hooks/useAgentModelLabel.js +6 -2
  9. package/dist/agents/hooks/useAgentRunSurfaceScope.js +3 -4
  10. package/dist/agents/identity/agent-catalog-lists.d.ts +45 -0
  11. package/dist/agents/identity/agent-catalog-lists.js +128 -0
  12. package/dist/agents/identity/agent-identity.d.ts +52 -0
  13. package/dist/agents/identity/agent-identity.js +144 -0
  14. package/dist/agents/identity/run-tier-store.d.ts +15 -0
  15. package/dist/agents/identity/run-tier-store.js +23 -0
  16. package/dist/agents/redux/agent-definition/converters.js +1 -1
  17. package/dist/agents/redux/agent-definition/selectors.d.ts +612 -4581
  18. package/dist/agents/redux/agent-definition/selectors.js +6 -129
  19. package/dist/agents/redux/agent-definition/slice.d.ts +1 -0
  20. package/dist/agents/redux/agent-definition/slice.js +1 -0
  21. package/dist/agents/redux/agent-definition/thunks.d.ts +9 -205
  22. package/dist/agents/redux/agent-definition/thunks.js +34 -237
  23. package/dist/agents/redux/agent-filter/selectors.d.ts +10 -402
  24. package/dist/agents/redux/agent-filter/selectors.js +23 -45
  25. package/dist/agents/redux/agent-filter/useAgentIdsForFilter.d.ts +6 -0
  26. package/dist/agents/redux/agent-filter/useAgentIdsForFilter.js +14 -0
  27. package/dist/agents/redux/conversation-history/selectors.js +2 -3
  28. package/dist/agents/redux/execution-system/thunks/launch-agent-execution.thunk.js +2 -2
  29. package/dist/agents/redux/execution-system/thunks/load-conversation.thunk.js +2 -2
  30. package/dist/agents/redux/execution-system/thunks/run-headless-agent-json.js +2 -2
  31. package/dist/agents/redux/execution-system/utils/output-contract-guard.js +2 -1
  32. package/dist/agents/types/agent-definition.types.d.ts +8 -26
  33. package/dist/cx-chat/components/ChatMobileAgentName.js +4 -7
  34. package/dist/cx-chat/components/ChatSidebarClient.js +2 -2
  35. package/dist/cx-chat/components/agent/AgentPickerSheet.js +10 -11
  36. package/dist/cx-chat/hooks/useChatCatalogueInit.js +4 -7
  37. package/dist/cx-chat/hooks/useInstanceBootstrap.js +4 -5
  38. package/dist/host/db-types.d.ts +122 -0
  39. package/dist/window-panels/windows/agents/AgentRunWindow.js +4 -6
  40. package/dist/window-panels/windows/agents/RunControlsWindow.js +2 -4
  41. package/package.json +9 -8
  42. package/dist/agents/route/AgentListHydrator.d.ts +0 -4
  43. package/dist/agents/route/AgentListHydrator.js +0 -49
@@ -8,34 +8,25 @@ import {
8
8
  hasField
9
9
  } from "@ai-matrx/agents/field-flags";
10
10
  import {
11
- supabase
12
- } from "../../../host/db.js";
13
- import { getAgentCatalog } from "../../../host/ui-slots.js";
14
- import {
15
- runWithSessionRetry
16
- } from "../../../host/session-retry.js";
11
+ RunTierNotReadableError,
12
+ RunTierReadError,
13
+ RunTierTimeoutError
14
+ } from "@ai-matrx/agents/runtime";
15
+ import { getRunTierStore } from "../../identity/run-tier-store.js";
17
16
  import {
18
17
  pgErrorToError
19
18
  } from "@ai-matrx/data";
20
19
  import {
21
20
  agentNameTakenError
22
21
  } from "./agentNameTaken.js";
23
- import {
24
- withRetry
25
- } from "@ai-matrx/data/net";
26
22
  import {
27
23
  ConnectTimeoutError
28
24
  } from "@ai-matrx/data/net";
29
- import {
30
- readFavoriteIds
31
- } from "../../../context/sources/scopes.js";
32
25
  import {
33
26
  mergePartialAgent,
34
27
  setAgentFetchStatus,
35
28
  setAgentLoading,
36
- setAgentError,
37
- setAgentsStatus,
38
- setAgentsError
29
+ setAgentError
39
30
  } from "./slice.js";
40
31
  import {
41
32
  selectAgentReadyForExecution,
@@ -48,6 +39,15 @@ import {
48
39
  isSignedOutVisitor,
49
40
  NotAuthenticatedError
50
41
  } from "../../../host/identity.js";
42
+ function runTierFailure(agentId, e) {
43
+ if (e instanceof RunTierNotReadableError) return agentNotReadableError(agentId);
44
+ if (e instanceof RunTierTimeoutError) return new ConnectTimeoutError(e.timeoutMs);
45
+ if (e instanceof RunTierReadError && e.pgError) {
46
+ const pg = { message: e.pgError.message, code: e.pgError.code ?? "", details: e.pgError.details ?? "", hint: e.pgError.hint ?? "" };
47
+ return agentNameTakenError(pg) ?? pgErrorToError(pg);
48
+ }
49
+ return e instanceof Error ? e : new Error(String(e));
50
+ }
51
51
  class AgentToolAssignmentError extends Error {
52
52
  constructor(message) {
53
53
  super(message);
@@ -131,8 +131,6 @@ function sameStringArray(a, b) {
131
131
  function isToolAssignmentPhantom(current, base) {
132
132
  return sameStringArray(current.tools, base.tools) && current.model_id === base.model_id && current.created_by === base.created_by && current.organization_id === base.organization_id && current.is_archived === base.is_archived;
133
133
  }
134
- const AGENT_LIST_RPC_PAGE_SIZE = 100;
135
- const AGENT_SEARCH_LIMIT = 200;
136
134
  const REGISTRY_ACCESS_LEVELS = [
137
135
  "owner",
138
136
  "admin",
@@ -145,124 +143,6 @@ function toRegistryAccessLevel(value) {
145
143
  (level) => level === value
146
144
  ) ?? null;
147
145
  }
148
- function mergeAgentSummaries(dispatch, rows) {
149
- for (const row of rows) {
150
- dispatch(
151
- mergePartialAgent({
152
- id: row.id,
153
- name: row.name ?? void 0,
154
- description: row.description,
155
- category: row.category,
156
- tags: row.tags,
157
- agentType: row.agentType,
158
- modelId: row.modelId,
159
- isActive: row.isActive,
160
- isArchived: row.isArchived,
161
- // No `isFavorite`: the catalog row's column is retired — stars are
162
- // overlaid from platform.user_entity_state by `overlayAgentFavorites`.
163
- // The registry spells "absent" as `undefined` where the DB row spells
164
- // it `null`. Five fields differ; this is the vocabulary translation
165
- // at the seam, not a value change.
166
- createdBy: row.createdBy ?? void 0,
167
- organizationId: row.organizationId ?? void 0,
168
- taskId: row.taskId,
169
- sourceAgentId: row.sourceAgentId,
170
- createdAt: row.createdAt ?? void 0,
171
- updatedAt: row.updatedAt ?? void 0,
172
- isVersion: false,
173
- isOwner: row.isOwner,
174
- // `access_level` is a DB-owned vocabulary the package deliberately
175
- // leaves open (an unknown level renders as itself). This registry's
176
- // field is a closed union, so an unrecognised level is stored as
177
- // `null` — absent, never silently coerced into a wrong level.
178
- accessLevel: toRegistryAccessLevel(row.accessLevel),
179
- sharedByEmail: row.sharedByEmail ?? void 0,
180
- // The class pin; a catalog read that lacks the column leaves it absent.
181
- ...row.offeringId === void 0 ? {} : { listOfferingPin: row.offeringId }
182
- })
183
- );
184
- dispatch(setAgentFetchStatus({ id: row.id, status: "list" }));
185
- }
186
- }
187
- async function overlayAgentFavorites(dispatch, ids) {
188
- if (ids.length === 0) return;
189
- const favorites = await readFavoriteIds("agent", ids);
190
- if (!favorites) return;
191
- for (const id of ids) {
192
- dispatch(mergePartialAgent({ id, isFavorite: favorites.has(id) }));
193
- }
194
- }
195
- const overlayAgentFavoritesThunk = createAsyncThunk("agentDefinition/overlayFavorites", async (ids, { dispatch }) => {
196
- await overlayAgentFavorites(dispatch, ids);
197
- });
198
- const fetchAgentsList = createAsyncThunk(
199
- "agentDefinition/fetchList",
200
- async (_, { dispatch }) => {
201
- dispatch(setAgentsStatus("loading"));
202
- dispatch(setAgentsError(null));
203
- const catalog = getAgentCatalog();
204
- try {
205
- await catalog.ensureLoaded();
206
- } catch (e) {
207
- dispatch(setAgentsError(e instanceof Error ? e.message : String(e)));
208
- dispatch(setAgentsStatus("failed"));
209
- throw e;
210
- }
211
- const rows = catalog.getState().rows;
212
- mergeAgentSummaries(dispatch, rows);
213
- await overlayAgentFavorites(
214
- dispatch,
215
- rows.map((r) => r.id)
216
- );
217
- dispatch(setAgentsStatus("succeeded"));
218
- }
219
- );
220
- const searchAgentsServer = createAsyncThunk(
221
- "agentDefinition/searchServer",
222
- async ({ query, deep = false }, { dispatch }) => {
223
- const q = query.trim();
224
- if (!q) return { ids: [], deep, query: q };
225
- const catalog = getAgentCatalog();
226
- const ids = await catalog.searchServer(q, deep);
227
- const state = catalog.getState();
228
- const hits = ids.map((id) => state.byId[id]).filter((r) => !!r);
229
- mergeAgentSummaries(dispatch, hits);
230
- await overlayAgentFavorites(
231
- dispatch,
232
- hits.map((r) => r.id)
233
- );
234
- return { ids, deep, query: q };
235
- }
236
- );
237
- const fetchAgentsListFull = createAsyncThunk(
238
- "agentDefinition/fetchListFull",
239
- async (_, { dispatch }) => {
240
- const catalog = getAgentCatalog();
241
- await catalog.ensureLoaded();
242
- const rows = catalog.getState().rows;
243
- mergeAgentSummaries(dispatch, rows);
244
- await overlayAgentFavorites(
245
- dispatch,
246
- rows.map((r) => r.id)
247
- );
248
- }
249
- );
250
- const ensureAgentIdentity = createAsyncThunk(
251
- "agentDefinition/ensureIdentity",
252
- async (agentId, { dispatch, getState }) => {
253
- if (getState().agentDefinition.agents?.[agentId]?.name) return;
254
- const catalog = getAgentCatalog();
255
- let row = catalog.getState().byId[agentId];
256
- if (!row) {
257
- await catalog.ensureLoaded();
258
- row = catalog.getState().byId[agentId];
259
- }
260
- if (row) {
261
- mergeAgentSummaries(dispatch, [row]);
262
- await overlayAgentFavorites(dispatch, [row.id]);
263
- }
264
- }
265
- );
266
146
  const fetchAgentRunTier = createAsyncThunk(
267
147
  "agentDefinition/fetchRunTier",
268
148
  async (arg, { dispatch, getState }) => {
@@ -273,36 +153,16 @@ const fetchAgentRunTier = createAsyncThunk(
273
153
  return;
274
154
  if (await isSignedOutVisitor()) throw new NotAuthenticatedError();
275
155
  dispatch(setAgentLoading({ id: agentId, loading: true }));
276
- const { data, error } = await withRetry(
277
- () => new Promise((resolve, reject) => {
278
- const timer = setTimeout(() => {
279
- reject(new ConnectTimeoutError(15e3));
280
- }, 15e3);
281
- supabase.rpc("agx_get_run_tier", { p_agent_id: agentId }).then(
282
- (result) => {
283
- clearTimeout(timer);
284
- resolve(result);
285
- },
286
- (err) => {
287
- clearTimeout(timer);
288
- reject(err);
289
- }
290
- );
291
- }),
292
- { attempts: 2, initialDelayMs: 400 }
293
- );
294
- dispatch(setAgentLoading({ id: agentId, loading: false }));
295
- if (error) {
296
- dispatch(setAgentError({ id: agentId, error: error.message }));
297
- throw agentNameTakenError(error) ?? pgErrorToError(error);
298
- }
299
- const raw = Array.isArray(data) ? data[0] : data;
300
- if (!raw) {
301
- const refusal = agentNotReadableError(agentId);
302
- dispatch(setAgentError({ id: agentId, error: refusal.message }));
303
- throw refusal;
156
+ let row;
157
+ try {
158
+ row = await getRunTierStore().loadRunTier(agentId, { force: true });
159
+ } catch (e) {
160
+ dispatch(setAgentLoading({ id: agentId, loading: false }));
161
+ const failure = runTierFailure(agentId, e);
162
+ dispatch(setAgentError({ id: agentId, error: failure.message }));
163
+ throw failure;
304
164
  }
305
- const row = raw;
165
+ dispatch(setAgentLoading({ id: agentId, loading: false }));
306
166
  dispatch(
307
167
  mergePartialAgent({
308
168
  id: row.id,
@@ -333,18 +193,13 @@ const fetchAgentRunControls = createAsyncThunk(
333
193
  async (agentId, { dispatch, getState }) => {
334
194
  if (selectAgentRunControlsReady(getState(), agentId)) return;
335
195
  if (await isSignedOutVisitor()) throw new NotAuthenticatedError();
336
- const { data, error } = await supabase.rpc("agx_get_run_controls", {
337
- p_agent_id: agentId
338
- });
339
- if (error) {
340
- dispatch(setAgentError({ id: agentId, error: error.message }));
341
- throw pgErrorToError(error);
342
- }
343
- const row = Array.isArray(data) ? data[0] : data;
344
- if (!row) {
345
- const refusal = agentNotReadableError(agentId);
346
- dispatch(setAgentError({ id: agentId, error: refusal.message }));
347
- throw refusal;
196
+ let row;
197
+ try {
198
+ row = await getRunTierStore().loadRunControls(agentId, { force: true });
199
+ } catch (e) {
200
+ const failure = runTierFailure(agentId, e);
201
+ dispatch(setAgentError({ id: agentId, error: failure.message }));
202
+ throw failure;
348
203
  }
349
204
  const loaded = getState().agentDefinition.agents?.[agentId]?._loadedFields;
350
205
  const missing = (field) => !loaded || !hasField(loaded, field);
@@ -360,51 +215,11 @@ const fetchAgentRunControls = createAsyncThunk(
360
215
  );
361
216
  }
362
217
  );
363
- const fetchSharedAgents = createAsyncThunk("agentDefinition/fetchShared", async (_, { dispatch }) => {
364
- const { data, error } = await supabase.rpc("agx_get_shared_with_me");
365
- if (error) throw pgErrorToError(error);
366
- const rows = data ?? [];
367
- for (const row of rows) {
368
- dispatch(
369
- mergePartialAgent({
370
- id: row.id,
371
- name: row.name ?? void 0,
372
- description: row.description,
373
- category: row.category,
374
- tags: row.tags ?? [],
375
- agentType: row.agent_type,
376
- isVersion: false,
377
- createdAt: row.created_at,
378
- updatedAt: row.updated_at,
379
- isOwner: false,
380
- accessLevel: row.permission_level,
381
- sharedByEmail: row.owner_email
382
- })
383
- );
384
- dispatch(setAgentFetchStatus({ id: row.id, status: "list" }));
385
- }
386
- await overlayAgentFavorites(
387
- dispatch,
388
- rows.map((r) => r.id)
389
- );
390
- return rows;
391
- });
392
- const fetchSharedAgentsForChat = createAsyncThunk("agentDefinition/fetchSharedForChat", async () => {
393
- const { data, error } = await supabase.rpc("agx_get_shared_for_chat");
394
- if (error) throw pgErrorToError(error);
395
- return data ?? [];
396
- });
397
218
  true;
398
219
  const fetchAgentAccessLevel = createAsyncThunk("agentDefinition/fetchAccessLevel", async (agentId, { dispatch }) => {
399
- const { data, error } = await runWithSessionRetry(
400
- () => supabase.rpc("agx_get_access_level", {
401
- p_agent_id: agentId
402
- })
403
- );
404
- if (error) throw pgErrorToError(error);
405
- const rawRow = Array.isArray(data) ? data[0] : data;
406
- if (!rawRow) throw new Error(`No access level returned for agent ${agentId}`);
407
- const row = rawRow;
220
+ const row = await getRunTierStore().loadAccessLevel(agentId, { force: true }).catch((e) => {
221
+ throw runTierFailure(agentId, e);
222
+ });
408
223
  dispatch(
409
224
  mergePartialAgent({
410
225
  id: agentId,
@@ -416,15 +231,6 @@ const fetchAgentAccessLevel = createAsyncThunk("agentDefinition/fetchAccessLevel
416
231
  );
417
232
  return row;
418
233
  });
419
- function isChatListStale() {
420
- return getAgentCatalog().isStale();
421
- }
422
- const initializeChatAgents = createAsyncThunk("agentDefinition/initializeChatAgents", async (arg, { dispatch }) => {
423
- const force = arg?.force ?? false;
424
- const catalog = getAgentCatalog();
425
- await catalog.ensureLoaded(force ? { force: true } : void 0);
426
- mergeAgentSummaries(dispatch, catalog.getState().rows);
427
- });
428
234
  export {
429
235
  AgentToolAssignmentConflictError,
430
236
  AgentToolAssignmentError,
@@ -432,21 +238,12 @@ export {
432
238
  assertOwnedLiveAgentToolAssignment,
433
239
  assertRegisteredActiveToolAdditions,
434
240
  assertToolAdditionModelCapability,
435
- ensureAgentIdentity,
436
241
  fetchAgentAccessLevel,
437
242
  fetchAgentExecutionMinimal,
438
243
  fetchAgentRunControls,
439
244
  fetchAgentRunTier,
440
- fetchAgentsList,
441
- fetchAgentsListFull,
442
- fetchSharedAgents,
443
- fetchSharedAgentsForChat,
444
- initializeChatAgents,
445
245
  isAvailableToolModel,
446
- isChatListStale,
447
246
  isToolAssignmentPhantom,
448
- overlayAgentFavoritesThunk,
449
247
  sameStringArray,
450
- searchAgentsServer,
451
248
  uniqueToolIds
452
249
  };