Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Add questions about a ticket and a meeting to the Nordlicht world
Guido Boykeb5810895180e
diff --git a/lib/lalabase/demo/fiction.rb b/lib/lalabase/demo/fiction.rbindex 3ef1e02..9df3854 100644--- a/lib/lalabase/demo/fiction.rb+++ b/lib/lalabase/demo/fiction.rb@@ -254,6 +254,50 @@ module Lalabasemodel: 'mistral-medium-latest'}.freeze+ # Asked from the ticket of the detail motif, with the ticket as its reference+ # (Chat#scope_references): the picture beside the open ticket. Cites the ticket,+ # Ole's last comment (COMMENTS) and the weekly call (MEETINGS). Same rule as CHAT:+ # stored, and checked against a real run before a new set of pictures.+ TICKET_QUESTION = {+ question: { de: 'Was ist an diesem Ticket noch offen, und wer arbeitet daran?',+ en: 'What is still open on this ticket, and who is working on it?' },+ answer: {+ de: 'Ole Jensen arbeitet daran, die Priorität ist dringend [1]. Summenzeile und Mieter-Ebene ' \+ 'stehen; offen ist die Vorlage mit dem Logo von Deichblick, die Ole morgen angeht [2]. ' \+ 'Im Wochentermin hat Deichblick eine eigene Seite je Mieter gewünscht, das Logo schickt ' \+ 'Kerstin Möller als Vektordatei [3].',+ en: 'Ole Jensen is working on it, and it is marked urgent [1]. The totals row and the tenant ' \+ 'level are done; still open is the template with the Deichblick logo, which Ole plans for ' \+ 'tomorrow [2]. In the weekly call Deichblick asked for a page per tenant, and Kerstin Möller ' \+ 'sends the logo as a vector file [3].'+ },+ ticket: 3,+ meeting: 0,+ model: 'mistral-medium-latest'+ }.freeze++ # Asked from the weekly call, with the meeting as its reference. Cites the+ # meeting and the ticket the call was about. Same rule as CHAT.+ MEETING_QUESTION = {+ question: { de: 'Was haben wir in diesem Termin vereinbart, und was sind die nächsten Schritte?',+ en: 'What did we agree in this meeting, and what are the next steps?' },+ answer: {+ de: 'Jeder Mieter bekommt in der Nebenkostenabrechnung eine eigene Seite mit seinem Anteil, oben ' \+ 'mit dem Logo von Deichblick [1]. Nächste Schritte: Kerstin Möller schickt das Logo als ' \+ 'Vektordatei, Ole Jensen baut die Seite je Mieter, und drei Hausmeister testen die ' \+ 'Schadensmeldung ab Montag [1]. Die Abnahme ist in zwei Wochen geplant; der PDF-Export ist ' \+ 'noch in Bearbeitung [2].',+ en: 'Each tenant gets a page of their own in the service charge statement, with their share and ' \+ 'the Deichblick logo at the top [1]. Next steps: Kerstin Möller sends the logo as a vector ' \+ 'file, Ole Jensen builds the page per tenant, and three caretakers test the damage report ' \+ 'from Monday [1]. The acceptance is planned in two weeks; the PDF export is still in ' \+ 'progress [2].'+ },+ meeting: 0,+ ticket: 3,+ model: 'mistral-medium-latest'+ }.freeze+module_function# The sidebar shows the part before the @, so the address carries the full name.diff --git a/lib/lalabase/demo/world.rb b/lib/lalabase/demo/world.rbindex 69ec946..5ec29e8 100644--- a/lib/lalabase/demo/world.rb+++ b/lib/lalabase/demo/world.rb@@ -10,7 +10,7 @@ module Lalabase# their actors, projects the way Organisations::ProjectsController creates them.# No factories: the demo runs in production, where FactoryBot is not installed,# and a factory would show a state no real instance produces. Only the stored- # assistant answer is written directly, because its actor would ask a model.+ # assistant chats are written directly, because their actor would ask a model.## Entry point: build. The order of writes is explicit: people before projects,# projects before tickets, tickets before the hours booked on them.@@ -26,7 +26,7 @@ module Lalabaseclass WorldORGANISATION_NAME = 'Nordlicht Software GmbH'- attr_reader :organisation, :chat, :notes, :meetings+ attr_reader :organisation, :chat, :ticket_question, :meeting_question, :notes, :meetingsdef initialize(locale:, now: Time.current, organisation: {}, embeddings: false, password: nil)@locale = locale.to_sym@@ -70,7 +70,7 @@ module Lalabaseadd_notesadd_commentsadd_meetings- add_chat+ add_chatsenddef create_organisation@@ -166,7 +166,7 @@ module Lalabasedef add_commentstarget = ticket(Fiction::CHAT[:ticket])- Fiction::COMMENTS.each do |entry|+ @comments = Fiction::COMMENTS.map do |entry|params = { content: entry.fetch(@locale), create_embeddings: @embeddings }post = succeed!(Actors::SavePost.call(ticket: target, params: params, current_user: person(entry[:person])))backdate(post, @now - entry[:hours_ago].hours)@@ -190,21 +190,48 @@ module Lalabase{ display_name: Fiction.full_name(who), user_id: person(who).id }end+ # Three chats, newest last, each with the citations its [n] links point to, in+ # that order. The ticket and the meeting chat carry their object as the reference+ # the panel offers on that page.+ def add_chats+ @chat = add_chat(Fiction::CHAT, minutes_ago: 20,+ citations: [Lalabase::Citations.ticket(ticket(Fiction::CHAT[:ticket])),+ Lalabase::Citations.time_report(project(:deichblick), {}),+ Lalabase::Citations.note(@notes.fetch(Fiction::CHAT[:note]))])+ add_ticket_question+ add_meeting_question+ end++ def add_ticket_question+ spec = Fiction::TICKET_QUESTION+ target = ticket(spec[:ticket])+ @ticket_question = add_chat(spec, minutes_ago: 10, references: [target],+ citations: [Lalabase::Citations.ticket(target),+ Lalabase::Citations.post(@comments.last),+ Lalabase::Citations.meeting(@meetings.fetch(spec[:meeting]))])+ end++ def add_meeting_question+ spec = Fiction::MEETING_QUESTION+ target = @meetings.fetch(spec[:meeting])+ @meeting_question = add_chat(spec, minutes_ago: 5, references: [target],+ citations: [Lalabase::Citations.meeting(target),+ Lalabase::Citations.ticket(ticket(spec[:ticket]))])+ end+# The first post of a chat renders as the question (Chatpost#set_initial_role# makes it 'system'). model_used marks the answer as finished; without it the [n]# links stay text.- def add_chat- spec = Fiction::CHAT- @chat = Chat.new(organisation: @organisation, user: signed_in)- @chat.chatposts.build(organisation: @organisation, user: signed_in, content: spec[:question].fetch(@locale))- @chat.save!- citations = [Lalabase::Citations.ticket(ticket(spec[:ticket])),- Lalabase::Citations.time_report(project(:deichblick), {}),- Lalabase::Citations.note(@notes.fetch(spec[:note]))]- @chat.chatposts.create!(organisation: @organisation, user: signed_in, role: 'assistant',- content: dated(spec[:answer].fetch(@locale)), model_used: spec[:model],- source_citations: citations.map(&:deep_stringify_keys))- @chat.chatposts.update_all(created_at: @now - 20.minutes)+ def add_chat(spec, minutes_ago:, citations:, references: [])+ chat = Chat.new(organisation: @organisation, user: signed_in,+ scope_references: references.map { { 'type' => _1.class.name, 'id' => _1.id } })+ chat.chatposts.build(organisation: @organisation, user: signed_in, content: spec[:question].fetch(@locale))+ chat.save!+ chat.chatposts.create!(organisation: @organisation, user: signed_in, role: 'assistant',+ content: dated(spec[:answer].fetch(@locale)), model_used: spec[:model],+ source_citations: citations.map(&:deep_stringify_keys))+ chat.chatposts.update_all(created_at: @now - minutes_ago.minutes)+ chatenddef random_password = SecureRandom.base58(24)diff --git a/spec/lib/lalabase/demo/world_spec.rb b/spec/lib/lalabase/demo/world_spec.rbindex 352eb20..26b6f42 100644--- a/spec/lib/lalabase/demo/world_spec.rb+++ b/spec/lib/lalabase/demo/world_spec.rb@@ -31,7 +31,8 @@ RSpec.describe Lalabase::Demo::World doexpect(TimeSession.where(organisation: organisation).count).to eq(fiction::TIME.size)expect(world.notes.map(&:title)).to eq(fiction::NOTES.map { _1[:en] })expect(world.ticket(fiction::CHAT[:ticket]).posts.count).to eq(fiction::COMMENTS.size)- expect(world.chat.chatposts.count).to eq(2)+ chats = [world.chat, world.ticket_question, world.meeting_question]+ expect(Prosopite.pause { chats.map { _1.chatposts.count } }).to eq([2, 2, 2])end# The demo signs a visitor in as this person: every right of the team, none of@@ -85,6 +86,25 @@ RSpec.describe Lalabase::Demo::World doexpect(TimeSession.where(organisation: organisation).maximum(:occurred_on).to_date).to eq(now.to_date)end+ # The pictures beside a ticket and a meeting: the panel shows the object as the+ # chat's reference, and every [n] of the answer has a citation to point to.+ it 'adds a chat about the ticket and one about the meeting, each with its reference and citations' do+ statement = world.ticket(fiction::TICKET_QUESTION[:ticket])+ weekly_call = world.meetings.fetch(fiction::MEETING_QUESTION[:meeting])+ expect(world.ticket_question.scope_references).to eq([{ 'type' => 'Ticket', 'id' => statement.id }])+ expect(world.meeting_question.scope_references).to eq([{ 'type' => 'Meeting', 'id' => weekly_call.id }])+ expect(world.chat.scope_references).to eq([])++ { world.ticket_question => [['ticket', statement.id], ['post', statement.posts.order(:created_at).last.id],+ ['meeting', weekly_call.id]],+ world.meeting_question => [['meeting', weekly_call.id], ['ticket', statement.id]] }.each do |chat, cited|+ answer = Prosopite.pause { chat.chatposts.find_by!(role: 'assistant') }+ expect(answer.source_citations.map { _1.values_at('type', 'id') }).to eq(cited)+ expect(answer.content.scan(/\[(\d+)\]/).flatten.map(&:to_i).uniq.sort).to eq((1..cited.size).to_a)+ expect(answer.model_used).to be_present+ end+ end+it 'leaves the assistant search off unless asked' doexpect(world.notes.map(&:create_embeddings)).to all(be(false))expect(world.meetings.map(&:create_embeddings)).to all(be(false))diff --git a/spec/marketing/screenshots_spec.rb b/spec/marketing/screenshots_spec.rbindex 8a4c348..2b2913d 100644--- a/spec/marketing/screenshots_spec.rb+++ b/spec/marketing/screenshots_spec.rb@@ -120,6 +120,12 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system dosleep 0.2end+ # The sources of the answer in the open panel, unfolded.+ def open_citations(count)+ find('#assistant_panel [data-testid="citation-list"] summary').click+ expect(page).to have_css('#assistant_panel [data-testid="citation-row"]', count: count)+ end+def picture_bottom(selector)if selectorbox(selector)['bottom'] + 32@@ -178,6 +184,37 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system docapture(locale, :ticket)end+ # The tickets as a board: a setting per person and project, stored the way the+ # view switch stores it.+ it 'takes the ticket board' do+ ViewConfiguration.for_user_project(world.signed_in, world.project(:deichblick), 'tickets')+ .update!(view_mode: 'kanban')+ visit organisation_project_tickets_path(world.organisation, world.project(:deichblick))+ expect(page).to have_css('.kanban-board')+ expect(page).to have_text(Lalabase::Demo::Fiction::TICKETS.last.fetch(locale))+ capture(locale, :board)+ end++ # The assistant beside the object it was asked about, with the object as its+ # reference: the ticket of the detail motif, and the weekly call. The open panel+ # reaches the bottom of the window, so the picture is the whole window.+ it 'takes the assistant beside the ticket' do+ ticket = world.ticket(Lalabase::Demo::Fiction::TICKET_QUESTION[:ticket])+ visit organisation_project_ticket_path(world.organisation, ticket.project, ticket,+ assistant_chat_id: world.ticket_question.id)+ # Three citations, two rows: the comment is listed under its ticket.+ open_citations(2)+ capture(locale, :ticket_assistant, until_bottom_of: 'body')+ end++ it 'takes the assistant beside the meeting' do+ meeting = world.meetings.fetch(Lalabase::Demo::Fiction::MEETING_QUESTION[:meeting])+ visit organisation_project_meeting_path(world.organisation, meeting.project, meeting,+ assistant_chat_id: world.meeting_question.id)+ open_citations(2)+ capture(locale, :meeting_assistant, until_bottom_of: 'body')+ end+it 'takes the assistant answer with its sources' do# Narrower than the other pictures: in full mode the answer runs across the# whole window, and at 1600 px the picture came out four times as wide as tall.