-
Notifications
You must be signed in to change notification settings - Fork 467
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
Feature: AI Node and AI Actions extension #26055
Merged
fmontes
merged 62 commits into
dotCMS:nikolatrajkovic24-feature-ai-node-and-ai-actions
from
unknown repository
Oct 18, 2023
Merged
Changes from 59 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
8909420
Created AI content node
e9fdb40
Merge branch 'master' into new-extension-user-input-chatgpt
4cc7f6a
Created ai-content-service
b1ddbb7
Created AI prompt content extension
13c2932
Merge branch 'master' into new-extension-user-input-chatgpt
ea9977f
Update ai-content.service.ts
da83c59
Optimised and aligned extension code
b7893bb
Resolved comments on PR
91338b6
Removed ai content node file
bceda9b
Update ai-content.service.ts
8116d58
Remove import path for ai-content-node
ac18c95
Updated the ai-prompt form
4156879
align ai text prompt extension
db3efe5
Resovled comments on pull
52e9666
Fix the aiTextPrompt form
70f8297
Updated extension related code
77c70b6
Update ai-content-prompt.plugin.ts
3c79581
Remove some extra code
46a61a8
Fixed outside click for aiContentPrompt extension
nikolaPhy b42a2c3
Created ai content node
nikolaPhy 155773d
Updated ai-content node
nikolaPhy 02b292b
Remove unused code, resolve comments on PR
nikolaPhy 2c832e9
Merge branch 'master' into new-extension-user-input-chatgpt
nikolaPhy ef90d31
ai-content-prompt extension code optimisation
nikolaPhy b6a937f
Update ai-content-prompt.plugin.ts
nikolaPhy f05105e
Integrated with AI api
nikolaPhy bc86f8f
Merge branch 'master' into new-extension-user-input-chatgpt
nikolaPhy 55a0b18
Merge branch 'new-extension-user-input-chatgpt' into feature/ai-conte…
nikolaPhy 9d5f721
insert ai node on response
nikolaPhy 8cab5ca
textPrompt extension code optimsation
nikolaPhy 772a0fc
Update ai-content.service.ts
nikolaPhy c41b9d9
Resolve comments on pull req
nikolaPhy 60e7337
handle close extension on outside click and content flip fix
nikolaPhy 60f81dd
Added focus field method and type for form
nikolaPhy 94c6590
Merge branch 'master' into new-extension-user-input-chatgpt
nikolaPhy 69a4e02
Merge branch 'new-extension-user-input-chatgpt' into feature/ai-conte…
nikolaPhy b62772e
Change name of ai node creation command
nikolaPhy aa15c03
Update the ai-content icon in the actions menu list
nikolaPhy ff7f3df
Update ai-content-prompt.component.scss
nikolaPhy e18759a
Resolved comments on pull
nikolaPhy 18039c7
Merge branch 'new-extension-user-input-chatgpt' into feature/ai-conte…
nikolaPhy 921e046
Added pening status and update the name of destroy var
nikolaPhy 6548c71
Merge branch 'master' into new-extension-user-input-chatgpt
nikolaPhy 0ace3d7
Merge branch 'new-extension-user-input-chatgpt' into feature/ai-conte…
nikolaPhy daac750
Implement ai-content-actions extension
2d684d6
ai-prompt extension code optimisation
b62bd26
Merge branch 'master' into new-extension-user-input-chatgpt
9a22cf7
Merge branch 'new-extension-user-input-chatgpt' into feature-ai-node-…
23c2352
ai-text-prompt block optimisation
a813fda
Merge branch 'master' into feature-ai-node-and-ai-actions
7080f85
Merge branch 'master' into feature-ai-node-and-ai-actions
3d54ccb
Update main.ts
31040f9
Resolve comments on pull
873e577
Merge branch 'master' into feature-ai-node-and-ai-actions
11db56b
Resolve comments on PR
9d6fc34
Merge branch 'master' into feature-ai-node-and-ai-actions
cb1b706
Code optimisation for ai-content-actions extension
2a33515
Fix css for p-listbox
663bec8
Merge branch 'master' into feature-ai-node-and-ai-actions
679ae0e
Merge branch 'master' into feature-ai-node-and-ai-actions
fd1f7a3
Merge branch 'master' into feature-ai-node-and-ai-actions
fmontes cfbd93b
Merge branch 'master' into feature-ai-node-and-ai-actions
wezell 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 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 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 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 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
8 changes: 8 additions & 0 deletions
8
...libs/block-editor/src/lib/extensions/ai-content-actions/ai-content-actions.component.html
This file contains 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,8 @@ | ||
<p-listbox [options]="actionOptions" (onClick)="$event.value.callback()"> | ||
<ng-template let-actionOption pTemplate="item"> | ||
<div class="action-content"> | ||
<i [class]="actionOption.icon"></i> | ||
{{ actionOption.label }} | ||
</div> | ||
</ng-template> | ||
</p-listbox> |
47 changes: 47 additions & 0 deletions
47
...libs/block-editor/src/lib/extensions/ai-content-actions/ai-content-actions.component.scss
This file contains 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,47 @@ | ||
@use "variables" as *; | ||
|
||
:host ::ng-deep { | ||
.p-listbox { | ||
display: block; | ||
width: 12.5rem; | ||
padding: $spacing-1; | ||
margin-left: $spacing-8; | ||
|
||
li { | ||
padding: $spacing-2 $spacing-3; | ||
|
||
// accept option | ||
&:first-child { | ||
background-color: $color-palette-primary-200; | ||
} | ||
|
||
// regenerate option | ||
&:nth-child(2) { | ||
padding: $spacing-3; | ||
background-color: $white !important; | ||
} | ||
|
||
// delete option | ||
&:last-child { | ||
border-top: 1px solid $color-palette-gray-300; | ||
background-color: $white !important; | ||
} | ||
|
||
&:hover { | ||
background-color: $color-palette-primary-100; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.action-content { | ||
display: flex; | ||
align-items: center; | ||
color: $black; | ||
|
||
// list option icon | ||
i { | ||
margin-right: $spacing-0; | ||
color: $color-palette-gray-600; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...s/block-editor/src/lib/extensions/ai-content-actions/ai-content-actions.component.spec.ts
This file contains 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,28 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
|
||
import { AIContentActionsComponent } from './ai-content-actions.component'; | ||
|
||
import { AiContentService } from '../../shared'; | ||
|
||
describe('AIContentActionsComponent', () => { | ||
let component: AIContentActionsComponent; | ||
let fixture: ComponentFixture<AIContentActionsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ReactiveFormsModule, HttpClientTestingModule], | ||
declarations: [AIContentActionsComponent], | ||
providers: [AiContentService] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AIContentActionsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
...b/libs/block-editor/src/lib/extensions/ai-content-actions/ai-content-actions.component.ts
This file contains 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,72 @@ | ||
import { Observable, of } from 'rxjs'; | ||
|
||
import { Component, EventEmitter, Output, OnInit } from '@angular/core'; | ||
|
||
import { AiContentService } from '../../shared/services/ai-content/ai-content.service'; | ||
|
||
interface ActionOption { | ||
label: string; | ||
icon: string; | ||
selectedOption: boolean; | ||
callback: () => void; | ||
} | ||
|
||
export enum ACTIONS { | ||
ACCEPT = 'ACCEPT', | ||
DELETE = 'DELETE', | ||
REGENERATE = 'REGENERATE' | ||
} | ||
|
||
@Component({ | ||
selector: 'dot-ai-content-actions', | ||
templateUrl: './ai-content-actions.component.html', | ||
styleUrls: ['./ai-content-actions.component.scss'] | ||
}) | ||
export class AIContentActionsComponent implements OnInit { | ||
@Output() actionEmitter = new EventEmitter<ACTIONS>(); | ||
|
||
actionOptions!: ActionOption[]; | ||
|
||
constructor(private aiContentService: AiContentService) {} | ||
|
||
ngOnInit() { | ||
this.actionOptions = [ | ||
{ | ||
label: 'Accept', | ||
rjvelazco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
icon: 'pi pi-check', | ||
callback: () => this.emitAction(ACTIONS.ACCEPT), | ||
selectedOption: true | ||
}, | ||
{ | ||
label: 'Regenerate', | ||
icon: 'pi pi-sync', | ||
callback: () => this.emitAction(ACTIONS.REGENERATE), | ||
selectedOption: false | ||
}, | ||
{ | ||
label: 'Delete', | ||
icon: 'pi pi-trash', | ||
callback: () => this.emitAction(ACTIONS.DELETE), | ||
selectedOption: false | ||
} | ||
]; | ||
} | ||
|
||
private emitAction(action: ACTIONS) { | ||
this.actionEmitter.emit(action); | ||
} | ||
|
||
getLatestContent() { | ||
return this.aiContentService.getLastContentResponse(); | ||
} | ||
|
||
getNewContent(): Observable<string> { | ||
const promptToUse: string = this.aiContentService.getLastUsedPrompt(); | ||
|
||
if (promptToUse) { | ||
return this.aiContentService.getIAContent(promptToUse); | ||
} | ||
|
||
return of(''); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...b/libs/block-editor/src/lib/extensions/ai-content-actions/ai-content-actions.extension.ts
This file contains 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,84 @@ | ||
import { PluginKey } from 'prosemirror-state'; | ||
import { Props } from 'tippy.js'; | ||
|
||
import { ViewContainerRef } from '@angular/core'; | ||
|
||
import { Extension } from '@tiptap/core'; | ||
|
||
import { AIContentActionsComponent } from './ai-content-actions.component'; | ||
import { aiContentActionsPlugin } from './plugins/ai-content-actions.plugin'; | ||
|
||
export interface AIContentActionsOptions { | ||
pluginKey: PluginKey; | ||
tippyOptions?: Partial<Props>; | ||
element: HTMLElement | null; | ||
} | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
AIContentActions: { | ||
openAIContentActions: () => ReturnType; | ||
closeAIContentActions: () => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
export const AI_CONTENT_ACTIONS_PLUGIN_KEY = new PluginKey('aiContentActions-form'); | ||
|
||
export const AIContentActionsExtension = (viewContainerRef: ViewContainerRef) => { | ||
return Extension.create<AIContentActionsOptions>({ | ||
name: 'aiContentActions', | ||
|
||
addOptions() { | ||
return { | ||
element: null, | ||
tippyOptions: {}, | ||
pluginKey: AI_CONTENT_ACTIONS_PLUGIN_KEY | ||
}; | ||
}, | ||
|
||
addCommands() { | ||
return { | ||
openAIContentActions: | ||
() => | ||
({ chain }) => { | ||
return chain() | ||
.command(({ tr }) => { | ||
tr.setMeta(AI_CONTENT_ACTIONS_PLUGIN_KEY, { open: true }); | ||
|
||
return true; | ||
}) | ||
.freezeScroll(true) | ||
.run(); | ||
}, | ||
closeAIContentActions: | ||
() => | ||
({ chain }) => { | ||
return chain() | ||
.command(({ tr }) => { | ||
tr.setMeta(AI_CONTENT_ACTIONS_PLUGIN_KEY, { open: false }); | ||
|
||
return true; | ||
}) | ||
.freezeScroll(false) | ||
.run(); | ||
} | ||
}; | ||
}, | ||
|
||
addProseMirrorPlugins() { | ||
const component = viewContainerRef.createComponent(AIContentActionsComponent); | ||
component.changeDetectorRef.detectChanges(); | ||
|
||
return [ | ||
aiContentActionsPlugin({ | ||
pluginKey: this.options.pluginKey, | ||
editor: this.editor, | ||
element: component.location.nativeElement, | ||
tippyOptions: this.options.tippyOptions, | ||
component: component | ||
}) | ||
]; | ||
} | ||
}); | ||
}; |
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.
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.
Maybe @fmontes can help you get rid of this
!important
;