From 541f2383129331dd8bdbcf9ec1ce99d52a895c97 Mon Sep 17 00:00:00 2001 From: nyanxyz Date: Tue, 12 Mar 2024 22:21:20 +0900 Subject: [PATCH 1/5] add customProperties to OpenSession, CreateMessage event --- package.json | 4 +- src/buf/{event_pb.ts => event_pb.d.ts} | 393 +++++++----------- src/buf/event_pb.js | 156 +++++++ src/buf/ingestion_connect.d.ts | 26 ++ ...estion_connect.ts => ingestion_connect.js} | 4 +- .../{ingestion_pb.ts => ingestion_pb.d.ts} | 46 +- src/buf/ingestion_pb.js | 19 + src/events.ts | 14 +- src/utils.ts | 13 + 9 files changed, 394 insertions(+), 281 deletions(-) rename src/buf/{event_pb.ts => event_pb.d.ts} (52%) create mode 100644 src/buf/event_pb.js create mode 100644 src/buf/ingestion_connect.d.ts rename src/buf/{ingestion_connect.ts => ingestion_connect.js} (88%) rename src/buf/{ingestion_pb.ts => ingestion_pb.d.ts} (52%) create mode 100644 src/buf/ingestion_pb.js create mode 100644 src/utils.ts diff --git a/package.json b/package.json index e69fddf..ec6f877 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alignai", - "version": "0.1.6", + "version": "0.2.0", "description": "Server-side Align AI SDK for Node.js", "keywords": [ "align-ai", @@ -22,7 +22,7 @@ ], "scripts": { "lint": "eslint .", - "build": "rm -rf ./dist && tsc" + "build": "rm -rf ./dist && tsc --allowJs" }, "dependencies": { "@bufbuild/protobuf": "^1.7.2", diff --git a/src/buf/event_pb.ts b/src/buf/event_pb.d.ts similarity index 52% rename from src/buf/event_pb.ts rename to src/buf/event_pb.d.ts index 2678431..9d0951d 100644 --- a/src/buf/event_pb.ts +++ b/src/buf/event_pb.d.ts @@ -1,23 +1,23 @@ -// @generated by protoc-gen-es v1.3.3 with parameter "target=ts" +// @generated by protoc-gen-es v1.7.2 // @generated from file ingestion/v1alpha/event.proto (package ingestion.v1alpha, syntax proto3) /* eslint-disable */ // @ts-nocheck -import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; -import { Message, proto3, Timestamp } from "@bufbuild/protobuf"; +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage, Timestamp } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; /** * Event represents a every possible ingestion case. * * @generated from message ingestion.v1alpha.Event */ -export class Event extends Message { +export declare class Event extends Message { /** * (Required) Unique identifier for the event * * @generated from field: string id = 1; */ - id = ""; + id: string; /** * (Required) The type of event data @@ -29,7 +29,7 @@ export class Event extends Message { * * @generated from field: string type = 2; */ - type = ""; + type: string; /** * (Required) Event generation time @@ -50,38 +50,21 @@ export class Event extends Message { * * @generated from field: string project_id = 5; */ - projectId = ""; + projectId: string; - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.Event"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "type", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "create_time", kind: "message", T: Timestamp }, - { no: 4, name: "properties", kind: "message", T: EventProperties }, - { no: 5, name: "project_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): Event { - return new Event().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): Event { - return new Event().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): Event { - return new Event().fromJsonString(jsonString, options); - } - - static equals(a: Event | PlainMessage | undefined, b: Event | PlainMessage | undefined): boolean { - return proto3.util.equals(Event, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Event; + + static fromJson(jsonValue: JsonValue, options?: Partial): Event; + + static fromJsonString(jsonString: string, options?: Partial): Event; + + static equals(a: Event | PlainMessage | undefined, b: Event | PlainMessage | undefined): boolean; } /** @@ -94,7 +77,7 @@ export class Event extends Message { * * @generated from message ingestion.v1alpha.EventProperties */ -export class EventProperties extends Message { +export declare class EventProperties extends Message { /** * @generated from oneof ingestion.v1alpha.EventProperties.reserved_properties */ @@ -122,56 +105,49 @@ export class EventProperties extends Message { */ value: EventProperties_FeedbackProperties; case: "feedbackProperties"; - } | { case: undefined; value?: undefined } = { case: undefined }; + } | { case: undefined; value?: undefined }; + + /** + * Custom properties + * Key must be unique and only contains alphanumeric characters and underscores. + * Key cannot start with a number. + * + * @generated from field: map custom_properties = 10; + */ + customProperties: { [key: string]: EventProperties_CustomPropertyValue }; - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "session_properties", kind: "message", T: EventProperties_SessionProperties, oneof: "reserved_properties" }, - { no: 2, name: "message_properties", kind: "message", T: EventProperties_MessageProperties, oneof: "reserved_properties" }, - { no: 3, name: "user_properties", kind: "message", T: EventProperties_UserProperties, oneof: "reserved_properties" }, - { no: 4, name: "feedback_properties", kind: "message", T: EventProperties_FeedbackProperties, oneof: "reserved_properties" }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties { - return new EventProperties().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties { - return new EventProperties().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties { - return new EventProperties().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties | PlainMessage | undefined, b: EventProperties | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties; + + static equals(a: EventProperties | PlainMessage | undefined, b: EventProperties | PlainMessage | undefined): boolean; } /** * @generated from message ingestion.v1alpha.EventProperties.SessionProperties */ -export class EventProperties_SessionProperties extends Message { +export declare class EventProperties_SessionProperties extends Message { /** * (Required) Unique identifier for the session * * @generated from field: string session_id = 1; */ - sessionId = ""; + sessionId: string; /** * Title of the session * * @generated from field: string session_title = 2; */ - sessionTitle = ""; + sessionTitle: string; /** * Start time of the session @@ -186,85 +162,68 @@ export class EventProperties_SessionProperties extends Message) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties.SessionProperties"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "session_title", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "session_start_time", kind: "message", T: Timestamp }, - { no: 4, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 5, name: "assistant_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_SessionProperties { - return new EventProperties_SessionProperties().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_SessionProperties { - return new EventProperties_SessionProperties().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties_SessionProperties { - return new EventProperties_SessionProperties().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties_SessionProperties | PlainMessage | undefined, b: EventProperties_SessionProperties | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties_SessionProperties, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_SessionProperties; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_SessionProperties; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_SessionProperties; + + static equals(a: EventProperties_SessionProperties | PlainMessage | undefined, b: EventProperties_SessionProperties | PlainMessage | undefined): boolean; } /** * @generated from message ingestion.v1alpha.EventProperties.MessageProperties */ -export class EventProperties_MessageProperties extends Message { +export declare class EventProperties_MessageProperties extends Message { /** * (Required) Unique identifier for the session * * @generated from field: string session_id = 1; */ - sessionId = ""; + sessionId: string; /** * Unique identifier for the message. This data only used for hint. * * @generated from field: string message_id_hint = 2; */ - messageIdHint = ""; + messageIdHint: string; /** * (Required) Message index in the session. * * @generated from field: int32 message_index_hint = 3; */ - messageIndexHint = 0; + messageIndexHint: number; /** * (Required) Role of the speaker * * @generated from field: ingestion.v1alpha.EventProperties.MessageProperties.Role message_role = 4; */ - messageRole = EventProperties_MessageProperties_Role.UNSPECIFIED; + messageRole: EventProperties_MessageProperties_Role; /** * (Required) Content of the message * * @generated from field: string message_content = 5; */ - messageContent = ""; + messageContent: string; /** * Message creation time @@ -274,43 +233,25 @@ export class EventProperties_MessageProperties extends Message) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties.MessageProperties"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "message_id_hint", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "message_index_hint", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 4, name: "message_role", kind: "enum", T: proto3.getEnumType(EventProperties_MessageProperties_Role) }, - { no: 5, name: "message_content", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 6, name: "message_create_time", kind: "message", T: Timestamp }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_MessageProperties { - return new EventProperties_MessageProperties().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_MessageProperties { - return new EventProperties_MessageProperties().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties_MessageProperties { - return new EventProperties_MessageProperties().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties_MessageProperties | PlainMessage | undefined, b: EventProperties_MessageProperties | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties_MessageProperties, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_MessageProperties; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_MessageProperties; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_MessageProperties; + + static equals(a: EventProperties_MessageProperties | PlainMessage | undefined, b: EventProperties_MessageProperties | PlainMessage | undefined): boolean; } /** * @generated from enum ingestion.v1alpha.EventProperties.MessageProperties.Role */ -export enum EventProperties_MessageProperties_Role { +export declare enum EventProperties_MessageProperties_Role { /** * @generated from enum value: ROLE_UNSPECIFIED = 0; */ @@ -326,25 +267,19 @@ export enum EventProperties_MessageProperties_Role { */ ASSISTANT = 2, } -// Retrieve enum metadata with: proto3.getEnumType(EventProperties_MessageProperties_Role) -proto3.util.setEnumType(EventProperties_MessageProperties_Role, "ingestion.v1alpha.EventProperties.MessageProperties.Role", [ - { no: 0, name: "ROLE_UNSPECIFIED" }, - { no: 1, name: "ROLE_USER" }, - { no: 2, name: "ROLE_ASSISTANT" }, -]); /** * All fields except user_id are optional but at least one field must be set. * * @generated from message ingestion.v1alpha.EventProperties.UserProperties */ -export class EventProperties_UserProperties extends Message { +export declare class EventProperties_UserProperties extends Message { /** * (Required) Unique identifier for the user * * @generated from field: string user_id = 1; */ - userId = ""; + userId: string; /** * User's email address @@ -352,7 +287,7 @@ export class EventProperties_UserProperties extends Message) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties.UserProperties"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "user_email", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "user_ip", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 4, name: "user_location", kind: "message", T: EventProperties_UserProperties_Location }, - { no: 5, name: "user_create_time", kind: "message", T: Timestamp }, - { no: 6, name: "user_display_name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_UserProperties { - return new EventProperties_UserProperties().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_UserProperties { - return new EventProperties_UserProperties().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties_UserProperties { - return new EventProperties_UserProperties().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties_UserProperties | PlainMessage | undefined, b: EventProperties_UserProperties | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties_UserProperties, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_UserProperties; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_UserProperties; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_UserProperties; + + static equals(a: EventProperties_UserProperties | PlainMessage | undefined, b: EventProperties_UserProperties | PlainMessage | undefined): boolean; } /** * @generated from message ingestion.v1alpha.EventProperties.UserProperties.Location */ -export class EventProperties_UserProperties_Location extends Message { +export declare class EventProperties_UserProperties_Location extends Message { /** * ISO-3166-1 alpha-2 code of the country * * @generated from field: string country_code = 1; */ - countryCode = ""; + countryCode: string; /** * State name * * @generated from field: string state = 2; */ - state = ""; + state: string; /** * City name * * @generated from field: string city = 3; */ - city = ""; + city: string; - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties.UserProperties.Location"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "country_code", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "state", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 3, name: "city", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_UserProperties_Location { - return new EventProperties_UserProperties_Location().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_UserProperties_Location { - return new EventProperties_UserProperties_Location().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties_UserProperties_Location { - return new EventProperties_UserProperties_Location().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties_UserProperties_Location | PlainMessage | undefined, b: EventProperties_UserProperties_Location | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties_UserProperties_Location, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_UserProperties_Location; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_UserProperties_Location; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_UserProperties_Location; + + static equals(a: EventProperties_UserProperties_Location | PlainMessage | undefined, b: EventProperties_UserProperties_Location | PlainMessage | undefined): boolean; } /** * @generated from message ingestion.v1alpha.EventProperties.FeedbackProperties */ -export class EventProperties_FeedbackProperties extends Message { +export declare class EventProperties_FeedbackProperties extends Message { /** * (Required) Unique identifier for the session * * @generated from field: string session_id = 1; */ - sessionId = ""; + sessionId: string; /** * (Required) Target resource of the feedback * * @generated from field: ingestion.v1alpha.EventProperties.FeedbackProperties.Target feedback_target = 2; */ - feedbackTarget = EventProperties_FeedbackProperties_Target.UNSPECIFIED; + feedbackTarget: EventProperties_FeedbackProperties_Target; /** * (Required) Score of the feedback. 0 * * @generated from field: int32 feedback_score = 3; */ - feedbackScore = 0; + feedbackScore: number; /** * Unique identifier for the message. This data only used for hint. * * @generated from field: string message_id_hint = 4; */ - messageIdHint = ""; + messageIdHint: string; /** * Message index in the session. @@ -513,44 +415,27 @@ export class EventProperties_FeedbackProperties extends Message) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.EventProperties.FeedbackProperties"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "feedback_target", kind: "enum", T: proto3.getEnumType(EventProperties_FeedbackProperties_Target) }, - { no: 3, name: "feedback_score", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - { no: 4, name: "message_id_hint", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 5, name: "message_index_hint", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_FeedbackProperties { - return new EventProperties_FeedbackProperties().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_FeedbackProperties { - return new EventProperties_FeedbackProperties().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): EventProperties_FeedbackProperties { - return new EventProperties_FeedbackProperties().fromJsonString(jsonString, options); - } - - static equals(a: EventProperties_FeedbackProperties | PlainMessage | undefined, b: EventProperties_FeedbackProperties | PlainMessage | undefined): boolean { - return proto3.util.equals(EventProperties_FeedbackProperties, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_FeedbackProperties; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_FeedbackProperties; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_FeedbackProperties; + + static equals(a: EventProperties_FeedbackProperties | PlainMessage | undefined, b: EventProperties_FeedbackProperties | PlainMessage | undefined): boolean; } /** * @generated from enum ingestion.v1alpha.EventProperties.FeedbackProperties.Target */ -export enum EventProperties_FeedbackProperties_Target { +export declare enum EventProperties_FeedbackProperties_Target { /** * @generated from enum value: TARGET_UNSPECIFIED = 0; */ @@ -570,10 +455,30 @@ export enum EventProperties_FeedbackProperties_Target { */ MESSAGE = 2, } -// Retrieve enum metadata with: proto3.getEnumType(EventProperties_FeedbackProperties_Target) -proto3.util.setEnumType(EventProperties_FeedbackProperties_Target, "ingestion.v1alpha.EventProperties.FeedbackProperties.Target", [ - { no: 0, name: "TARGET_UNSPECIFIED" }, - { no: 1, name: "TARGET_SESSION" }, - { no: 2, name: "TARGET_MESSAGE" }, -]); + +/** + * @generated from message ingestion.v1alpha.EventProperties.CustomPropertyValue + */ +export declare class EventProperties_CustomPropertyValue extends Message { + /** + * Value can have maximum 256 characters. + * + * @generated from field: string string_value = 1; + */ + stringValue: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "ingestion.v1alpha.EventProperties.CustomPropertyValue"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): EventProperties_CustomPropertyValue; + + static fromJson(jsonValue: JsonValue, options?: Partial): EventProperties_CustomPropertyValue; + + static fromJsonString(jsonString: string, options?: Partial): EventProperties_CustomPropertyValue; + + static equals(a: EventProperties_CustomPropertyValue | PlainMessage | undefined, b: EventProperties_CustomPropertyValue | PlainMessage | undefined): boolean; +} diff --git a/src/buf/event_pb.js b/src/buf/event_pb.js new file mode 100644 index 0000000..be02d10 --- /dev/null +++ b/src/buf/event_pb.js @@ -0,0 +1,156 @@ +// @generated by protoc-gen-es v1.7.2 +// @generated from file ingestion/v1alpha/event.proto (package ingestion.v1alpha, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { proto3, Timestamp } from "@bufbuild/protobuf"; + +/** + * Event represents a every possible ingestion case. + * + * @generated from message ingestion.v1alpha.Event + */ +export const Event = proto3.makeMessageType( + "ingestion.v1alpha.Event", + () => [ + { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "type", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "create_time", kind: "message", T: Timestamp }, + { no: 4, name: "properties", kind: "message", T: EventProperties }, + { no: 5, name: "project_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * Client must set one of the following properties according to the event type. + * Reserved properties: + * - session_open: SessionProperties + * - message_create: MessageProperties + * - session_close: SessionProperties + * - user_recognize: UserProperties + * + * @generated from message ingestion.v1alpha.EventProperties + */ +export const EventProperties = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties", + () => [ + { no: 1, name: "session_properties", kind: "message", T: EventProperties_SessionProperties, oneof: "reserved_properties" }, + { no: 2, name: "message_properties", kind: "message", T: EventProperties_MessageProperties, oneof: "reserved_properties" }, + { no: 3, name: "user_properties", kind: "message", T: EventProperties_UserProperties, oneof: "reserved_properties" }, + { no: 4, name: "feedback_properties", kind: "message", T: EventProperties_FeedbackProperties, oneof: "reserved_properties" }, + { no: 10, name: "custom_properties", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "message", T: EventProperties_CustomPropertyValue} }, + ], +); + +/** + * @generated from message ingestion.v1alpha.EventProperties.SessionProperties + */ +export const EventProperties_SessionProperties = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.SessionProperties", + () => [ + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "session_title", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "session_start_time", kind: "message", T: Timestamp }, + { no: 4, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "assistant_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], + {localName: "EventProperties_SessionProperties"}, +); + +/** + * @generated from message ingestion.v1alpha.EventProperties.MessageProperties + */ +export const EventProperties_MessageProperties = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.MessageProperties", + () => [ + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "message_id_hint", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "message_index_hint", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 4, name: "message_role", kind: "enum", T: proto3.getEnumType(EventProperties_MessageProperties_Role) }, + { no: 5, name: "message_content", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 6, name: "message_create_time", kind: "message", T: Timestamp }, + ], + {localName: "EventProperties_MessageProperties"}, +); + +/** + * @generated from enum ingestion.v1alpha.EventProperties.MessageProperties.Role + */ +export const EventProperties_MessageProperties_Role = proto3.makeEnum( + "ingestion.v1alpha.EventProperties.MessageProperties.Role", + [ + {no: 0, name: "ROLE_UNSPECIFIED", localName: "UNSPECIFIED"}, + {no: 1, name: "ROLE_USER", localName: "USER"}, + {no: 2, name: "ROLE_ASSISTANT", localName: "ASSISTANT"}, + ], +); + +/** + * All fields except user_id are optional but at least one field must be set. + * + * @generated from message ingestion.v1alpha.EventProperties.UserProperties + */ +export const EventProperties_UserProperties = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.UserProperties", + () => [ + { no: 1, name: "user_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "user_email", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "user_ip", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 4, name: "user_location", kind: "message", T: EventProperties_UserProperties_Location }, + { no: 5, name: "user_create_time", kind: "message", T: Timestamp }, + { no: 6, name: "user_display_name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], + {localName: "EventProperties_UserProperties"}, +); + +/** + * @generated from message ingestion.v1alpha.EventProperties.UserProperties.Location + */ +export const EventProperties_UserProperties_Location = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.UserProperties.Location", + () => [ + { no: 1, name: "country_code", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "state", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "city", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], + {localName: "EventProperties_UserProperties_Location"}, +); + +/** + * @generated from message ingestion.v1alpha.EventProperties.FeedbackProperties + */ +export const EventProperties_FeedbackProperties = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.FeedbackProperties", + () => [ + { no: 1, name: "session_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "feedback_target", kind: "enum", T: proto3.getEnumType(EventProperties_FeedbackProperties_Target) }, + { no: 3, name: "feedback_score", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + { no: 4, name: "message_id_hint", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 5, name: "message_index_hint", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, + ], + {localName: "EventProperties_FeedbackProperties"}, +); + +/** + * @generated from enum ingestion.v1alpha.EventProperties.FeedbackProperties.Target + */ +export const EventProperties_FeedbackProperties_Target = proto3.makeEnum( + "ingestion.v1alpha.EventProperties.FeedbackProperties.Target", + [ + {no: 0, name: "TARGET_UNSPECIFIED", localName: "UNSPECIFIED"}, + {no: 1, name: "TARGET_SESSION", localName: "SESSION"}, + {no: 2, name: "TARGET_MESSAGE", localName: "MESSAGE"}, + ], +); + +/** + * @generated from message ingestion.v1alpha.EventProperties.CustomPropertyValue + */ +export const EventProperties_CustomPropertyValue = proto3.makeMessageType( + "ingestion.v1alpha.EventProperties.CustomPropertyValue", + () => [ + { no: 1, name: "string_value", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], + {localName: "EventProperties_CustomPropertyValue"}, +); + diff --git a/src/buf/ingestion_connect.d.ts b/src/buf/ingestion_connect.d.ts new file mode 100644 index 0000000..424b304 --- /dev/null +++ b/src/buf/ingestion_connect.d.ts @@ -0,0 +1,26 @@ +// @generated by protoc-gen-connect-es v1.4.0 +// @generated from file ingestion/v1alpha/ingestion.proto (package ingestion.v1alpha, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { CollectEventsRequest } from "./ingestion_pb.js"; +import { Empty, MethodKind } from "@bufbuild/protobuf"; + +/** + * @generated from service ingestion.v1alpha.IngestionService + */ +export declare const IngestionService: { + readonly typeName: "ingestion.v1alpha.IngestionService", + readonly methods: { + /** + * @generated from rpc ingestion.v1alpha.IngestionService.CollectEvents + */ + readonly collectEvents: { + readonly name: "CollectEvents", + readonly I: typeof CollectEventsRequest, + readonly O: typeof Empty, + readonly kind: MethodKind.Unary, + }, + } +}; + diff --git a/src/buf/ingestion_connect.ts b/src/buf/ingestion_connect.js similarity index 88% rename from src/buf/ingestion_connect.ts rename to src/buf/ingestion_connect.js index 93218ab..ac74a1a 100644 --- a/src/buf/ingestion_connect.ts +++ b/src/buf/ingestion_connect.js @@ -1,4 +1,4 @@ -// @generated by protoc-gen-connect-es v1.1.2 with parameter "target=ts" +// @generated by protoc-gen-connect-es v1.4.0 // @generated from file ingestion/v1alpha/ingestion.proto (package ingestion.v1alpha, syntax proto3) /* eslint-disable */ // @ts-nocheck @@ -22,5 +22,5 @@ export const IngestionService = { kind: MethodKind.Unary, }, } -} as const; +}; diff --git a/src/buf/ingestion_pb.ts b/src/buf/ingestion_pb.d.ts similarity index 52% rename from src/buf/ingestion_pb.ts rename to src/buf/ingestion_pb.d.ts index 73b77ce..04e0ece 100644 --- a/src/buf/ingestion_pb.ts +++ b/src/buf/ingestion_pb.d.ts @@ -1,16 +1,16 @@ -// @generated by protoc-gen-es v1.3.3 with parameter "target=ts" +// @generated by protoc-gen-es v1.7.2 // @generated from file ingestion/v1alpha/ingestion.proto (package ingestion.v1alpha, syntax proto3) /* eslint-disable */ // @ts-nocheck import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import { Event } from "./event_pb.js"; +import type { Event } from "./event_pb.js"; /** * @generated from message ingestion.v1alpha.CollectEventsRequest */ -export class CollectEventsRequest extends Message { +export declare class CollectEventsRequest extends Message { /** * A unique identifier for this request. Restricted to 36 ASCII characters. * A random UUID is recommended. @@ -18,41 +18,27 @@ export class CollectEventsRequest extends Message { * * @generated from field: string request_id = 1; */ - requestId = ""; + requestId: string; /** * Events to be collected * * @generated from field: repeated ingestion.v1alpha.Event events = 2; */ - events: Event[] = []; + events: Event[]; - constructor(data?: PartialMessage) { - super(); - proto3.util.initPartial(data, this); - } + constructor(data?: PartialMessage); - static readonly runtime: typeof proto3 = proto3; + static readonly runtime: typeof proto3; static readonly typeName = "ingestion.v1alpha.CollectEventsRequest"; - static readonly fields: FieldList = proto3.util.newFieldList(() => [ - { no: 1, name: "request_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, - { no: 2, name: "events", kind: "message", T: Event, repeated: true }, - ]); - - static fromBinary(bytes: Uint8Array, options?: Partial): CollectEventsRequest { - return new CollectEventsRequest().fromBinary(bytes, options); - } - - static fromJson(jsonValue: JsonValue, options?: Partial): CollectEventsRequest { - return new CollectEventsRequest().fromJson(jsonValue, options); - } - - static fromJsonString(jsonString: string, options?: Partial): CollectEventsRequest { - return new CollectEventsRequest().fromJsonString(jsonString, options); - } - - static equals(a: CollectEventsRequest | PlainMessage | undefined, b: CollectEventsRequest | PlainMessage | undefined): boolean { - return proto3.util.equals(CollectEventsRequest, a, b); - } + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): CollectEventsRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): CollectEventsRequest; + + static fromJsonString(jsonString: string, options?: Partial): CollectEventsRequest; + + static equals(a: CollectEventsRequest | PlainMessage | undefined, b: CollectEventsRequest | PlainMessage | undefined): boolean; } diff --git a/src/buf/ingestion_pb.js b/src/buf/ingestion_pb.js new file mode 100644 index 0000000..5e15e5e --- /dev/null +++ b/src/buf/ingestion_pb.js @@ -0,0 +1,19 @@ +// @generated by protoc-gen-es v1.7.2 +// @generated from file ingestion/v1alpha/ingestion.proto (package ingestion.v1alpha, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { proto3 } from "@bufbuild/protobuf"; +import { Event } from "./event_pb.js"; + +/** + * @generated from message ingestion.v1alpha.CollectEventsRequest + */ +export const CollectEventsRequest = proto3.makeMessageType( + "ingestion.v1alpha.CollectEventsRequest", + () => [ + { no: 1, name: "request_id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "events", kind: "message", T: Event, repeated: true }, + ], +); + diff --git a/src/events.ts b/src/events.ts index fd0c378..00fc1eb 100644 --- a/src/events.ts +++ b/src/events.ts @@ -1,7 +1,11 @@ import {Timestamp} from '@bufbuild/protobuf' import {v4 as uuidv4} from 'uuid'; -import {Event as PBEvent, EventProperties_MessageProperties_Role} from './buf/event_pb'; +import { + Event as PBEvent, + EventProperties_MessageProperties_Role +} from './buf/event_pb'; import {defaultAssistantId} from "./consts"; +import {CustomProperties, serializeCustomProperties} from "./utils"; export interface Event { toPB(): PBEvent; @@ -12,6 +16,7 @@ export interface OpenSessionEventProps { userId: string; assistantId?: string; sessionTitle?: string; + customProperties?: CustomProperties; } export class OpenSessionEvent implements Event { @@ -31,7 +36,8 @@ export class OpenSessionEvent implements Event { userId: props.userId, assistantId: props.assistantId ?? defaultAssistantId, }, - } + }, + customProperties: props.customProperties ? serializeCustomProperties(props.customProperties) : undefined, } }); } @@ -46,6 +52,7 @@ export interface CreateMessageEventProps { messageIndex: number; messageRole: 'user' | 'assistant'; messageContent: string; + customProperties?: CustomProperties; } export class CreateMessageEvent implements Event { @@ -64,7 +71,8 @@ export class CreateMessageEvent implements Event { messageRole: props.messageRole === 'user' ? EventProperties_MessageProperties_Role.USER : EventProperties_MessageProperties_Role.ASSISTANT, messageContent: props.messageContent, }, - } + }, + customProperties: props.customProperties ? serializeCustomProperties(props.customProperties) : undefined, } }); } diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..16d5129 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,13 @@ +import {EventProperties_CustomPropertyValue} from "./buf/event_pb"; + +export type CustomProperties = Record; + +export function serializeCustomProperties(props: CustomProperties) { + return Object.entries(props).reduce((acc, [key, value]) => { + if (typeof value === 'string') { + acc[key] = EventProperties_CustomPropertyValue.fromJson({stringValue: value}); + } + + return acc; + }, {} as Record); +} \ No newline at end of file From 21648e45dd7b9c454aae017f437c7e4b0394a94d Mon Sep 17 00:00:00 2001 From: nyanxyz Date: Wed, 13 Mar 2024 11:32:09 +0900 Subject: [PATCH 2/5] add customProperties to IdentifyUser event --- src/events.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/events.ts b/src/events.ts index 00fc1eb..fea0b0c 100644 --- a/src/events.ts +++ b/src/events.ts @@ -116,6 +116,7 @@ export interface IdentifyUserEventProps { userIp?: string; userCountryCode?: string; userCreateTime?: Date; + customProperties?: CustomProperties; } export class IdentifyUserEvent implements Event { @@ -138,7 +139,8 @@ export class IdentifyUserEvent implements Event { } : undefined, userCreateTime: props.userCreateTime ? Timestamp.fromDate(props.userCreateTime) : Timestamp.now(), }, - } + }, + customProperties: props.customProperties ? serializeCustomProperties(props.customProperties) : undefined, } }); } From be8a9af50aabedceb4cf291622cb9f15f1b7e9d4 Mon Sep 17 00:00:00 2001 From: nyanxyz Date: Thu, 14 Mar 2024 10:55:33 +0900 Subject: [PATCH 3/5] update dependency versions --- package.json | 4 ++-- pnpm-lock.yaml | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index ec6f877..925cd8e 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ }, "dependencies": { "@bufbuild/protobuf": "^1.7.2", - "@connectrpc/connect": "^1.3.0", - "@connectrpc/connect-node": "^1.3.0", + "@connectrpc/connect": "^1.4.0", + "@connectrpc/connect-node": "^1.4.0", "uuid": "^9.0.1" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c88dfe9..66b42b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,11 +9,11 @@ dependencies: specifier: ^1.7.2 version: 1.7.2 '@connectrpc/connect': - specifier: ^1.3.0 - version: 1.3.0(@bufbuild/protobuf@1.7.2) + specifier: ^1.4.0 + version: 1.4.0(@bufbuild/protobuf@1.7.2) '@connectrpc/connect-node': - specifier: ^1.3.0 - version: 1.3.0(@bufbuild/protobuf@1.7.2)(@connectrpc/connect@1.3.0) + specifier: ^1.4.0 + version: 1.4.0(@bufbuild/protobuf@1.7.2)(@connectrpc/connect@1.4.0) uuid: specifier: ^9.0.1 version: 9.0.1 @@ -52,20 +52,20 @@ packages: resolution: {integrity: sha512-i5GE2Dk5ekdlK1TR7SugY4LWRrKSfb5T1Qn4unpIMbfxoeGKERKQ59HG3iYewacGD10SR7UzevfPnh6my4tNmQ==} dev: false - /@connectrpc/connect-node@1.3.0(@bufbuild/protobuf@1.7.2)(@connectrpc/connect@1.3.0): - resolution: {integrity: sha512-2fV/z/8MUFOkTn2Gbm7T/qvRfkpt/D/w7ykYqACZRH6VNG/faY4lH2wUZiNkwv9tzTrECKOJFyPsaGs3nRYK3w==} + /@connectrpc/connect-node@1.4.0(@bufbuild/protobuf@1.7.2)(@connectrpc/connect@1.4.0): + resolution: {integrity: sha512-0ANnrr6SvsjevsWEgdzHy7BaHkluZyS6s4xNoVt7RBHFR5V/kT9lPokoIbYUOU9JHzdRgTaS3x5595mwUsu15g==} engines: {node: '>=16.0.0'} peerDependencies: '@bufbuild/protobuf': ^1.4.2 - '@connectrpc/connect': 1.3.0 + '@connectrpc/connect': 1.4.0 dependencies: '@bufbuild/protobuf': 1.7.2 - '@connectrpc/connect': 1.3.0(@bufbuild/protobuf@1.7.2) + '@connectrpc/connect': 1.4.0(@bufbuild/protobuf@1.7.2) undici: 5.28.3 dev: false - /@connectrpc/connect@1.3.0(@bufbuild/protobuf@1.7.2): - resolution: {integrity: sha512-kTeWxJnLLtxKc2ZSDN0rIBgwfP8RwcLknthX4AKlIAmN9ZC4gGnCbwp+3BKcP/WH5c8zGBAWqSY3zeqCM+ah7w==} + /@connectrpc/connect@1.4.0(@bufbuild/protobuf@1.7.2): + resolution: {integrity: sha512-vZeOkKaAjyV4+RH3+rJZIfDFJAfr+7fyYr6sLDKbYX3uuTVszhFe9/YKf5DNqrDb5cKdKVlYkGn6DTDqMitAnA==} peerDependencies: '@bufbuild/protobuf': ^1.4.2 dependencies: From 9d38406e1ad7d69bc267ecf92fad6ac73e17fd5f Mon Sep 17 00:00:00 2001 From: nyanxyz Date: Thu, 14 Mar 2024 10:56:06 +0900 Subject: [PATCH 4/5] move the CustomProperties type to event.ts --- src/events.ts | 4 +++- src/utils.ts | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/events.ts b/src/events.ts index fea0b0c..64c1c76 100644 --- a/src/events.ts +++ b/src/events.ts @@ -5,12 +5,14 @@ import { EventProperties_MessageProperties_Role } from './buf/event_pb'; import {defaultAssistantId} from "./consts"; -import {CustomProperties, serializeCustomProperties} from "./utils"; +import {serializeCustomProperties} from "./utils"; export interface Event { toPB(): PBEvent; } +export type CustomProperties = Record; + export interface OpenSessionEventProps { sessionId: string; userId: string; diff --git a/src/utils.ts b/src/utils.ts index 16d5129..bf9c4c3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,5 @@ import {EventProperties_CustomPropertyValue} from "./buf/event_pb"; - -export type CustomProperties = Record; +import {CustomProperties} from "./events"; export function serializeCustomProperties(props: CustomProperties) { return Object.entries(props).reduce((acc, [key, value]) => { From c69438a759aea47e4bd6bc5992259015af902562 Mon Sep 17 00:00:00 2001 From: nyanxyz Date: Thu, 14 Mar 2024 11:33:59 +0900 Subject: [PATCH 5/5] add type similar to sdk-edge --- src/events.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/events.ts b/src/events.ts index 64c1c76..a0ddb4e 100644 --- a/src/events.ts +++ b/src/events.ts @@ -11,7 +11,8 @@ export interface Event { toPB(): PBEvent; } -export type CustomProperties = Record; +export type CustomPropertyValue = string; +export type CustomProperties = Record; export interface OpenSessionEventProps { sessionId: string;