@ai-matrx/chat 0.7.29 → 0.7.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-matrx/chat
2
2
 
3
+ ## 0.7.30
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/chat/v0.7.29..npm/chat/v0.7.30 -- apps/shared/chat`).
7
+ No source changes intended and no consumer action required.
8
+
3
9
  ## 0.7.29
4
10
  ### the agents messenger
5
11
 
@@ -1,12 +1,11 @@
1
+ import { type ResolvedContextRow } from "@ai-matrx/agents/context";
2
+ import type { ChatRootState } from "../../../../store/root-state.js";
1
3
  /**
2
- * The context rows a conversation's chip and full view DISPLAY: the door's
3
- * display rows (`selectDisplayContextRows`), with the server-added documents
4
- * reconciled against what is attached to the conversation NOW — the same
5
- * platform.associations edges `AttachedDocumentChips` lists, and the connector
6
- * resources (repos, Google files, synced records) the attachments handle has
7
- * read (`selectConversationAttachmentsEntry`, no second fetch). An attachment
8
- * detached since the last receipt drops out at once; one attached since then
9
- * shows at once, its size unknown until the next receipt.
4
+ * What the host's context sources (the page the person is on, for a browser host) would add to
5
+ * the next turn, read now and again whenever a source says it changed, the window regains focus,
6
+ * or the conversation changes. A host without sources reads `{}` once and never again.
10
7
  */
11
- import type { ResolvedContextRow } from "@ai-matrx/agents/context";
8
+ export declare function useHostContextPreview(conversationId: string): Record<string, unknown>;
9
+ /** The host's would-be context as rows, each under the person's saved rule; keys already shown stay as they are. */
10
+ export declare function hostContextRows(state: ChatRootState, conversationId: string, shown: readonly ResolvedContextRow[], hostContext: Readonly<Record<string, unknown>>): ResolvedContextRow[];
12
11
  export declare function useConversationDisplayRows(conversationId: string, mandateKillSwitch: boolean): ResolvedContextRow[];
@@ -1,9 +1,22 @@
1
1
  "use client";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import {
4
+ DEFAULT_SURFACE_KEY,
5
+ resolveContextRow
6
+ } from "@ai-matrx/agents/context";
7
+ import { humanizeIdentifier } from "@ai-matrx/kit/text-case";
2
8
  import { useAppSelector, useAppStore } from "../../../../store/hooks.js";
3
9
  import { useConversationMaterialized } from "../../../hooks/useConversationMaterialized.js";
4
10
  import { useContainerLinks } from "@ai-matrx/associations/react";
5
11
  import { attachmentContextKey } from "@ai-matrx/agents/context";
6
12
  import {
13
+ previewHostTurnContext,
14
+ subscribeHostContextChanges
15
+ } from "../../../redux/execution-system/utils/host-turn.js";
16
+ import { resolveClientSurface } from "../../../redux/execution-system/utils/build-tool-injection.js";
17
+ import { selectSavedContextRuleRows } from "../../../redux/execution-system/context-rules/context-rules.thunks.js";
18
+ import {
19
+ selectContextInlineCap,
7
20
  DOCUMENT_ATTACHMENT_PREFIXES,
8
21
  RESOURCE_ATTACHMENT_PREFIXES,
9
22
  durableAttachmentKey,
@@ -18,6 +31,51 @@ import {
18
31
  useAttachedDocumentFileNames
19
32
  } from "../resources/attached-documents.js";
20
33
  import { selectOrganizationId } from "../../../../host/org.js";
34
+ function useHostContextPreview(conversationId) {
35
+ const store = useAppStore();
36
+ const [preview, setPreview] = useState({});
37
+ const latest = useRef(0);
38
+ useEffect(() => {
39
+ let live = true;
40
+ const read = () => {
41
+ const ticket = ++latest.current;
42
+ void previewHostTurnContext(store.getState(), conversationId).then(
43
+ (context) => {
44
+ if (live && ticket === latest.current) setPreview(context);
45
+ },
46
+ () => void 0
47
+ );
48
+ };
49
+ read();
50
+ const off = subscribeHostContextChanges(read);
51
+ const onFocus = () => read();
52
+ window.addEventListener("focus", onFocus);
53
+ return () => {
54
+ live = false;
55
+ off();
56
+ window.removeEventListener("focus", onFocus);
57
+ };
58
+ }, [store, conversationId]);
59
+ return preview;
60
+ }
61
+ function hostContextRows(state, conversationId, shown, hostContext) {
62
+ const keys = Object.keys(hostContext);
63
+ if (keys.length === 0) return [];
64
+ const have = new Set(shown.map((row) => row.key));
65
+ const saved = selectSavedContextRuleRows(state);
66
+ const cap = selectContextInlineCap(state, conversationId);
67
+ const primarySurface = resolveClientSurface(state, conversationId) ?? null;
68
+ return keys.filter((key) => !have.has(key) && hostContext[key] !== void 0).map((key) => {
69
+ const source = {
70
+ key,
71
+ label: humanizeIdentifier(key) || key,
72
+ surfaceKey: DEFAULT_SURFACE_KEY,
73
+ origin: "page",
74
+ value: hostContext[key]
75
+ };
76
+ return resolveContextRow(source, saved, cap, primarySurface);
77
+ });
78
+ }
21
79
  function useConversationDisplayRows(conversationId, mandateKillSwitch) {
22
80
  const store = useAppStore();
23
81
  const rows = useAppSelector(selectDisplayContextRows(conversationId, mandateKillSwitch));
@@ -55,11 +113,28 @@ function useConversationDisplayRows(conversationId, mandateKillSwitch) {
55
113
  key: attachmentContextKey(row.provider, row.resource_ref),
56
114
  label: row.display_name
57
115
  })) : null;
58
- return reconcileDurableAttachments(store.getState(), conversationId, rows, [
59
- { prefixes: DOCUMENT_ATTACHMENT_PREFIXES, items: documents },
60
- { prefixes: RESOURCE_ATTACHMENT_PREFIXES, items: resources }
61
- ]);
116
+ const reconciled = reconcileDurableAttachments(
117
+ store.getState(),
118
+ conversationId,
119
+ rows,
120
+ [
121
+ { prefixes: DOCUMENT_ATTACHMENT_PREFIXES, items: documents },
122
+ { prefixes: RESOURCE_ATTACHMENT_PREFIXES, items: resources }
123
+ ]
124
+ );
125
+ const hostContext = useHostContextPreview(conversationId);
126
+ return useMemo(() => {
127
+ const extra = hostContextRows(
128
+ store.getState(),
129
+ conversationId,
130
+ reconciled,
131
+ hostContext
132
+ );
133
+ return extra.length === 0 ? reconciled : [...reconciled, ...extra];
134
+ }, [store, conversationId, reconciled, hostContext]);
62
135
  }
63
136
  export {
64
- useConversationDisplayRows
137
+ hostContextRows,
138
+ useConversationDisplayRows,
139
+ useHostContextPreview
65
140
  };
@@ -37,6 +37,15 @@ export declare function resetLatchedTurns(): void;
37
37
  * keeps what the start latched (a resume whose start predates this page load latches then).
38
38
  */
39
39
  export declare function collectHostTurnContribution(state: ChatRootState, conversationId: string, phase: ChatHostTurnPhase): Promise<ChatHostTurnContribution | null>;
40
+ /**
41
+ * What the host's context sources would add to the NEXT turn's `context`, read for display (the
42
+ * composer's context chip). Same sources, same bounded wait, same merge as a real send, but
43
+ * nothing is latched. A source that is slow or throws contributes no rows here (the skip is
44
+ * announced through diagnostics like any other).
45
+ */
46
+ export declare function previewHostTurnContext(state: ChatRootState, conversationId: string): Promise<Record<string, unknown>>;
47
+ /** Subscribe to every context source's "my answer may have changed" signal; returns one unsubscribe. */
48
+ export declare function subscribeHostContextChanges(onChange: () => void): () => void;
40
49
  /**
41
50
  * Merge the host's context entries under what the request already carries: a key the person
42
51
  * or the agent set always wins. Returns the original object when the host adds nothing.
@@ -93,6 +93,29 @@ async function collectHostTurnContribution(state, conversationId, phase) {
93
93
  }
94
94
  return contribution;
95
95
  }
96
+ async function previewHostTurnContext(state, conversationId) {
97
+ if (!isChatHostConfigured()) return {};
98
+ const sources = getChatHost().registry.contextSources ?? [];
99
+ if (sources.length === 0) return {};
100
+ const input = {
101
+ conversationId,
102
+ agentId: agentIdOf(state, conversationId),
103
+ phase: "start"
104
+ };
105
+ const merged = mergeContributions(
106
+ await Promise.all(sources.map((source) => askSource(source, input)))
107
+ );
108
+ return merged?.context ?? {};
109
+ }
110
+ function subscribeHostContextChanges(onChange) {
111
+ if (!isChatHostConfigured()) return () => void 0;
112
+ const offs = (getChatHost().registry.contextSources ?? []).flatMap(
113
+ (source) => source.subscribe ? [source.subscribe(onChange)] : []
114
+ );
115
+ return () => {
116
+ for (const off of offs) off();
117
+ };
118
+ }
96
119
  function mergeHostTurnContext(existing, hostContext) {
97
120
  if (!hostContext) return existing;
98
121
  const keys = Object.keys(hostContext);
@@ -113,7 +136,9 @@ export {
113
136
  devicePermissionModeKey,
114
137
  getLatchedTurn,
115
138
  mergeHostTurnContext,
139
+ previewHostTurnContext,
116
140
  readDevicePermissionMode,
117
141
  resetLatchedTurns,
142
+ subscribeHostContextChanges,
118
143
  writeDevicePermissionMode
119
144
  };
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Scopes (user-authored dimensions: organization, project, task, scope types and their
5
5
  * values, the active scope selection) are a platform primitive the chat package READS to
6
- * build what an agent receives. Until `@ai-matrx/scopes` exists (P17s1–s2), the host hands
6
+ * build what an agent receives. Until the data/records packages own scope reading (scopes package deleted 2026-10-09), the host hands
7
7
  * them over through ONE registration, `registerChatScopes({...})`, keyed by the export names
8
8
  * that package will publish — so P17s3 swaps this module's import specifier for
9
9
  * `@ai-matrx/scopes` and deletes this file, with no call-site change.
@@ -873,6 +873,12 @@ export interface ChatContextSource {
873
873
  /** Stable id, for diagnostics. */
874
874
  id: string;
875
875
  contribute(input: ChatHostTurnInput): Promise<ChatHostTurnContribution | null>;
876
+ /**
877
+ * Tell the package this source's answer may have changed (the page navigated, the person
878
+ * switched tabs), so the composer's context chip re-reads it. Returns the unsubscribe. Absent:
879
+ * the chip reads the source when the conversation opens and when the window regains focus.
880
+ */
881
+ subscribe?(onChange: () => void): () => void;
876
882
  }
877
883
  export interface ChatRoutingPort {
878
884
  policy(conversationId: string): ChatRoutingPolicy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-matrx/chat",
3
- "version": "0.7.29",
3
+ "version": "0.7.30",
4
4
  "description": "THE one AI Matrx person-to-agent chat system: the full chat (running agents, conversations, tool calls, streaming, context, surfaces, voice) as explicit per-module subpaths @ai-matrx/chat/<domain>/<module> (no wildcards: scripts/public-modules.json) over a host contract (/host, /host/react) whose only required value is a db. One chat, one renderer: the old kernel entries (., /external-store, /matrx, /react, /tools, styles.css, tokens.css) are retired.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -4716,14 +4716,14 @@
4716
4716
  "server-only": "^0.0.1",
4717
4717
  "uuid": "^14.0.2",
4718
4718
  "zod": "^4.6.5",
4719
+ "@ai-matrx/alchemy": "latest",
4719
4720
  "@ai-matrx/associations": "latest",
4720
4721
  "@ai-matrx/browser-audio": "latest",
4721
- "@ai-matrx/alchemy": "latest",
4722
+ "@ai-matrx/agents": "latest",
4722
4723
  "@ai-matrx/canvas": "latest",
4723
4724
  "@ai-matrx/content-ir": "latest",
4724
4725
  "@ai-matrx/content-ir-react": "latest",
4725
4726
  "@ai-matrx/data": "latest",
4726
- "@ai-matrx/diff": "latest",
4727
4727
  "@ai-matrx/design-system": "latest",
4728
4728
  "@ai-matrx/icons": "latest",
4729
4729
  "@ai-matrx/kit": "latest",
@@ -4731,11 +4731,11 @@
4731
4731
  "@ai-matrx/messaging": "latest",
4732
4732
  "@ai-matrx/print": "latest",
4733
4733
  "@ai-matrx/realtime": "latest",
4734
+ "@ai-matrx/diff": "latest",
4734
4735
  "@ai-matrx/records": "latest",
4735
4736
  "@ai-matrx/records-ui": "latest",
4736
4737
  "@ai-matrx/rich-content": "latest",
4737
- "@ai-matrx/rich-editor": "latest",
4738
- "@ai-matrx/agents": "latest"
4738
+ "@ai-matrx/rich-editor": "latest"
4739
4739
  },
4740
4740
  "devDependencies": {
4741
4741
  "@arethetypeswrong/cli": "^0.18.5",
@@ -4854,5 +4854,5 @@
4854
4854
  "check:side-effects": "node ../scripts/check-side-effects-listed.mjs . && node ../scripts/check-side-effects-listed.mjs --self-test",
4855
4855
  "check:public-surface": "node ./scripts/sync-public-surface.mjs --check && node ./scripts/sync-public-surface.mjs --self-test"
4856
4856
  },
4857
- "gitHead": "4d71c2b833fcf4ddf381519c7ceda59cfa0174db"
4857
+ "gitHead": "95a5e215a7437a241b5588b14653a183c82c240c"
4858
4858
  }