@jsb188/ai-chat 1.1.12 → 1.1.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jsb188
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -105,6 +105,6 @@ node packages/@jsb188:ai-chat/benchmarks/streaming.mjs /tmp/chat-streaming.json
105
105
 
106
106
  An optional second argument points to a saved baseline parser bundle exporting `parseContent`, allowing comparison with the original implementation as well as the current full parser. The browser benchmark accepts a built preview directory and JSON output path; see the build and comparison instructions in `VERIFICATION.md`.
107
107
 
108
- The application includes a local browser fixture at `apps/marketday/tests/fixtures/AIChatContentPreview.html`. Its standalone Vite config bypasses application routing and uses synthetic data only. From `apps/marketday`, run `npx vite --config tests/fixtures/ai-chat.vite.config.ts --port 3010 --strictPort` (3011 if occupied). It exercises the real assistant container, themes, sidebar widths, status changes, streaming, and parsing/React profiling. It never creates production messages.
108
+ The application includes a local browser fixture at `client/tests/fixtures/AIChatContentPreview.html`. Its standalone Vite config bypasses application routing and uses synthetic data only. From `client`, run `npx vite --config tests/fixtures/ai-chat.vite.config.ts --port 3010 --strictPort` (3011 if occupied). It exercises the real assistant container, themes, sidebar widths, status changes, streaming, and parsing/React profiling. It never creates production messages.
109
109
 
110
110
  See [verification results](./VERIFICATION.md) for measured performance, commands, and environment limitations. Application integration and this package live in separate repositories (`packages` is a submodule); coordinate them when committing or deploying. No backend schema, persisted text format, or migration changed.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@jsb188/ai-chat",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Source-preserving AI chat content parsing and rendering.",
5
- "license": "ISC",
5
+ "license": "MIT",
6
6
  "author": "jsb188",
7
7
  "type": "module",
8
8
  "exports": {
@@ -12,12 +12,12 @@
12
12
  "./ui/AIChatUI": "./src/ui/AIChatUI.tsx"
13
13
  },
14
14
  "peerDependencies": {
15
- "@jsb188/app": "1.1.12",
16
- "@jsb188/form": "1.1.12",
17
- "@jsb188/graphql": "1.1.12",
18
- "@jsb188/mday": "1.1.12",
19
- "@jsb188/mday-web": "1.1.12",
20
- "@jsb188/react-web": "1.1.12",
15
+ "@jsb188/app": "1.1.13",
16
+ "@jsb188/form": "1.1.13",
17
+ "@jsb188/graphql": "1.1.13",
18
+ "@jsb188/mday": "1.1.13",
19
+ "@jsb188/mday-web": "1.1.13",
20
+ "@jsb188/react-web": "1.1.13",
21
21
  "react": "^19.3.0",
22
22
  "react-dom": "^19.3.0"
23
23
  },
@@ -33,5 +33,13 @@
33
33
  "scripts": {
34
34
  "test": "vitest run --config ./vitest.config.ts",
35
35
  "typecheck": "tsc --project ./tsconfig.json"
36
- }
36
+ },
37
+ "files": [
38
+ "src/**/*.{ts,tsx,css,svg}",
39
+ "!**/*.test.*",
40
+ "!**/*.spec.*",
41
+ "!**/tests/**",
42
+ "!**/*.md",
43
+ "!**/.DS_Store"
44
+ ]
37
45
  }
package/src/main.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { AIChatContent } from './modules/AIChatContent';
2
2
  export type { AIChatContentProps } from './modules/AIChatContent';
3
3
  export { AgentNotes } from './modules/AgentNotes';
4
+ export { AgentNoteContent } from './modules/AgentNoteItem';
4
5
  export type { AgentNoteChatStarted, AgentNotesProps } from './modules/AgentNotes.types';
5
6
  export type { ChatContentStatus } from './types/content';
7
+ export { ChatLinkHandlerContext } from './modules/ChatLinkHandlerContext';
@@ -1,8 +1,9 @@
1
1
  import i18n from '@jsb188/app/i18n/index.ts';
2
+ import type { AgentNoteGQL } from '@jsb188/mday/types/agentNote.d.ts';
2
3
  import { usePopOverActions, usePopOverEvent } from '@jsb188/react/states';
3
- import type { POListItemObj } from '@jsb188/react/types/PopOver.d';
4
+ import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
4
5
  import { PopOverButton } from '@jsb188/react-web/modules/PopOver';
5
- import { Icon } from '@jsb188/react-web/svgs/Icon';
6
+ import { COMMON_ICON_NAMES, Icon } from '@jsb188/react-web/svgs/Icon';
6
7
  import { useEffect, useRef } from 'react';
7
8
  import type { AgentNoteActionState } from '../ui/AgentNotesUI.types';
8
9
 
@@ -12,7 +13,7 @@ import type { AgentNoteActionState } from '../ui/AgentNotesUI.types';
12
13
  export const AgentNoteActionsMenu = (p: {
13
14
  id: string;
14
15
  priorityAction: AgentNoteActionState;
15
- needsAttention: boolean;
16
+ note: AgentNoteGQL;
16
17
  archiveAction: AgentNoteActionState;
17
18
  deleteScheduledTaskAction: AgentNoteActionState | null;
18
19
  onCollapse: () => void;
@@ -21,7 +22,7 @@ export const AgentNoteActionsMenu = (p: {
21
22
  const { acknowledgePopOverEvent, closePopOver } = usePopOverActions();
22
23
  const currentProps = useRef(p);
23
24
  currentProps.current = p;
24
- const options: POListItemObj[] = [
25
+ const options: POListIfaceItem[] = [
25
26
  {
26
27
  __type: 'LIST_ITEM',
27
28
  name: 'collapse',
@@ -29,6 +30,18 @@ export const AgentNoteActionsMenu = (p: {
29
30
  text: i18n.t('c.collapse_item'),
30
31
  iconName: 'arrow-rectangle-up',
31
32
  },
33
+ {
34
+ __type: 'LIST_ITEM_POPUP',
35
+ text: i18n.t('agent_note.edit_title'),
36
+ iconName: COMMON_ICON_NAMES.edit,
37
+ disabled: !p.note.canManage,
38
+ description: p.note.canManage ? undefined : i18n.t('agent_note.agent_note_manage_not_allowed'),
39
+ variables: {
40
+ name: 'EDIT_AGENT_NOTE_TITLE',
41
+ preset: 'EDIT_AGENT_NOTE_TITLE',
42
+ props: { organizationId: p.note.organizationId, agentNoteId: p.note.id, title: p.note.title ?? null },
43
+ },
44
+ },
32
45
  {
33
46
  __type: 'LIST_ITEM',
34
47
  name: 'priority',
@@ -37,7 +50,7 @@ export const AgentNoteActionsMenu = (p: {
37
50
  text: i18n.t(
38
51
  p.priorityAction.busy
39
52
  ? 'agent_note.updating_priority'
40
- : p.needsAttention === true
53
+ : p.note.needsAttention === true
41
54
  ? 'agent_note.decrease_priority'
42
55
  : 'agent_note.increase_priority',
43
56
  ),
@@ -1,32 +1,23 @@
1
+ import { AGENT_NOTE_LINK_ENTITY_TYPE_ENUMS } from '@jsb188/mday/constants/agentNote.ts';
1
2
  import i18n from '@jsb188/app/i18n/index.ts';
2
3
  import type { AgentNoteGQL, AgentNoteLinkGQL } from '@jsb188/mday/types/agentNote.d.ts';
3
4
  import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d.ts';
4
- import { makeFieldDocFormPath } from '@jsb188/mday-web/utils/route';
5
+ import { getLinkedEntityDestination } from '@jsb188/mday-web/utils/linkedEntity';
6
+ import { LINKED_ENTITY_TYPES, type LinkedEntityType } from '@jsb188/mday/constants/linkedEntity.ts';
5
7
  import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
6
8
  import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
7
9
  import { getAgentNoteSourceLink } from './AgentNotes.helpers';
8
10
 
9
11
  const FILE_CONSTANTS = {
10
- hiddenReferenceTypes: ['LOG_ACTIVITY', 'LOG_ACTIVITY_GROUP', 'CAMPAIGN_TEMPLATE'] as readonly string[],
12
+ hiddenReferenceTypes: ['LOG_ACTIVITY', 'LOG_ACTIVITY_GROUP'] as readonly string[],
11
13
  };
12
14
 
13
15
  /*
14
16
  * Resolve references with unambiguous viewer routes; other references remain visible as labels.
15
17
  */
16
18
  function getReferencePath(link: AgentNoteLinkGQL) {
17
- const id = encodeURIComponent(link.entityId);
18
- switch (link.entityType) {
19
- case 'DATA_TABLE':
20
- return `/app/d/${id}`;
21
- case 'SHEET':
22
- return `/app/s/${id}`;
23
- case 'WORKFLOW':
24
- return `/app/runs/${id}`;
25
- case 'FIELD_DOC':
26
- return link.fieldDocProgramId ? makeFieldDocFormPath(link.fieldDocProgramId, link.entityId) : undefined;
27
- default:
28
- return undefined;
29
- }
19
+ if (!LINKED_ENTITY_TYPES.includes(link.entityType as LinkedEntityType)) return undefined;
20
+ return getLinkedEntityDestination({ ...link, entityType: link.entityType as LinkedEntityType }).to;
30
21
  }
31
22
 
32
23
  /*
@@ -64,12 +55,13 @@ export function getAgentNoteReferenceOptions(
64
55
  const seen = new Set<string>();
65
56
  let hasReferences = false;
66
57
  for (const link of note.links) {
67
- if (FILE_CONSTANTS.hiddenReferenceTypes.includes(link.entityType)) continue;
58
+ if (!AGENT_NOTE_LINK_ENTITY_TYPE_ENUMS.includes(link.entityType) || FILE_CONSTANTS.hiddenReferenceTypes.includes(link.entityType))
59
+ continue;
68
60
  const key = `${link.entityType}:${link.entityId}`;
69
61
  if (seen.has(key)) continue;
70
62
  seen.add(key);
71
63
  const to = getReferencePath(link);
72
- if (source && (to === source.to || (link.entityType === 'CAMPAIGN' && link.entityId === note.campaignId))) continue;
64
+ if (source && (to === source.to || (link.entityType === 'EMAIL_OUTREACH' && link.entityId === note.emailOutreachId))) continue;
73
65
  if (!hasReferences) {
74
66
  options.push({ __type: 'TEXT', text: i18n.t('agent_note.sources'), fontClassName: 'ft_xs ft_medium', designClassName: 'cl_md' });
75
67
  hasReferences = true;
@@ -15,37 +15,34 @@ import {
15
15
  getAgentNoteRefreshWarning,
16
16
  getAgentNoteResultBlockStatus,
17
17
  getAgentNoteSharedResultComputedAt,
18
+ getAgentNoteSourcePath,
18
19
  } from './AgentNotes.helpers';
19
20
  import { useAgentNoteItem, useAgentNoteRefreshLabel } from './AgentNotes.hooks';
20
21
  import type { AgentNoteChatActions, AgentNoteStateActions, AgentNoteRefreshActions, AgentNoteStateCache } from './AgentNotes.types';
21
22
  import { AIChatContent } from './AIChatContent';
22
23
  import { canViewerReadAgentNoteSourceKind } from '@jsb188/mday/utils/agentNote.ts';
23
24
  import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
24
- import { useOpenModalScreen } from '@jsb188/react/states';
25
+ import { SmartLink } from '@jsb188/react-web/modules/Link';
25
26
 
26
27
  /*
27
- * Offer report navigation from an expanded email note without fetching any report data.
28
+ * Link an expanded email outreach note to its outreach summary.
28
29
  */
29
- const AgentNoteRepliesAction = (p: { note: AgentNoteGQL }) => {
30
+ const AgentNoteOutreachAction = (p: { note: AgentNoteGQL }) => {
30
31
  const { organizationRelationship } = useOrgRelFromMyOrganizations(p.note.organizationId);
31
- const openModalScreen = useOpenModalScreen();
32
- const allowed = canViewerReadAgentNoteSourceKind('CAMPAIGN_EMAIL', (check, permission) =>
32
+ const sourcePath = getAgentNoteSourcePath(p.note);
33
+ const allowed = canViewerReadAgentNoteSourceKind('EMAIL_OUTREACH', (check, permission) =>
33
34
  checkACLPermission(organizationRelationship, check, permission),
34
35
  );
35
- if (!p.note.campaignId || !allowed) return null;
36
+ if (!sourcePath || !allowed) return null;
36
37
  return (
37
- <button
38
- type='button'
39
- className='link ft_sm mt_sm'
40
- onClick={() =>
41
- openModalScreen({
42
- name: 'AGENT_NOTE',
43
- props: { organizationId: p.note.organizationId, agentNoteId: p.note.id, initialSection: 'replies' },
44
- })
45
- }
46
- >
47
- {i18n.t('campaign.reply_report.view_replies')}
48
- </button>
38
+ <div className="mt_md">
39
+ <SmartLink
40
+ to={sourcePath}
41
+ linkClassName="text_link cl_md"
42
+ >
43
+ {i18n.t('campaign.view_email_outreach')}
44
+ </SmartLink>
45
+ </div>
49
46
  );
50
47
  };
51
48
 
@@ -84,7 +81,7 @@ const AgentNoteReferencesMenu = (p: { id: string; note: AgentNoteGQL }) => {
84
81
  className="ic_sm"
85
82
  aria-hidden="true"
86
83
  >
87
- <Icon name="list-bullets" />
84
+ <Icon name="list-items" />
88
85
  </span>
89
86
  </PopOverTooltipButton>
90
87
  );
@@ -125,8 +122,27 @@ const AgentNoteResultBlocks = memo((p: { blocks?: AgentNoteResultBlockGQL[] }) =
125
122
  });
126
123
 
127
124
  /*
128
- * Fetch full note content only while its disclosure is open and render it with the chat parser,
129
- * followed by its saved query results.
125
+ * Render a loaded note's body with the chat parser, followed by its saved query results and, when asked,
126
+ * the outreach summary link. Shared by the homepage note cards and the note modal so both look identical.
127
+ */
128
+ export const AgentNoteContent = memo((p: { agentNote: AgentNoteGQL; showOutreachAction?: boolean }) => (
129
+ <>
130
+ <div
131
+ className="mdy_msg p_n ofw"
132
+ style={{ minWidth: 0 }}
133
+ >
134
+ <AIChatContent
135
+ text={p.agentNote.body || ''}
136
+ tableClassName="bd_t_1 bd_b_1 bd_lt"
137
+ />
138
+ </div>
139
+ <AgentNoteResultBlocks blocks={p.agentNote.resultBlocks} />
140
+ {p.showOutreachAction && p.agentNote.kind === 'EMAIL_OUTREACH' && <AgentNoteOutreachAction note={p.agentNote} />}
141
+ </>
142
+ ));
143
+
144
+ /*
145
+ * Fetch full note content only while its disclosure is open and render the shared note content.
130
146
  */
131
147
  const AgentNoteBody = memo((p: { organizationId: string; agentNoteId: string }) => {
132
148
  const { agentNote, error } = useAgentNote(p, { markRead: false });
@@ -134,19 +150,10 @@ const AgentNoteBody = memo((p: { organizationId: string; agentNoteId: string })
134
150
  if (error || !agentNote) return null;
135
151
 
136
152
  return (
137
- <>
138
- <div
139
- className="mdy_msg p_n ofw"
140
- style={{ minWidth: 0 }}
141
- >
142
- <AIChatContent
143
- text={agentNote.body || ''}
144
- tableClassName="bd_t_1 bd_b_1 bd_lt"
145
- />
146
- </div>
147
- <AgentNoteResultBlocks blocks={agentNote.resultBlocks} />
148
- {agentNote.kind === 'CAMPAIGN_EMAIL' && <AgentNoteRepliesAction note={agentNote} />}
149
- </>
153
+ <AgentNoteContent
154
+ agentNote={agentNote}
155
+ showOutreachAction
156
+ />
150
157
  );
151
158
  });
152
159
 
@@ -178,6 +185,7 @@ export const AgentNoteItem = memo(
178
185
  <div>
179
186
  <AgentNoteItemUI
180
187
  emoji={p.note.emoji}
188
+ title={p.note.title}
181
189
  headline={p.note.headline?.trim() || i18n.t('agent_note.agent_note')}
182
190
  expanded={p.expanded}
183
191
  needsAttention={p.note.needsAttention === true}
@@ -193,7 +201,7 @@ export const AgentNoteItem = memo(
193
201
  <AgentNoteActionsMenu
194
202
  id={`agent_note_actions_${controlsId}`}
195
203
  priorityAction={actions.priority}
196
- needsAttention={p.note.needsAttention}
204
+ note={p.note}
197
205
  archiveAction={actions.archive}
198
206
  deleteScheduledTaskAction={actions.deleteScheduledTask}
199
207
  onCollapse={() => p.onToggleExpanded(p.note.id)}
@@ -1,9 +1,10 @@
1
1
  import type { AgentNoteKindEnum } from '@jsb188/mday/types/agentNote.d.ts';
2
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
2
3
 
3
4
  // Presentation-only groups: extending this registry never changes the query or database reads.
4
5
  export const AGENT_NOTE_GROUPS = {
5
6
  SCHEDULED_TASKS: { kinds: ['REMINDER'], title: 'c.scheduled_tasks', icon: 'calendar-3' },
6
- CAMPAIGNS: { kinds: ['CAMPAIGN_EMAIL', 'CAMPAIGN_FORM'], title: 'campaign.campaigns', icon: 'email-megaphone' },
7
+ CAMPAIGNS: { kinds: ['EMAIL_OUTREACH'], title: 'campaign.campaigns', icon: COMMON_ICON_NAMES.email_outreach },
7
8
  DATA_INSIGHTS: { kinds: ['INSIGHT', 'FIELD_DOC'], title: 'c.data_insights', icon: 'workflow-data-table-2' },
8
9
  } as const satisfies Record<string, { kinds: readonly AgentNoteKindEnum[]; title: string; icon: string }>;
9
10
 
@@ -7,7 +7,7 @@ import { AGENT_NOTE_DISPLAY_LIMITS } from './AgentNotes.constants';
7
7
 
8
8
  type AgentNoteSourceFields = Pick<
9
9
  AgentNoteGQL,
10
- 'kind' | 'campaignId' | 'fieldDocId' | 'fieldDocProgramId' | 'reminderWorkflowId' | 'ownedDataTableId'
10
+ 'kind' | 'emailOutreachId' | 'fieldDocId' | 'fieldDocProgramId' | 'reminderWorkflowId' | 'ownedDataTableId'
11
11
  >;
12
12
 
13
13
  /*
@@ -94,12 +94,13 @@ export function getAgentNotesDisplayKey(notes: AgentNoteGQL[]) {
94
94
  note.id,
95
95
  note.organizationId,
96
96
  note.kind,
97
- note.campaignId,
97
+ note.emailOutreachId,
98
98
  note.fieldDocId,
99
99
  note.fieldDocProgramId,
100
100
  note.reminderWorkflowId,
101
101
  note.ownedDataTableId,
102
102
  note.emoji,
103
+ note.title,
103
104
  note.headline,
104
105
  note.pinned,
105
106
  note.importance,
@@ -223,10 +224,8 @@ export function getAgentNoteSourcePath(note: AgentNoteSourceFields) {
223
224
  switch (note.kind) {
224
225
  case 'INSIGHT':
225
226
  return note.ownedDataTableId ? getAgentNoteDataTablePath(note.ownedDataTableId) : null;
226
- case 'CAMPAIGN_FORM':
227
- return note.campaignId ? `/app/outbound/forms/c/${encodeURIComponent(note.campaignId)}` : null;
228
- case 'CAMPAIGN_EMAIL':
229
- return note.campaignId ? `/app/outbound/emails/c/${encodeURIComponent(note.campaignId)}` : null;
227
+ case 'EMAIL_OUTREACH':
228
+ return note.emailOutreachId ? `/app/oe/${encodeURIComponent(note.emailOutreachId)}?page=summary` : null;
230
229
  case 'FIELD_DOC':
231
230
  return note.fieldDocId && note.fieldDocProgramId ? makeFieldDocFormPath(note.fieldDocProgramId, note.fieldDocId) : null;
232
231
  case 'REMINDER':
@@ -395,7 +395,7 @@ export function useAgentNoteItem(p: {
395
395
  agentNoteId: note.id,
396
396
  headline: note.headline,
397
397
  kind: note.kind,
398
- campaignId: note.campaignId,
398
+ emailOutreachId: note.emailOutreachId,
399
399
  reminderWorkflowId: note.reminderWorkflowId,
400
400
  ownedDataTableId: note.ownedDataTableId,
401
401
  },
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+
3
+ /* Let the chat host claim supported internal links while preserving ordinary browser navigation. */
4
+ export const ChatLinkHandlerContext = createContext<((href: string) => boolean) | null>(null);
@@ -70,9 +70,10 @@
70
70
  scrollbar-gutter: stable;
71
71
  }
72
72
 
73
- .cm_textarea_cnt {
73
+ .cm_textarea_cnt.cw {
74
74
  position: sticky;
75
75
  bottom: 0;
76
+ width: calc(100% - 20px);
76
77
  padding-bottom: calc(1rem + 0.5vh);
77
78
  }
78
79