Skip to content

Commit

Permalink
fix: Fix changing of scene capabilities (#323)
Browse files Browse the repository at this point in the history
* fix: Fix changing of scene capabilities

* chore: @inworld/web-core 2.9.2-beta.0

* fix: Don't send loadScene if scene name is not changed

* chore: @inworld/web-core 2.9.2-beta.1

* fix: Make name optional

* chore: @inworld/web-core 2.9.2-beta.2

* chore: Upgade yarn

* fix: Take into account main logs value

* feat: Add capabilities tests

* feat: Allow to get current connection capabilities

* fix: Fix tests

* chore: Update yarn.lock

* fix: Add logs capability automatically

* chore: @inworld/web-core 2.9.2-beta.4

---------

Co-authored-by: CI-inworld <[email protected]>
  • Loading branch information
tshashkova and inworld-gh-svc-account authored Jan 6, 2025
1 parent 6b03682 commit 977110b
Show file tree
Hide file tree
Showing 23 changed files with 1,344 additions and 989 deletions.
894 changes: 0 additions & 894 deletions .yarn/releases/yarn-4.3.0.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.3.cjs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
enableGlobalCache: true
npmPublishAccess: public

nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.3.0.cjs

npmPublishAccess: public

yarnPath: .yarn/releases/yarn-4.5.3.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"ts-jest": "^29.1.2",
"typescript": "^5.5.2"
},
"packageManager": "yarn@4.3.0"
"packageManager": "yarn@4.5.3"
}
6 changes: 6 additions & 0 deletions packages/web-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [Unreleased]

### Fixed

- Fix changing of scene capabilities

## [2.9.1] - 2024-12-03

### Added
Expand Down
16 changes: 12 additions & 4 deletions packages/web-core/__tests__/clients/inworld.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ describe('should finish with success', () => {
expect(() => inworldClient.build()).not.toThrow();
});

test("should warn about logs capability if it's set explicitly with speciied logs type", async () => {
jest.spyOn(console, 'warn').mockImplementationOnce(jest.fn());
new InworldClient().setConfiguration({
capabilities: { logs: true },
});
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
'logs capability is deprecated. Please use logsDebug, logsInfo, logsWarning instead',
);
});

test('should allow to specify custom gateway', async () => {
const connection = {
gateway: {
Expand All @@ -84,10 +95,7 @@ describe('should finish with success', () => {
expect(ConnectionService).toHaveBeenCalledTimes(1);
expect(ConnectionService).toHaveBeenCalledWith(
expect.objectContaining({
config: {
connection,
capabilities: expect.anything(),
},
config: { connection },
}),
);
});
Expand Down
75 changes: 75 additions & 0 deletions packages/web-core/__tests__/entities/capability.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Capability } from '../../src/entities/capability.entity';

test('should convert empty capabilities to proto', () => {
const proto = Capability.toProto({});

expect(proto).toEqual({
audio: true,
debugInfo: false,
emotions: false,
interruptions: false,
logs: true,
logsWarning: true,
logsInfo: true,
logsDebug: false,
logsInternal: false,
multiAgent: true,
multiModalActionPlanning: false,
narratedActions: false,
perceivedLatencyReport: true,
phonemeInfo: false,
pingPongReport: true,
silenceEvents: false,
});
});

test('should convert logsInfo capabilities to proto', () => {
const capabilities = {
logsWarning: false,
logsInfo: true,
logsDebug: false,
logsInternal: false,
};

const proto = Capability.toProto(capabilities);

expect(proto.logs).toEqual(true);
expect(proto.logsWarning).toEqual(false);
expect(proto.logsInfo).toEqual(true);
expect(proto.logsDebug).toEqual(false);
expect(proto.logsInternal).toEqual(false);
});

test('should convert logsDebug capabilities to proto', () => {
const capabilities = {
logsWarning: false,
logsInfo: false,
logsDebug: true,
logsInternal: false,
};

const proto = Capability.toProto(capabilities);

expect(proto.logs).toEqual(true);
expect(proto.logsWarning).toEqual(false);
expect(proto.logsInfo).toEqual(false);
expect(proto.logsDebug).toEqual(true);
expect(proto.logsInternal).toEqual(false);
});

test('should convert logsInternal capabilities to proto', () => {
const capabilities = {
logsWarning: false,
logsInfo: false,
logsDebug: false,
logsInternal: true,
};

const proto = Capability.toProto(capabilities);

expect(proto.logs).toEqual(true);
expect(proto.logsWarning).toEqual(false);
expect(proto.logsInfo).toEqual(false);
expect(proto.logsDebug).toEqual(false);
expect(proto.logsInternal).toEqual(true);
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EmotionEventSpaffCode } from '../../proto/ai/inworld/packets/packets.pb';
import { EmotionEventSpaffCode } from '../../../../proto/ai/inworld/packets/packets.pb';
import {
EmotionBehavior,
EmotionBehaviorCode,
} from '../../src/entities/packets/emotion/emotion_behavior.entity';
} from '../../../../src/entities/packets/emotion/emotion_behavior.entity';

const mappingTestTable = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EmotionEventStrength } from '../../proto/ai/inworld/packets/packets.pb';
import { EmotionEventStrength } from '../../../../proto/ai/inworld/packets/packets.pb';
import {
EmotionStrength,
EmotionStrengthCode,
} from '../../src/entities/packets/emotion/emotion_strength.entity';
} from '../../../../src/entities/packets/emotion/emotion_strength.entity';

const mappingTestTable = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import {
InworlControlAction,
InworldPacketType,
ItemsInEntitiesOperationType,
} from '../../src/common/data_structures';
import { protoTimestamp } from '../../src/common/helpers';
import { EntityItem } from '../../src/entities/entities/entity_item';
import { ItemOperation } from '../../src/entities/entities/item_operation';
import { AudioEvent } from '../../src/entities/packets/audio.entity';
import { ControlEvent } from '../../src/entities/packets/control.entity';
import { InworldPacket } from '../../src/entities/packets/inworld_packet.entity';
import { Routing } from '../../src/entities/packets/routing.entity';
import { TextEvent } from '../../src/entities/packets/text.entity';
import { agents, convertAgentsToCharacters, getPacketId } from '../helpers';
LogLevel,
} from '../../../src/common/data_structures';
import { protoTimestamp } from '../../../src/common/helpers';
import { EntityItem } from '../../../src/entities/entities/entity_item';
import { ItemOperation } from '../../../src/entities/entities/item_operation';
import { AudioEvent } from '../../../src/entities/packets/audio.entity';
import { ControlEvent } from '../../../src/entities/packets/control.entity';
import { InworldPacket } from '../../../src/entities/packets/inworld_packet.entity';
import { PerceivedLatencyReportPrecisionType } from '../../../src/entities/packets/latency/perceived_latency_report_precision.entity';
import { PingPongType } from '../../../src/entities/packets/latency/ping_pong_report_type.entity';
import { Routing } from '../../../src/entities/packets/routing.entity';
import { TextEvent } from '../../../src/entities/packets/text.entity';
import { agents, convertAgentsToCharacters, getPacketId } from '../../helpers';

const packetId = getPacketId();
const packetIdWithCorrelation = {
Expand Down Expand Up @@ -91,6 +94,21 @@ test('should get trigger packet fields', () => {
expect(packet.packetId).toEqual(packetIdWithCorrelation);
});

test('should get task packet fields', () => {
const packet = new InworldPacket({
packetId: packetIdWithCorrelation,
routing,
date,
type: InworldPacketType.TASK,
});

expect(packet.isTask()).toEqual(true);

expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetIdWithCorrelation);
});

test('should get emotion packet fields', () => {
const packet = new InworldPacket({
packetId,
Expand Down Expand Up @@ -140,6 +158,93 @@ test('should get cancel response packet fields', () => {
expect(packet.packetId).toEqual(packetId);
});

test('should get log packet fields', () => {
const packet = new InworldPacket({
packetId,
routing,
date,
log: {
text: v4(),
details: [],
metadata: {},
level: LogLevel.DEBUG,
},
type: InworldPacketType.LOG,
});

expect(packet.isLog()).toEqual(true);
expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetId);
});

test('should get ping packet fields', () => {
const packet = new InworldPacket({
packetId,
routing,
date,
latencyReport: {
pingPong: {
packetId: null,
pingTimestamp: protoTimestamp(),
type: { type: PingPongType.PING },
},
},
type: InworldPacketType.LATENCY_REPORT,
});

expect(packet.isLatencyReport()).toEqual(true);
expect(packet.isPingPongReport()).toEqual(true);
expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetId);
});

test('should get pong packet fields', () => {
const packet = new InworldPacket({
packetId,
routing,
date,
latencyReport: {
pingPong: {
packetId,
pingTimestamp: protoTimestamp(),
type: { type: PingPongType.PONG },
},
},
type: InworldPacketType.LATENCY_REPORT,
});

expect(packet.isLatencyReport()).toEqual(true);
expect(packet.isPingPongReport()).toEqual(true);
expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetId);
});

test('should get perceived latency packet fields', () => {
const packet = new InworldPacket({
packetId,
routing,
date,
latencyReport: {
perceivedLatency: {
latency: 100,
precision: {
precision: PerceivedLatencyReportPrecisionType.FINE,
},
},
},
type: InworldPacketType.LATENCY_REPORT,
});

expect(packet.isLatencyReport()).toEqual(true);
expect(packet.isPerceivedLatencyReport()).toEqual(true);
expect(packet.routing).toEqual(routing);
expect(packet.date).toEqual(date);
expect(packet.packetId).toEqual(packetId);
});

describe('scene mutation', () => {
const characters = convertAgentsToCharacters(agents);

Expand Down
54 changes: 54 additions & 0 deletions packages/web-core/__tests__/entities/packets/task.entity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { v4 } from 'uuid';

import { TaskEvent } from '../../../src/entities/packets/task.entity';

test('should get fields', () => {
const name = v4();
const parameters = [
{
name: v4(),
value: v4(),
},
];
const task = new TaskEvent({
name,
parameters,
});

expect(task.name).toEqual(name);
expect(task.parameters).toEqual(parameters);
});

test('shoulf get fields without parameters', () => {
const name = v4();
const task = new TaskEvent({
name,
});

expect(task.name).toEqual(name);
expect(task.parameters).toBeUndefined();
});

test('should convert from proto', () => {
const proto = {
name: v4(),
parameters: [
{
name: v4(),
value: v4(),
},
],
};
const packet = TaskEvent.fromProto(proto);

expect(packet.name).toEqual(proto.name);
expect(packet.parameters).toEqual(packet.parameters);
});

test('should convert from proto without parameters', () => {
const proto = { name: v4() };
const packet = TaskEvent.fromProto(proto);

expect(packet.name).toEqual(proto.name);
expect(packet.parameters).toBeUndefined();
});
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ describe('open', () => {
.mockImplementationOnce(() =>
Promise.resolve({ sceneStatus: { agents } } as LoadedScene),
);
jest
.spyOn(WebSocketConnection.prototype, 'reopenSession')
.mockImplementationOnce(() => Promise.resolve());

await connection.open();

Expand Down Expand Up @@ -700,7 +703,7 @@ describe('onMessage', () => {
const HOSTNAME = 'localhost:1235';

beforeEach(() => {
server = new WS(`ws://${HOSTNAME}/v1/session/open`, {
server = new WS(`wss://${HOSTNAME}/v1/session/open`, {
jsonProtocol: true,
});

Expand Down Expand Up @@ -1028,7 +1031,7 @@ describe('latency', () => {
let server: WS;

beforeEach(() => {
server = new WS(`ws://${HOSTNAME}/v1/session/open`, {
server = new WS(`wss://${HOSTNAME}/v1/session/open`, {
jsonProtocol: true,
});

Expand Down
Loading

0 comments on commit 977110b

Please sign in to comment.