Skip to content

Commit 96c876e

Browse files
committed
Support multiple @type value
1 parent 797198a commit 96c876e

55 files changed

Lines changed: 355 additions & 192 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

__tests__/html2/chatAdapter/layer/addCopyButton.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'@id' in entity &&
3737
entity['@id'] === '' &&
3838
'@type' in entity &&
39-
entity['@type'] === 'Message'
39+
entity['@type'].includes('Message')
4040
) {
4141
return entity;
4242
}

__tests__/html2/feedbackStatus/feedbackActivityStatus.click.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
entities: expect.arrayContaining([
7373
expect.objectContaining({
7474
'@context': 'https://schema.org',
75-
'@type': 'VoteAction',
75+
'@type': ['VoteAction'],
7676
actionOption: 'upvote',
7777
type: 'https://schema.org/VoteAction'
7878
})
@@ -99,7 +99,7 @@
9999
entities: expect.arrayContaining([
100100
expect.objectContaining({
101101
'@context': 'https://schema.org',
102-
'@type': 'VoteAction',
102+
'@type': ['VoteAction'],
103103
type: 'https://schema.org/VoteAction',
104104
actionOption: 'downvote'
105105
})
@@ -127,7 +127,7 @@
127127
entities: expect.arrayContaining([
128128
expect.objectContaining({
129129
'@context': 'https://schema.org',
130-
'@type': 'VoteAction',
130+
'@type': ['VoteAction'],
131131
type: 'https://schema.org/VoteAction',
132132
actionOption: 'downvote'
133133
})

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"packages/test/web-server",
2323
"packages/core-debug-api",
2424
"packages/core-graph",
25+
"packages/core-json-ld",
2526
"packages/core",
2627
"packages/react-hooks",
2728
"packages/react-valibot",
@@ -85,6 +86,7 @@
8586
"precommit:eslint:core": "cd packages && cd core && npm run precommit:eslint",
8687
"precommit:eslint:core-debug-api": "cd packages && cd core-debug-api && npm run precommit:eslint",
8788
"precommit:eslint:core-graph": "cd packages && cd core-graph && npm run precommit:eslint",
89+
"precommit:eslint:core-json-ld": "cd packages && cd core-json-ld && npm run precommit:eslint",
8890
"precommit:eslint:debug-theme": "cd packages && cd debug-theme && npm run precommit:eslint",
8991
"precommit:eslint:directlinespeech": "cd packages && cd directlinespeech && npm run precommit:eslint",
9092
"precommit:eslint:fluent-theme": "cd packages && cd fluent-theme && npm run precommit:eslint",
@@ -122,6 +124,7 @@
122124
"precommit:typecheck:core": "cd packages && cd core && npm run precommit:typecheck",
123125
"precommit:typecheck:core-debug-api": "cd packages && cd core-debug-api && npm run precommit:typecheck",
124126
"precommit:typecheck:core-graph": "cd packages && cd core-graph && npm run precommit:typecheck",
127+
"precommit:typecheck:core-json-ld": "cd packages && cd core-json-ld && npm run precommit:typecheck",
125128
"precommit:typecheck:debug-theme": "cd packages && cd debug-theme && npm run precommit:typecheck",
126129
"precommit:typecheck:fluent-theme": "cd packages && cd fluent-theme && npm run precommit:typecheck",
127130
"precommit:typecheck:react-hooks": "cd packages && cd react-hooks && npm run precommit:typecheck",
@@ -151,6 +154,7 @@
151154
"start:core": "cd packages && cd core && npm start",
152155
"start:core-debug-api": "cd packages && cd core-debug-api && npm start",
153156
"start:core-graph": "cd packages && cd core-graph && npm start",
157+
"start:core-json-ld": "cd packages && cd core-json-ld && npm start",
154158
"start:debug-theme": "cd packages && cd debug-theme && npm start",
155159
"start:directlinespeech": "cd packages && cd directlinespeech && npm start",
156160
"start:fluent-theme": "cd packages && cd fluent-theme && npm start",

packages/bundle/esbuild.static.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const IGNORED_OWN_PACKAGES = [
137137

138138
const { workspaces } = await readPackage({ cwd: resolve(fileURLToPath(import.meta.url), '../../../') });
139139

140-
const allOwnExports = new Set();
140+
const allOwnExports = new Map();
141141

142142
for (const path of workspaces) {
143143
// eslint-disable-next-line no-await-in-loop
@@ -147,14 +147,16 @@ const IGNORED_OWN_PACKAGES = [
147147
continue;
148148
}
149149

150+
const { name: packageName } = packageJson;
151+
150152
for (const key of getKeysRecursive(packageJson.exports)) {
151153
if (key.startsWith('.')) {
152154
if (key === '.') {
153-
allOwnExports.add(`${packageJson.name}`);
155+
allOwnExports.set(packageName, packageName);
154156
} else if (key.endsWith('.js')) {
155157
// We need to remove .js suffix otherwise, esbuild will emit filename.js.js.
156158
// ./filename.js -> /filename
157-
allOwnExports.add(`${packageJson.name}${key.slice(1, -3)}`);
159+
allOwnExports.set(`${packageName}${key.slice(1, -3)}`, `${packageName}${key.slice(1)}`);
158160
}
159161
}
160162
}
@@ -175,7 +177,7 @@ const IGNORED_OWN_PACKAGES = [
175177
'botframework-webchat/middleware': './src/boot/exports/middleware.ts',
176178
'botframework-webchat/schema': './src/boot/exports/schema.ts',
177179
// TODO: [P2] We can remove the `Array.from()` after bumping Node.js.
178-
...Array.from(allOwnExports.keys()).reduce((entryPoints, key) => ({ ...entryPoints, [key]: key }), {})
180+
...Object.fromEntries(allOwnExports)
179181
};
180182

181183
console.log('Exporting the following own entry points:');

packages/bundle/src/boot/actual/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ export {
1919
type OrgSchemaSoftwareSourceCode,
2020
type OrgSchemaUserReview,
2121
type OrgSchemaVoteAction
22-
} from 'botframework-webchat-core';
22+
} from 'botframework-webchat-core/org-schema.js';

packages/component/src/ActivityFeedback/ActivityFeedback.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
2+
import { isOfType } from 'botframework-webchat-core/json-ld.js';
23
import React, { memo, useCallback, useMemo, type FormEventHandler, type KeyboardEventHandler } from 'react';
34
import { Extract, wrapWith } from 'react-wrap-with';
45
import { useRefFrom } from 'use-ref-from';
@@ -57,7 +58,7 @@ function InternalActivityFeedback() {
5758

5859
// Hide feedback form if feedback has already been submitted or it does not require UserReview.
5960
const isExpanded = useMemo(
60-
() => !hasSubmitted && selectedAction?.result[0]?.['@type'] === 'UserReview',
61+
() => !hasSubmitted && isOfType('UserReview', selectedAction?.result[0]),
6162
[hasSubmitted, selectedAction]
6263
);
6364

packages/component/src/ActivityFeedback/private/FeedbackVoteButton.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
22
import { hooks } from 'botframework-webchat-api';
3-
import { orgSchemaActionSchema, orgSchemaVoteActionSchema } from 'botframework-webchat-core';
3+
import { orgSchemaActionSchema, orgSchemaVoteActionSchema } from 'botframework-webchat-core/org-schema.js';
44
import React, { memo, useCallback, useMemo, useRef } from 'react';
55
import { useRefFrom } from 'use-ref-from';
66
import { literal, object, pipe, readonly, string, union, type InferInput } from 'valibot';
7+
import { isOfType } from 'botframework-webchat-core/json-ld.js';
78

89
import { useListenToActivityFeedbackFocus } from '../providers/private/FocusPropagation';
910
import useActivityFeedbackHooks from '../providers/useActivityFeedbackHooks';
@@ -35,11 +36,11 @@ function FeedbackVoteButton(props: FeedbackVoteButtonProps) {
3536
const actionRef = useRefFrom(action);
3637
const buttonRef = useRef<HTMLInputElement>(null);
3738
const direction = useMemo(() => {
38-
if (action['@type'] === 'DislikeAction') {
39+
if (isOfType('DislikeAction', action)) {
3940
return 'down';
40-
} else if (action['@type'] === 'LikeAction') {
41+
} else if (isOfType('LikeAction', action)) {
4142
return 'up';
42-
} else if (action['@type'] === 'VoteAction') {
43+
} else if (isOfType('VoteAction', action)) {
4344
if (action.actionOption[0] === 'downvote') {
4445
return 'down';
4546
} else if (action.actionOption[0] === 'upvote') {

packages/component/src/ActivityFeedback/private/getDisclaimerFromReviewAction.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { orgSchemaUserReviewSchema, type OrgSchemaAction, type OrgSchemaThing } from 'botframework-webchat-core';
1+
import {
2+
orgSchemaUserReviewSchema,
3+
type OrgSchemaAction,
4+
type OrgSchemaThing
5+
} from 'botframework-webchat-core/org-schema.js';
26
import { safeParse } from 'valibot';
37

48
export default function getDisclaimerFromActivity(action: OrgSchemaAction): string | undefined {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { type OrgSchemaAction } from 'botframework-webchat-core';
1+
import { type OrgSchemaAction } from 'botframework-webchat-core/org-schema.js';
2+
import { isOfType } from 'botframework-webchat-core/json-ld.js';
23

34
export default function isActionRequireReview(
45
action: OrgSchemaAction | undefined
5-
): action is OrgSchemaAction & { result: { '@type': 'UserReview' } } {
6-
return action?.result[0]?.['@type'] === 'UserReview';
6+
): action is OrgSchemaAction & { result: { '@type': 'UserReview'[] } } {
7+
const [firstResult] = action?.result ?? [];
8+
9+
return isOfType('UserReview', firstResult);
710
}

0 commit comments

Comments
 (0)