-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat(grain): migrate to v2 API, add get-transcript and list-recordings actions #21855
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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
45 changes: 45 additions & 0 deletions
45
components/grain/actions/get-transcript/get-transcript.mjs
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,45 @@ | ||
| import { TRANSCRIPT_FORMAT_OPTIONS } from "../../common/constants.mjs"; | ||
| import grain from "../../grain.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "grain-get-transcript", | ||
| name: "Get Transcript", | ||
| description: "Fetches the full transcript of a Grain recording." | ||
| + " The `json` format returns structured segments with speaker, participant ID, start/end times in milliseconds, and text;" | ||
| + " `txt`, `vtt`, and `srt` return plain text or subtitle formats." | ||
| + " Use **List Recordings** to find recording IDs; use **Get Recording** for the recording's metadata instead of its transcript." | ||
| + " [See the documentation](https://developers.grain.com)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| grain, | ||
| recordingId: { | ||
| propDefinition: [ | ||
| grain, | ||
| "recordingId", | ||
| ], | ||
| }, | ||
| format: { | ||
| type: "string", | ||
| label: "Format", | ||
| description: "Format for the transcript", | ||
| options: TRANSCRIPT_FORMAT_OPTIONS, | ||
| default: "json", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.grain.fetchTranscript({ | ||
| $, | ||
| recordingId: this.recordingId, | ||
| format: this.format, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully fetched transcript for recording ${this.recordingId}`); | ||
| return response; | ||
| }, | ||
| }; |
91 changes: 91 additions & 0 deletions
91
components/grain/actions/list-recordings/list-recordings.mjs
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,91 @@ | ||
| import grain from "../../grain.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "grain-list-recordings", | ||
| name: "List Recordings", | ||
| description: "Lists Grain recordings, optionally filtered by start datetime range (ISO8601), title search, or participant scope." | ||
| + " Automatically paginates and returns up to Max Results recordings." | ||
| + " Use this to find recording IDs for **Get Recording** and **Get Transcript**." | ||
| + " [See the documentation](https://developers.grain.com)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| grain, | ||
| beforeDatetime: { | ||
| type: "string", | ||
| label: "Before Datetime", | ||
| description: "Only return recordings that started before this ISO8601 datetime. E.g. `2025-01-01T00:00:00Z`", | ||
| optional: true, | ||
| }, | ||
| afterDatetime: { | ||
| type: "string", | ||
| label: "After Datetime", | ||
| description: "Only return recordings that started after this ISO8601 datetime. E.g. `2025-01-01T00:00:00Z`", | ||
| optional: true, | ||
| }, | ||
| titleSearch: { | ||
| type: "string", | ||
| label: "Title Search", | ||
| description: "Only return recordings whose title matches this search string", | ||
| optional: true, | ||
| }, | ||
| participantScope: { | ||
| type: "string", | ||
| label: "Participant Scope", | ||
| description: "Only return recordings whose participants are all internal, or that include external participants", | ||
| options: [ | ||
| "internal", | ||
| "external", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "Maximum number of recordings to return. Must be a positive integer.", | ||
| optional: true, | ||
| default: 100, | ||
| min: 1, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const filter = { | ||
| before_datetime: this.beforeDatetime, | ||
| after_datetime: this.afterDatetime, | ||
| title_search: this.titleSearch, | ||
| participant_scope: this.participantScope, | ||
| }; | ||
|
|
||
| const recordings = []; | ||
| let cursor; | ||
| do { | ||
| const { | ||
| recordings: page, cursor: nextCursor, | ||
| } = await this.grain.listRecordings({ | ||
| $, | ||
| data: { | ||
| cursor, | ||
| filter: Object.fromEntries(Object.entries(filter).filter(([ | ||
| , value, | ||
| ]) => value !== undefined)), | ||
| }, | ||
| }); | ||
| recordings.push(...page); | ||
| cursor = nextCursor; | ||
| } while (cursor && recordings.length < this.maxResults); | ||
|
|
||
| if (recordings.length > this.maxResults) { | ||
| recordings.length = this.maxResults; | ||
| } | ||
|
|
||
| $.export("$summary", `Successfully fetched ${recordings.length} recording${recordings.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| return recordings; | ||
| }, | ||
| }; | ||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.