Skip to content

Commit

Permalink
feat: Add details to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tshashkova committed Nov 18, 2024
1 parent b56f590 commit 4b83175
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
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]

### Added

- Add details to logs

## [2.9.0] - 2024-11-18

### Added
Expand Down
9 changes: 9 additions & 0 deletions packages/web-core/src/common/data_structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,12 @@ export enum LogLevel {
INTERNAL = 'INTERNAL',
DEBUG = 'DEBUG',
}

export type ProtobufValue =
| string
| number
| boolean
| null
| undefined
| ProtobufValue[]
| { [key: string]: ProtobufValue };
18 changes: 17 additions & 1 deletion packages/web-core/src/entities/packets/log.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,48 @@ import {
LogsEvent as ProtoLogsEvent,
LogsEventLogLevel,
} from '../../../proto/ai/inworld/packets/packets.pb';
import { LogLevel } from '../../common/data_structures';
import { LogLevel, ProtobufValue } from '../../common/data_structures';

export interface LogsEventLogDetail {
text: string | undefined;
detail: ProtobufValue | undefined;
}

export class LogsEvent {
readonly text: string;
readonly level: LogLevel;
readonly metadata: Record<string, string> | undefined;
readonly details: LogsEventLogDetail[] | undefined;

constructor({
text,
level,
metadata,
details,
}: {
text: string;
level: LogLevel;
metadata: Record<string, string>;
details: LogsEventLogDetail[] | undefined;
}) {
this.text = text;
this.level = level;
this.metadata = metadata;

if (details?.length >= 0) {
this.details = details;
}
}

static fromProto(proto: ProtoLogsEvent) {
return new LogsEvent({
text: proto.text,
level: this.getLogLevel(proto.level),
metadata: proto.metadata,
details: proto.details?.map((detail) => ({
text: detail.text,
detail: detail.detail as ProtobufValue,
})),
});
}

Expand Down
5 changes: 5 additions & 0 deletions packages/web-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
HistoryChangedProps,
ItemsInEntitiesOperationType,
MicrophoneMode,
ProtobufValue,
SessionState,
StopAudioPlayback,
TaskParameter,
Expand Down Expand Up @@ -71,6 +72,7 @@ import {
EmotionStrengthCode,
} from './entities/packets/emotion/emotion_strength.entity';
import { InworldPacket } from './entities/packets/inworld_packet.entity';
import { LogsEvent, LogsEventLogDetail } from './entities/packets/log.entity';
import { PacketId } from './entities/packets/packet_id.entity';
import { Actor, Routing } from './entities/packets/routing.entity';
import { TextEvent } from './entities/packets/text.entity';
Expand Down Expand Up @@ -127,9 +129,12 @@ export {
InworldPacket,
InworldTriggers,
ItemsInEntitiesOperationType,
LogsEvent,
LogsEventLogDetail,
MicrophoneMode,
PacketId,
PreviousDialog,
ProtobufValue,
ProtoPacket,
Routing,
SessionContinuation,
Expand Down

0 comments on commit 4b83175

Please sign in to comment.