-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d7fb25
commit cac93e1
Showing
10 changed files
with
268 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OPENAI_API_KEY="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" |
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 |
---|---|---|
|
@@ -142,3 +142,7 @@ | |
height: 20px; | ||
width: 20px; | ||
} | ||
|
||
.layer-copilot { | ||
opacity: 0.5; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { clear as svgClear } from 'tiny-svg'; | ||
|
||
export default class Copilot { | ||
constructor( | ||
canvas, | ||
createPreview, | ||
directEditing, | ||
eventBus, | ||
keyboard, | ||
modeling, | ||
selection) { | ||
this._canvas = canvas; | ||
this._createPreview = createPreview; | ||
this._directEditing = directEditing; | ||
this._modeling = modeling; | ||
this._selection = selection; | ||
|
||
eventBus.on('selection.changed', (context) => { | ||
const { newSelection } = context; | ||
|
||
this.clearSuggestion(); | ||
|
||
if (newSelection.length === 1) { | ||
this.makeSuggestion(newSelection[ 0 ]); | ||
} | ||
}); | ||
|
||
eventBus.on('directEditing.activate', () => { | ||
this.hideSuggestion(); | ||
}); | ||
|
||
eventBus.on('directEditing.deactivate', () => { | ||
this.showSuggestion(); | ||
}); | ||
|
||
keyboard.addListener((context) => { | ||
if (context.keyEvent.key === 'Tab') { | ||
context.keyEvent.preventDefault(); | ||
|
||
this.acceptSuggestion(); | ||
} else if (context.keyEvent.key === 'Escape') { | ||
this.clearSuggestion(); | ||
} | ||
}); | ||
|
||
this._suggestion = null; | ||
|
||
this._layer = canvas.getLayer('copilot', 1000); | ||
} | ||
|
||
acceptSuggestion() { | ||
console.log('acceptSuggestion'); | ||
|
||
if (!this._suggestion) { | ||
return; | ||
} | ||
|
||
const { | ||
elements, | ||
position, | ||
target | ||
} = this._suggestion; | ||
|
||
const createdElements = this._modeling.createElements(elements, position, target, { | ||
position: 'absolute' | ||
}); | ||
|
||
this.clearSuggestion(); | ||
|
||
if (createdElements.length === 1) { | ||
this._selection.select(createdElements[ 0 ]); | ||
|
||
this._directEditing.activate(createdElements[ 0 ]); | ||
} | ||
} | ||
|
||
makeSuggestion(element) { | ||
console.log('makeSuggestion'); | ||
|
||
const suggestion = this._suggestion = this.createSuggestion(element); | ||
|
||
console.log('suggestion', suggestion); | ||
|
||
if (!suggestion) { | ||
return; | ||
} | ||
|
||
const { elements } = suggestion; | ||
|
||
const group = this._createPreview.createPreview(elements); | ||
|
||
this._layer.appendChild(group); | ||
} | ||
|
||
showSuggestion() { | ||
console.log('showSuggestion'); | ||
|
||
this._canvas.showLayer('copilot'); | ||
} | ||
|
||
hideSuggestion() { | ||
console.log('hideSuggestion'); | ||
|
||
this._canvas.hideLayer('copilot'); | ||
} | ||
|
||
clearSuggestion() { | ||
console.log('clearSuggestion'); | ||
|
||
this._suggestion = null; | ||
|
||
svgClear(this._layer); | ||
} | ||
|
||
createSuggestion(element) { | ||
console.log('createSuggestion'); | ||
|
||
if (!this._provider) { | ||
return null; | ||
} | ||
|
||
return this._provider.createSuggestion(element); | ||
} | ||
|
||
setProvider(provider) { | ||
this._provider = provider; | ||
} | ||
} | ||
|
||
Copilot.$inject = [ | ||
'canvas', | ||
'createPreview', | ||
'directEditing', | ||
'eventBus', | ||
'keyboard', | ||
'modeling', | ||
'selection' | ||
]; |
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,43 @@ | ||
import { is } from '../../util/ModelUtil'; | ||
|
||
import { getMid } from 'diagram-js/lib/layout/LayoutUtil'; | ||
|
||
const apiKey = process.env.OPENAI_API_KEY; | ||
Check failure on line 5 in lib/features/copilot/OpenAIProvider.js GitHub Actions / Build (ubuntu-20.04)
|
||
|
||
export default class OpenAIProvider { | ||
constructor(copilot, elementFactory) { | ||
copilot.setProvider(this); | ||
|
||
this._elementFactory = elementFactory; | ||
} | ||
|
||
createSuggestion(element) { | ||
const suggestion = { | ||
elements: [], | ||
position: null, | ||
target: element.parent | ||
}; | ||
|
||
const mid = getMid(element); | ||
|
||
if (is(element, 'bpmn:Task')) { | ||
return { | ||
...suggestion, | ||
elements: [ | ||
this._elementFactory.createShape({ | ||
type: 'bpmn:Task', | ||
x: element.x + element.width + 100, | ||
y: element.y | ||
}) | ||
] | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
OpenAIProvider.$inject = [ | ||
'copilot', | ||
'elementFactory' | ||
]; |
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,15 @@ | ||
import Copilot from './Copilot'; | ||
import OpenAIProvider from './OpenAIProvider'; | ||
|
||
export default { | ||
__depends__: [ | ||
|
||
// TODO | ||
], | ||
__init__: [ | ||
'copilot', | ||
'openaiprovider' | ||
], | ||
copilot: [ 'type', Copilot ], | ||
openaiprovider: [ 'type', OpenAIProvider ] | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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