Skip to content
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

feat: Add Ask assistant behind feature flag #9995

Merged
merged 216 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 212 commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
ef2ecae
feat: Add ask assistant button
mutdmour Jul 9, 2024
bee38b6
feat: add button states
mutdmour Jul 10, 2024
3cb05eb
chore: add todo
mutdmour Jul 10, 2024
8839b80
feat: add chat compponent
mutdmour Jul 10, 2024
487bb73
feat: rework button
mutdmour Jul 10, 2024
4dcc7c9
feat: rework chat
mutdmour Jul 10, 2024
fe219c5
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 10, 2024
d9ccb53
feat: update chat
mutdmour Jul 10, 2024
74f4630
feat: fix up header
mutdmour Jul 10, 2024
821b5a0
feat: add resizing
mutdmour Jul 10, 2024
64b1c52
feat: try to add resizing
mutdmour Jul 10, 2024
9160360
feat: add more features to chat
mutdmour Jul 11, 2024
271b628
feat: add code section
mutdmour Jul 11, 2024
9f79f3e
feat: add block section
mutdmour Jul 11, 2024
48660ac
feat: add min/max height for code sec
mutdmour Jul 11, 2024
ca7d264
feat: add floating button
mutdmour Jul 11, 2024
5ca2cf9
feat: add closing button
mutdmour Jul 11, 2024
c4d55c2
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 12, 2024
b2096f6
fix: clean up
mutdmour Jul 12, 2024
7f62b8a
feat: reposition buttons
mutdmour Jul 12, 2024
9957923
fix: hide button if open
mutdmour Jul 12, 2024
59d6bae
fix: show button
mutdmour Jul 12, 2024
7f22c7c
fix: hover state
mutdmour Jul 12, 2024
80a8f75
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 12, 2024
fafc03f
feat: add num notification
mutdmour Jul 12, 2024
79c1c5a
feat: add asked state
mutdmour Jul 12, 2024
47b428c
feat: add input
mutdmour Jul 12, 2024
844debb
feat: fix up spacing
mutdmour Jul 12, 2024
3d941d3
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 15, 2024
73127d9
feat: add more code diff features
mutdmour Jul 15, 2024
046b9d6
feat: change structure
mutdmour Jul 15, 2024
c5b8bb6
feat: add api setup
mutdmour Jul 15, 2024
7f9c56c
feat: handle error state
mutdmour Jul 15, 2024
0c356f4
feat: hide on pages
mutdmour Jul 16, 2024
8d3a810
feat: make banner full height
mutdmour Jul 16, 2024
6e24a32
feat: add more e2e functionality
mutdmour Jul 16, 2024
9047e4c
feat: hide on pages
mutdmour Jul 16, 2024
b1c6662
fix: add todo
mutdmour Jul 16, 2024
0740ece
feat: Add AI assistant SDK (#10078)
RicardoE105 Jul 17, 2024
3bb3999
feat: update config
mutdmour Jul 17, 2024
fd69a0e
feat: update store
mutdmour Jul 17, 2024
1b55b34
feat: update store
mutdmour Jul 17, 2024
daf7e4e
feat: handle enabled env
mutdmour Jul 17, 2024
9c58d6c
feat: add service base
mutdmour Jul 17, 2024
0cde5d6
feat: handle errors better
mutdmour Jul 17, 2024
c25f35e
feat: add streaming effect
mutdmour Jul 17, 2024
5f004f6
feat: add end of chat
mutdmour Jul 17, 2024
265d893
feat: add slide transition
mutdmour Jul 17, 2024
80b339c
refactor: simplify types
mutdmour Jul 17, 2024
b11de1b
feat: move creator
mutdmour Jul 17, 2024
b634cd2
feat: offset notifications
mutdmour Jul 17, 2024
63732f8
fix: example
mutdmour Jul 17, 2024
333e2be
feat: add unordered example
mutdmour Jul 17, 2024
00283c2
fix: add static data, fix types
mutdmour Jul 17, 2024
d410cd1
fix: add static data, fix types
mutdmour Jul 17, 2024
a1d8977
fix: update types
mutdmour Jul 18, 2024
bf5c05f
feat: add streaming feat and code replace
mutdmour Jul 18, 2024
1a1d280
feat: add streaming
mutdmour Jul 19, 2024
4f8895c
feat: implement more interactions with api
mutdmour Jul 19, 2024
4980b8b
feat: update to summary message
mutdmour Jul 19, 2024
56398da
feat: update to summary message
mutdmour Jul 19, 2024
b10e893
feat: handle edge case
mutdmour Jul 19, 2024
f3000b8
feat: add id
mutdmour Jul 19, 2024
c527fb4
feat: add streaming to blocks
mutdmour Jul 19, 2024
934ad68
fix: if already asked, clickable after execution
mutdmour Jul 20, 2024
e58c243
refactor: clean up refactor
mutdmour Jul 20, 2024
a551ece
fix: undo/redo
mutdmour Jul 20, 2024
1a9ee6a
feat: add confirm on context change
mutdmour Jul 20, 2024
e26b4e9
feat: update chat
mutdmour Jul 22, 2024
fc26fbc
resolve conflict
mutdmour Jul 22, 2024
0509838
merge
mutdmour Jul 23, 2024
a91f354
feat: add updating code
mutdmour Jul 23, 2024
b73cdb5
feat: add event support
mutdmour Jul 23, 2024
290edd0
fix: full flow
mutdmour Jul 23, 2024
8a160cb
feat: add unread count
mutdmour Jul 23, 2024
ca84d1c
feat: add last unread notification
mutdmour Jul 23, 2024
f141d36
feat: support end of session event
mutdmour Jul 24, 2024
0f6aff4
feat: add debug log
mutdmour Jul 24, 2024
635cd01
fix: add type
mutdmour Jul 24, 2024
95240e2
fix: update config to match
mutdmour Jul 24, 2024
77b4d07
fix: bug with browserid
mutdmour Jul 24, 2024
9dfbd0f
fix: add request info
mutdmour Jul 24, 2024
c32438f
fix: add log
mutdmour Jul 24, 2024
2f21358
fix: add browser id to proxy
mutdmour Jul 24, 2024
1d2d493
fix: remove console log
mutdmour Jul 24, 2024
6b316cc
feat: Add tooltip styles
mutdmour Jul 24, 2024
72e379d
fix: hide quick replies title
mutdmour Jul 25, 2024
121883c
feat: increase id
mutdmour Jul 25, 2024
b0ec085
feat: fix session ended state
mutdmour Jul 25, 2024
7878f45
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 25, 2024
66810f1
fix: add back ai.enabled
mutdmour Jul 25, 2024
ec4d9f5
fix: add back ai.enabled
mutdmour Jul 25, 2024
56f17dd
refactor: remove commented out css
mutdmour Jul 25, 2024
7d3f480
refactor: clean up dead code
mutdmour Jul 25, 2024
8bf3cb6
refactor: clean up blinking cursor
mutdmour Jul 25, 2024
ef24b23
refactor: update code diff component
mutdmour Jul 25, 2024
5d41f10
refactor: comment
mutdmour Jul 25, 2024
ec28369
refactor: center text
mutdmour Jul 25, 2024
3a812a9
refactor: add more stories
mutdmour Jul 25, 2024
fb9f712
fix: import
mutdmour Jul 25, 2024
bf5663b
fix: update imports
mutdmour Jul 25, 2024
9a1b892
feat: add tokens
mutdmour Jul 25, 2024
777a4ec
feat: use css here
mutdmour Jul 25, 2024
2aa3695
feat: add tokens
mutdmour Jul 25, 2024
717ef6b
feat: add tokens
mutdmour Jul 25, 2024
3c13372
fix: clean up
mutdmour Jul 25, 2024
9b76ac3
fix: update colors
mutdmour Jul 25, 2024
bb9253e
feat: use css here
mutdmour Jul 25, 2024
ae7c5ce
refactor: clean up a bit
mutdmour Jul 25, 2024
87229bf
increase proxy timeout
RicardoE105 Jul 25, 2024
d19177f
feat: localization
mutdmour Jul 25, 2024
4cae156
Merge branch 'ask-assistant' of github.com:n8n-io/n8n into ask-assistant
mutdmour Jul 25, 2024
30ec59a
refactor: ask assistant component
mutdmour Jul 25, 2024
9c05c36
refactor: update tokens
mutdmour Jul 25, 2024
92275d0
fix: remove debug log
mutdmour Jul 25, 2024
9ab34fb
refactor: remove props
mutdmour Jul 25, 2024
fe9ec9c
refactor: update button
mutdmour Jul 25, 2024
a05871a
refactor: lint
mutdmour Jul 25, 2024
ace657c
refactor: localization
mutdmour Jul 25, 2024
9b896bd
💄 Fix diff background with horizontal overflow. Updating TODO comments
MiloradFilipovic Jul 26, 2024
c0ff350
🔨 Address design system type errors
MiloradFilipovic Jul 26, 2024
1efecaa
🔨 Fix typing errors in `editor-ui`
MiloradFilipovic Jul 29, 2024
496780d
🔨 Fix dependency cycle between stores
MiloradFilipovic Jul 29, 2024
949219f
Merge branch 'master' into ask-assistant
MiloradFilipovic Jul 29, 2024
107857c
✔️ Updating banner snapshots
MiloradFilipovic Jul 29, 2024
13c22e6
👕 Ignoring unbound method call warnign
MiloradFilipovic Jul 29, 2024
0798b3d
👕 Removing extra pipe in spinner props
MiloradFilipovic Jul 29, 2024
9bebc4f
👕 Fixing type imports in apiUtils
MiloradFilipovic Jul 29, 2024
c82cbb1
✨ Implemented new session confirm dialog
MiloradFilipovic Jul 29, 2024
67e637c
👕 Removing unused imports
MiloradFilipovic Jul 29, 2024
4c24b73
⚡ Hiding assistant button for custom nodes, fixing banner border in d…
MiloradFilipovic Jul 29, 2024
bde612e
👕 Breaking up long line
MiloradFilipovic Jul 30, 2024
b20f5a6
Merge branch 'master' into ask-assistant
MiloradFilipovic Jul 30, 2024
b14f453
✨ Added UI support for agent responses
MiloradFilipovic Jul 30, 2024
b97b0e4
bump ai assistant version to show logs
RicardoE105 Jul 30, 2024
660df7d
update packpage.lock
RicardoE105 Jul 30, 2024
d1c64e7
Merge branch 'master' into ask-assistant
RicardoE105 Jul 30, 2024
369cf06
bump sdk version
RicardoE105 Jul 30, 2024
0c04e76
bump sdk version
RicardoE105 Jul 30, 2024
d4fb138
add feature flag
RicardoE105 Jul 31, 2024
33f6fb8
Merge branch 'master' into ask-assistant
MiloradFilipovic Jul 31, 2024
0bad965
✨ Added referenced node schemas and authentication info to agent request
MiloradFilipovic Jul 31, 2024
c9eccd2
✔️ Fixing typing and lint errors
MiloradFilipovic Jul 31, 2024
b3bbf7a
bump sdk version
RicardoE105 Jul 31, 2024
87f301c
update pnpm lock file
RicardoE105 Jul 31, 2024
b977dd7
Rename referenceNodesData to executionSchema to match api definition
RicardoE105 Jul 31, 2024
a2408bb
💄 Adding margin around preview elements
MiloradFilipovic Aug 1, 2024
ff1b13d
⚡ Using `block` message type to display suggestions
MiloradFilipovic Aug 1, 2024
3d4a422
⚡ Added posthog experiment condition to assistant rendering
MiloradFilipovic Aug 1, 2024
eadcc5a
⚡ Removing excessive node properties before sending it to the assistant
MiloradFilipovic Aug 1, 2024
d7faf9d
💄 Implementing design review changes
MiloradFilipovic Aug 1, 2024
c65ab51
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 1, 2024
9b6fa8e
🐛 Fixing proxy endpoint config in cli
MiloradFilipovic Aug 1, 2024
ff30bf2
📈 Implemented telemetry events
MiloradFilipovic Aug 1, 2024
66cec8a
⚡ Only show streaming cursor in the last message
MiloradFilipovic Aug 2, 2024
59d2af5
Updating proxy timeout to 20s
MiloradFilipovic Aug 2, 2024
21ba59d
⚡ Only show assistant button if feature is enabled
MiloradFilipovic Aug 2, 2024
1bbbc81
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 2, 2024
827606e
✨ Implemented code editor flash when suggested code is applied
MiloradFilipovic Aug 4, 2024
a572adf
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 5, 2024
ff0a970
💄 Removing box-shadow animation when flashing code node
MiloradFilipovic Aug 5, 2024
66892c3
⚡ Drop messages from different sessions
MiloradFilipovic Aug 5, 2024
1d5c867
Get information about whether the AI assistant enabled or not from li…
RicardoE105 Aug 5, 2024
aec4e11
fix tests and include aiAssistant in settings
RicardoE105 Aug 5, 2024
12c4d18
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 6, 2024
a665167
💄 Tweaking code editor flash animatioin
MiloradFilipovic Aug 6, 2024
6fb55a4
⚡ Indicate streaming on events, fix suggestion count in telemetry
MiloradFilipovic Aug 6, 2024
3aeb87b
feat: update license key name
mutdmour Aug 6, 2024
9e641ed
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 6, 2024
695e5e3
⚡ Updating referenced node schema types according to backend types
MiloradFilipovic Aug 6, 2024
8c4bf4b
fix: On switching views, clear previous context
mutdmour Aug 6, 2024
b275889
fix: open link in new tab
mutdmour Aug 6, 2024
5a4b93f
fix: remove blinking
mutdmour Aug 7, 2024
626d57b
👌 Updating code review feedback
MiloradFilipovic Aug 7, 2024
cb8144b
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 7, 2024
a2b082e
Merge branch 'master' of github.com:n8n-io/n8n into ask-assistant
mutdmour Aug 8, 2024
d9ea858
🐛 Fixing Avatar initials rendering with missing first or last name
MiloradFilipovic Aug 8, 2024
7b983e1
feat: remove proxy
mutdmour Aug 8, 2024
32b89ac
feat: add client
mutdmour Aug 8, 2024
f4972bc
fix: type log level
mutdmour Aug 8, 2024
a4dfe5a
💄 Rebranding Assistant to Ava, updating some chat components styling
MiloradFilipovic Aug 8, 2024
8b7bfe9
feat: setup controller
mutdmour Aug 8, 2024
bfeb332
Merge branch 'ask-assistant' of github.com:n8n-io/n8n into ask-assistant
mutdmour Aug 8, 2024
6a92ce9
💄 Rebranding Assistant to Ava, updating some chat components styling
MiloradFilipovic Aug 8, 2024
2ea5b0c
📈 Added new telemetry event
MiloradFilipovic Aug 8, 2024
3e24993
⚡ Positioning execution error toasts relative to assistant sidebar
MiloradFilipovic Aug 9, 2024
785a566
✨ Improving chat input UX
MiloradFilipovic Aug 9, 2024
451f983
⚡ Moving all toasts to content area
MiloradFilipovic Aug 9, 2024
badcb54
Merge branch 'master' into ask-assistant
MiloradFilipovic Aug 9, 2024
d442e9a
⚡ Preventing sending messages on enter keydown if sending is disabled
MiloradFilipovic Aug 11, 2024
b02e7ea
🐛 Showing assistant button when error doesn't contain node reference
MiloradFilipovic Aug 12, 2024
6af90ae
✨ Showing toast when replacing code if ndv id not open for the node
MiloradFilipovic Aug 12, 2024
6b71f73
⚡ Fixing grid responsiveness
MiloradFilipovic Aug 12, 2024
6db943e
🐛 Fixing assistant keydown event conflicts with canvas shortcuts
MiloradFilipovic Aug 12, 2024
e41ddf3
🐛 Sending the correct error description to the back-end
MiloradFilipovic Aug 12, 2024
ece709e
💄 Updating default chat width
MiloradFilipovic Aug 12, 2024
bd116e9
⚡ Updating 'Replace code' toast copy
MiloradFilipovic Aug 12, 2024
f69e9f6
💄 Ask Ava -> Ask assistant
MiloradFilipovic Aug 13, 2024
96043a3
💄 Updating assistant placeholder message
MiloradFilipovic Aug 13, 2024
042926a
📈 Adding the `new session` telemetry event, sending `assistant open` …
MiloradFilipovic Aug 13, 2024
b9b58d0
📈 Updating the `User gave feedback` event
MiloradFilipovic Aug 13, 2024
c7e9a14
Merge branch 'ask-assistant' of github.com:n8n-io/n8n into ask-assistant
mutdmour Aug 13, 2024
382875f
⚡ Added dark mode tokens for the `Ask Assistant` button
MiloradFilipovic Aug 13, 2024
5e8081b
Merge branch 'ask-assistant' of github.com:n8n-io/n8n into ask-assistant
mutdmour Aug 13, 2024
2b9ca67
💄 Fixing `Ask Assistant` buttons alignment
MiloradFilipovic Aug 14, 2024
ec617b5
Merge branch 'ask-assistant' of github.com:n8n-io/n8n into ask-assistant
mutdmour Aug 14, 2024
cb312cc
fix: add unique seperator
mutdmour Aug 14, 2024
a413db5
feat: Replace proxy with rest endpoints in Ask assistant (#10383)
mutdmour Aug 14, 2024
b6a7f4a
handle merge conflicts
mutdmour Aug 14, 2024
b7d09d8
fix: update package.json
mutdmour Aug 14, 2024
f785950
fix: type
mutdmour Aug 14, 2024
76e6597
fix: e2e test
mutdmour Aug 14, 2024
dccb6d1
fix: rename button, hide from community
mutdmour Aug 14, 2024
e878aac
fix: remove default url
mutdmour Aug 14, 2024
cc02824
feat: remove var
mutdmour Aug 14, 2024
422d9af
🐛 Fixing grid column widths
MiloradFilipovic Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cypress/e2e/19-execution.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ describe('Execution', () => {
.within(() => cy.get('.fa-check').should('not.exist'));

successToast().should('be.visible');
clearNotifications();

// Clear execution data
workflowPage.getters.clearExecutionDataButton().should('be.visible');
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@n8n/n8n-nodes-langchain": "workspace:*",
"@n8n/permissions": "workspace:*",
"@n8n/typeorm": "0.3.20-10",
"@n8n_io/ai-assistant-sdk": "1.9.4",
"@n8n_io/license-sdk": "2.13.0",
"@oclif/core": "4.0.7",
"@rudderstack/rudder-sdk-node": "2.0.7",
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export class License {
return this.isFeatureEnabled(LICENSE_FEATURES.SAML);
}

isAiAssistantEnabled() {
return this.isFeatureEnabled(LICENSE_FEATURES.AI_ASSISTANT);
}

isAdvancedExecutionFiltersEnabled() {
return this.isFeatureEnabled(LICENSE_FEATURES.ADVANCED_EXECUTION_FILTERS);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import '@/controllers/activeWorkflows.controller';
import '@/controllers/auth.controller';
import '@/controllers/binaryData.controller';
import '@/controllers/curl.controller';
import '@/controllers/aiAssistant.controller';
import '@/controllers/dynamicNodeParameters.controller';
import '@/controllers/invitation.controller';
import '@/controllers/me.controller';
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ export const schema = {
},
},

aiAssistant: {
baseUrl: {
doc: 'Base URL of the AI assistant service',
format: String,
default: 'https://ai-assistant.n8n.io',
env: 'N8N_AI_ASSISTANT_BASE_URL',
},
},

expression: {
evaluator: {
doc: 'Expression evaluator to use',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const LICENSE_FEATURES = {
PROJECT_ROLE_ADMIN: 'feat:projectRole:admin',
PROJECT_ROLE_EDITOR: 'feat:projectRole:editor',
PROJECT_ROLE_VIEWER: 'feat:projectRole:viewer',
AI_ASSISTANT: 'feat:aiAssistant',
COMMUNITY_NODES_CUSTOM_REGISTRY: 'feat:communityNodes:customRegistry',
} as const;

Expand Down
44 changes: 44 additions & 0 deletions packages/cli/src/controllers/aiAssistant.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Post, RestController } from '@/decorators';
import { AiAssistantService } from '@/services/aiAsisstant.service';
import { AiAssistantRequest } from '@/requests';
import { Response } from 'express';
import type { AiAssistantSDK } from '@n8n_io/ai-assistant-sdk';
import { Readable, promises } from 'node:stream';
import { InternalServerError } from 'express-openapi-validator/dist/openapi.validator';
import { strict as assert } from 'node:assert';
import { ErrorReporterProxy } from 'n8n-workflow';

@RestController('/ai-assistant')
export class AiAssistantController {
constructor(private readonly aiAssistantService: AiAssistantService) {}

@Post('/chat', { rateLimit: { limit: 100 } })
async chat(req: AiAssistantRequest.Chat, res: Response) {
try {
const stream = await this.aiAssistantService.chat(req.body, req.user);

if (stream.body) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
await promises.pipeline(Readable.fromWeb(stream.body), res);
}
} catch (e) {
// todo add sentry reporting
assert(e instanceof Error);
ErrorReporterProxy.error(e);
throw new InternalServerError({ message: `Something went wrong: ${e.message}` });
}
}

@Post('/chat/apply-suggestion')
async applySuggestion(
req: AiAssistantRequest.ApplySuggestion,
): Promise<AiAssistantSDK.ApplySuggestionResponse> {
try {
return await this.aiAssistantService.applySuggestion(req.body, req.user);
} catch (e) {
assert(e instanceof Error);
ErrorReporterProxy.error(e);
throw new InternalServerError({ message: `Something went wrong: ${e.message}` });
}
}
}
1 change: 1 addition & 0 deletions packages/cli/src/controllers/e2e.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class E2EController {
[LICENSE_FEATURES.PROJECT_ROLE_ADMIN]: false,
[LICENSE_FEATURES.PROJECT_ROLE_EDITOR]: false,
[LICENSE_FEATURES.PROJECT_ROLE_VIEWER]: false,
[LICENSE_FEATURES.AI_ASSISTANT]: false,
[LICENSE_FEATURES.COMMUNITY_NODES_CUSTOM_REGISTRY]: false,
};

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { Project, ProjectType } from '@db/entities/Project';
import type { ProjectRole } from './databases/entities/ProjectRelation';
import type { Scope } from '@n8n/permissions';
import type { ScopesField } from './services/role.service';
import type { AiAssistantSDK } from '@n8n_io/ai-assistant-sdk';

export class UserUpdatePayload implements Pick<User, 'email' | 'firstName' | 'lastName'> {
@Expose()
Expand Down Expand Up @@ -607,3 +608,14 @@ export declare namespace NpsSurveyRequest {
// once some schema validation is added
type NpsSurveyUpdate = AuthenticatedRequest<{}, {}, unknown>;
}

// ----------------------------------
// /ai-assistant
// ----------------------------------

export declare namespace AiAssistantRequest {
type Chat = AuthenticatedRequest<{}, {}, AiAssistantSDK.ChatRequestPayload>;

type SuggestionPayload = { sessionId: string; suggestionId: string };
type ApplySuggestion = AuthenticatedRequest<{}, {}, SuggestionPayload>;
}
56 changes: 56 additions & 0 deletions packages/cli/src/services/aiAsisstant.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Service } from 'typedi';
import type { AiAssistantSDK } from '@n8n_io/ai-assistant-sdk';
import { AiAssistantClient } from '@n8n_io/ai-assistant-sdk';
import { assert, type IUser } from 'n8n-workflow';
import { License } from '../License';
import { N8N_VERSION } from '../constants';
import config from '@/config';
import type { AiAssistantRequest } from '@/requests';
import type { Response } from 'undici';

@Service()
export class AiAssistantService {
private client: AiAssistantClient | undefined;

constructor(private readonly licenseService: License) {
this.licenseService = licenseService;
}

async init() {
const aiAssistantEnabled = this.licenseService.isAiAssistantEnabled();
if (!aiAssistantEnabled) {
return;
}

const licenseCert = await this.licenseService.loadCertStr();
const consumerId = this.licenseService.getConsumerId();
const baseUrl = config.get('aiAssistant.baseUrl');
const logLevel = config.getEnv('logs.level');

this.client = new AiAssistantClient({
licenseCert,
consumerId,
n8nVersion: N8N_VERSION,
baseUrl,
logLevel,
});
}

async chat(payload: AiAssistantSDK.ChatRequestPayload, user: IUser): Promise<Response> {
if (!this.client) {
await this.init();
}
assert(this.client, 'Assistant client not setup');

return await this.client.chat(payload, { id: user.id });
}

async applySuggestion(payload: AiAssistantRequest.SuggestionPayload, user: IUser) {
if (!this.client) {
await this.init();
}
assert(this.client, 'Assistant client not setup');

return await this.client.applySuggestion(payload, { id: user.id });
}
}
8 changes: 8 additions & 0 deletions packages/cli/src/services/frontend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export class FrontendService {
workflowTagsDisabled: config.getEnv('workflowTagsDisabled'),
logLevel: config.getEnv('logs.level'),
hiringBannerEnabled: config.getEnv('hiringBanner.enabled'),
aiAssistant: {
enabled: false,
},
templates: {
enabled: this.globalConfig.templates.enabled,
host: this.globalConfig.templates.host,
Expand Down Expand Up @@ -279,6 +282,7 @@ export class FrontendService {
const isS3Selected = config.getEnv('binaryDataManager.mode') === 's3';
const isS3Available = config.getEnv('binaryDataManager.availableModes').includes('s3');
const isS3Licensed = this.license.isBinaryDataS3Licensed();
const isAiAssistantEnabled = this.license.isAiAssistantEnabled();

this.settings.license.planName = this.license.getPlanName();
this.settings.license.consumerId = this.license.getConsumerId();
Expand Down Expand Up @@ -331,6 +335,10 @@ export class FrontendService {
this.settings.missingPackages = this.communityPackagesService.hasMissingPackages;
}

if (isAiAssistantEnabled) {
this.settings.aiAssistant.enabled = isAiAssistantEnabled;
}

this.settings.mfa.enabled = config.get('mfa.enabled');

this.settings.executionMode = config.getEnv('executions.mode');
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"markdown-it-emoji": "^2.0.2",
"markdown-it-link-attributes": "^4.0.1",
"markdown-it-task-lists": "^2.1.1",
"parse-diff": "^0.11.1",
"sanitize-html": "2.12.1",
"vue": "catalog:frontend",
"vue-boring-avatars": "^1.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import AssistantAvatar from './AssistantAvatar.vue';
import type { StoryFn } from '@storybook/vue3';

export default {
title: 'Assistant/AssistantAvatar',
component: AssistantAvatar,
argTypes: {},
};

const Template: StoryFn = (args, { argTypes }) => ({
setup: () => ({ args }),
props: Object.keys(argTypes),
components: {
AssistantAvatar,
},
template: '<AssistantAvatar v-bind="args" />',
});

export const Default = Template.bind({});
Default.args = {};

export const Mini = Template.bind({});
Mini.args = {
size: 'mini',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
import AssistantIcon from '../AskAssistantIcon/AssistantIcon.vue';

withDefaults(defineProps<{ size: 'small' | 'mini' }>(), {
size: 'small',
});
</script>

<template>
<div :class="[$style.container, $style[size]]">
MiloradFilipovic marked this conversation as resolved.
Show resolved Hide resolved
<AssistantIcon :size="size" theme="blank" />
</div>
</template>

<style lang="scss" module>
.container {
background: var(--color-assistant-highlight-gradient);
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
}

.small {
height: var(--spacing-m);
width: var(--spacing-m);
}

.mini {
height: var(--spacing-s);
width: var(--spacing-s);
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import AskAssistantButton from './AskAssistantButton.vue';
import { action } from '@storybook/addon-actions';
import type { StoryFn } from '@storybook/vue3';

export default {
title: 'Assistant/AskAssistantButton',
component: AskAssistantButton,
argTypes: {},
};

const methods = {
onClick: action('click'),
};

const Template: StoryFn = (args, { argTypes }) => ({
setup: () => ({ args }),
props: Object.keys(argTypes),
components: {
AskAssistantButton,
},
template:
'<div style="display: flex; height: 50px; width: 300px; align-items: center; justify-content: center"><AskAssistantButton v-bind="args" @click="onClick" /></div>',
methods,
});

export const Button = Template.bind({});

export const Notifications = Template.bind({});
Notifications.args = {
unreadCount: 1,
};
Loading
Loading