-
Notifications
You must be signed in to change notification settings - Fork 197
Add internal attributes definition helper #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ docs/ | |
node_modules/ | ||
protocol/ | ||
src/proto/ | ||
src/room/attributes/ | ||
yarn.lock | ||
pnpm-lock.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// This file is auto-generated. Do not edit manually. | ||
|
||
const AgentStateAttribute = { | ||
key: "lk.agent.state", | ||
values: ["initializing", "idle", "listening", "thinking", "speaking"], | ||
default: "idle", | ||
} as const; | ||
|
||
const PublishOnBehalfAttribute = { | ||
key: "lk.publish_on_behalf", | ||
values: [], // Any string value allowed | ||
default: null, | ||
} as const; | ||
|
||
export const AgentAttributesRegistry = [ | ||
AgentStateAttribute, | ||
PublishOnBehalfAttribute, | ||
] as const; | ||
|
||
/** | ||
* Agent connection state | ||
*/ | ||
export type AgentStateType = (typeof AgentStateAttribute.values)[number]; | ||
/** | ||
* The identity of the user that the agent is publishing on behalf of | ||
*/ | ||
export type PublishOnBehalfType = string; | ||
|
||
export interface AgentAttributes { | ||
/** | ||
* Agent connection state | ||
*/ | ||
[AgentStateAttribute.key]?: AgentStateType; | ||
/** | ||
* The identity of the user that the agent is publishing on behalf of | ||
*/ | ||
[PublishOnBehalfAttribute.key]?: PublishOnBehalfType; | ||
} | ||
|
||
/** | ||
* Parse a raw attribute map into a typed AgentAttributesRegistry | ||
* @param attributes Raw attribute map (key-value pairs) | ||
* @returns Typed AgentAttributes | ||
*/ | ||
export function parseAgentAttributes( | ||
attributes: Record<string, string> | ||
): AgentAttributes { | ||
const result: AgentAttributes = {}; | ||
|
||
// First add default values from registry | ||
for (const attribute of AgentAttributesRegistry) { | ||
if (attribute.default !== null) { | ||
result[attribute.key] = attribute.default as any; | ||
} | ||
} | ||
|
||
// Then override with provided values | ||
for (const [key, value] of Object.entries(attributes)) { | ||
for (const attribute of AgentAttributesRegistry) { | ||
if (key === attribute.key) { | ||
// For attributes with allowed values (non-empty array), validate the value | ||
if (attribute.values.length > 0 && !(attribute.values as readonly string[]).includes(value)) { | ||
// Skip invalid values | ||
continue; | ||
} | ||
result[key] = value as any; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as agent from './agent_attr'; | ||
import * as transcription from './transcription_attr'; | ||
|
||
export { agent, transcription }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// This file is auto-generated. Do not edit manually. | ||
|
||
const SegmentIdAttribute = { | ||
key: "lk.segment_id", | ||
values: [], // Any string value allowed | ||
default: null, | ||
} as const; | ||
|
||
const TranscribedTrackIdAttribute = { | ||
key: "lk.transcribed_track_id", | ||
values: [], // Any string value allowed | ||
default: null, | ||
} as const; | ||
|
||
const TranscriptionFinalAttribute = { | ||
key: "lk.transcription_final", | ||
values: ["true", "false"], | ||
default: null, | ||
} as const; | ||
|
||
export const TranscriptionAttributesRegistry = [ | ||
SegmentIdAttribute, | ||
TranscribedTrackIdAttribute, | ||
TranscriptionFinalAttribute, | ||
] as const; | ||
|
||
/** | ||
* The segment id of the transcription | ||
*/ | ||
export type SegmentIdType = string; | ||
/** | ||
* The associated track id of the transcription | ||
*/ | ||
export type TranscribedTrackIdType = string; | ||
/** | ||
* Whether the transcription is final | ||
*/ | ||
export type TranscriptionFinalType = (typeof TranscriptionFinalAttribute.values)[number]; | ||
|
||
export interface TranscriptionAttributes { | ||
/** | ||
* The segment id of the transcription | ||
*/ | ||
[SegmentIdAttribute.key]?: SegmentIdType; | ||
/** | ||
* The associated track id of the transcription | ||
*/ | ||
[TranscribedTrackIdAttribute.key]?: TranscribedTrackIdType; | ||
/** | ||
* Whether the transcription is final | ||
*/ | ||
[TranscriptionFinalAttribute.key]?: TranscriptionFinalType; | ||
} | ||
|
||
/** | ||
* Parse a raw attribute map into a typed TranscriptionAttributesRegistry | ||
* @param attributes Raw attribute map (key-value pairs) | ||
* @returns Typed TranscriptionAttributes | ||
*/ | ||
export function parseTranscriptionAttributes( | ||
attributes: Record<string, string> | ||
): TranscriptionAttributes { | ||
const result: TranscriptionAttributes = {}; | ||
|
||
// First add default values from registry | ||
for (const attribute of TranscriptionAttributesRegistry) { | ||
if (attribute.default !== null) { | ||
result[attribute.key] = attribute.default as any; | ||
} | ||
} | ||
|
||
// Then override with provided values | ||
for (const [key, value] of Object.entries(attributes)) { | ||
for (const attribute of TranscriptionAttributesRegistry) { | ||
if (key === attribute.key) { | ||
// For attributes with allowed values (non-empty array), validate the value | ||
if (attribute.values.length > 0 && !(attribute.values as readonly string[]).includes(value)) { | ||
// Skip invalid values | ||
continue; | ||
} | ||
result[key] = value as any; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the auto-generation occurs elsewhere, maybe worth updating these comments with a link to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, currently restructuring the code gen anyways to support JSON parsing so holding off until that's done