pgkiln 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/SECURITY.md +7 -0
  2. package/db/migrations/119_workspace_home.sql +30 -0
  3. package/db/migrations/120_datasets.sql +87 -0
  4. package/db/migrations/121_ai_agents.sql +94 -0
  5. package/db/migrations/122_team_development.sql +186 -0
  6. package/db/migrations/123_workflow_outcomes.sql +407 -0
  7. package/db/migrations/124_component_details.sql +51 -0
  8. package/docs/apex-feature-parity.md +15 -12
  9. package/docs/guide/01-installation.md +9 -3
  10. package/docs/guide/03-builder.md +211 -11
  11. package/docs/guide/04-pages-and-regions.md +96 -22
  12. package/docs/guide/05-items.md +7 -1
  13. package/docs/guide/06-processing.md +123 -8
  14. package/docs/guide/07-dynamic-actions.md +34 -0
  15. package/docs/guide/09-reference.md +2 -1
  16. package/docs/guide/11-from-apex.md +2 -1
  17. package/docs/guide/12-development.md +70 -11
  18. package/docs/guide/20-ai-agents.md +4 -2
  19. package/examples/hr/README.md +2 -0
  20. package/examples/hr/hr_63_datasets.sql +29 -0
  21. package/examples/hr/hr_64_ai_agent.sql +97 -0
  22. package/examples/hr/hr_65_ask_reports.sql +21 -0
  23. package/examples/hr/hr_66_team_development.sql +58 -0
  24. package/examples/hr/hr_67_workflow_outcomes.sql +113 -0
  25. package/examples/hr/hr_68_component_details.sql +96 -0
  26. package/package.json +1 -1
  27. package/public/app.css +46 -0
  28. package/public/app.js +134 -20
  29. package/public/builder.css +116 -0
  30. package/public/builder.js +47 -0
  31. package/src/ai/chat.ts +18 -18
  32. package/src/ai/service.ts +35 -11
  33. package/src/ai/types.ts +7 -2
  34. package/src/app.ts +11 -1
  35. package/src/builder/advisor.ts +6 -3
  36. package/src/builder/ai-agents.ts +372 -0
  37. package/src/builder/ai-builder.ts +3 -3
  38. package/src/builder/ai.ts +13 -9
  39. package/src/builder/assistant.ts +22 -7
  40. package/src/builder/components.ts +38 -9
  41. package/src/builder/datasets.ts +472 -0
  42. package/src/builder/designer.ts +8 -3
  43. package/src/builder/feedback.ts +6 -1
  44. package/src/builder/home.ts +12 -7
  45. package/src/builder/instance.ts +2 -0
  46. package/src/builder/locks.ts +7 -1
  47. package/src/builder/region-help.ts +2 -2
  48. package/src/builder/reporter.ts +52 -3
  49. package/src/builder/routes.ts +7 -4
  50. package/src/builder/shared.ts +1 -1
  51. package/src/builder/subscriptions.ts +1 -0
  52. package/src/builder/team.ts +991 -0
  53. package/src/builder/ui.ts +8 -5
  54. package/src/builder/workflow-migrate.ts +210 -0
  55. package/src/builder/workflows.ts +29 -6
  56. package/src/builder/workspace-home.ts +285 -0
  57. package/src/builder/workspace-transfer.ts +1 -1
  58. package/src/builder/workspaces.ts +7 -4
  59. package/src/cli/replace.ts +7 -1
  60. package/src/datasets.ts +367 -0
  61. package/src/i18n/ar.ts +33 -0
  62. package/src/i18n/cs.ts +33 -0
  63. package/src/i18n/da.ts +33 -0
  64. package/src/i18n/de.ts +33 -0
  65. package/src/i18n/el.ts +33 -0
  66. package/src/i18n/es.ts +33 -0
  67. package/src/i18n/fi.ts +33 -0
  68. package/src/i18n/fr.ts +33 -0
  69. package/src/i18n/he.ts +33 -0
  70. package/src/i18n/it.ts +33 -0
  71. package/src/i18n/ja.ts +33 -0
  72. package/src/i18n/ko.ts +33 -0
  73. package/src/i18n/nb.ts +33 -0
  74. package/src/i18n/pl.ts +33 -0
  75. package/src/i18n/pt.ts +33 -0
  76. package/src/i18n/ru.ts +33 -0
  77. package/src/i18n/sv.ts +33 -0
  78. package/src/i18n/tr.ts +33 -0
  79. package/src/i18n/uk.ts +33 -0
  80. package/src/i18n/zh.ts +33 -0
  81. package/src/i18n.ts +66 -0
  82. package/src/instance.ts +3 -0
  83. package/src/metadata.ts +9 -3
  84. package/src/release-check.ts +139 -0
  85. package/src/reporting-app.ts +101 -0
  86. package/src/runtime/ai-agents.ts +365 -0
  87. package/src/runtime/ai-filter.ts +385 -107
  88. package/src/runtime/assistant.ts +64 -11
  89. package/src/runtime/context.ts +2 -0
  90. package/src/runtime/data-reporter.ts +199 -32
  91. package/src/runtime/ir-phrases.ts +812 -0
  92. package/src/runtime/ir-plan.ts +449 -0
  93. package/src/runtime/items.ts +1 -1
  94. package/src/runtime/regions.ts +6 -2
  95. package/src/runtime/render.ts +1 -1
  96. package/src/runtime/report.ts +1 -1
  97. package/src/runtime/tasks.ts +63 -12
  98. package/src/session.ts +2 -0
  99. package/src/subscriptions.ts +2 -1
  100. package/src/task-events.ts +232 -0
  101. package/src/team-samples.ts +74 -0
  102. package/src/team.ts +342 -0
  103. package/src/workflow.ts +135 -18
  104. package/src/workspace-export.ts +39 -4
@@ -1,3 +1,4 @@
1
+ import { pageIssuesNote } from './team.ts';
1
2
  import type { FastifyInstance, FastifyReply } from 'fastify';
2
3
  import { owner } from '../db.ts';
3
4
  import { html, raw, type Raw } from '../html.ts';
@@ -163,13 +164,17 @@ export async function designerRoutes(app: FastifyInstance) {
163
164
  <div class="pd-dialog-buttons"><button type="button" class="btn" data-dialog-close>Cancel</button><button class="btn btn-primary">Copy</button></div>
164
165
  </form>
165
166
  </dialog>`;
166
- const events: [string, string][] = [['change', 'Change'], ['click', 'Click'], ['load', 'Page load']];
167
+ const events: [string, string][] = [['change', 'Change'], ['click', 'Click'], ['load', 'Page load'], ['menu_entry', 'Menu entry chosen']];
168
+ const daLeaf = (d: (typeof rows.dynamic_action)[number]) => leaf('dynamic_action', d, icon('bolt'), d.name, `${d.trigger_element ?? ''} → ${d.action}`);
169
+ // (sprint 115) the other events (focus, custom, before_submit, …) in one folder, when there are any
170
+ const others = rows.dynamic_action.filter((d) => !events.some(([ev]) => ev === d.event));
167
171
  const dynamicActions = html`${createBar([['dynamic_action', 'Dynamic action']])}
168
172
  <ul class="pd-tree" aria-label="Dynamic actions">
169
173
  ${events.map(([ev, label]) => {
170
174
  const list = rows.dynamic_action.filter((d) => d.event === ev);
171
- return folder(`Events: ${label}`, list.length ? list.map((d) => leaf('dynamic_action', d, icon('bolt'), d.name, `${d.trigger_element ?? ''} → ${d.action}`)) : none('None'), list.length > 0);
175
+ return folder(`Events: ${label}`, list.length ? list.map(daLeaf) : none('None'), list.length > 0);
172
176
  })}
177
+ ${others.length ? folder('Events: Other', others.map((d) => leaf('dynamic_action', d, icon('bolt'), d.name, `${d.event}: ${d.trigger_element ?? ''} → ${d.action}`)), true) : ''}
173
178
  </ul>`;
174
179
  // after processing: the branches in sequence, then (when none applies) the pressed button's target page
175
180
  const afterBranches = rows.branch.filter((x) => x.point !== 'before_header');
@@ -303,7 +308,7 @@ export async function designerRoutes(app: FastifyInstance) {
303
308
  const blocking = runOnly ?? locks.find((l) => l.locked_by !== s.username);
304
309
  const mine = locks.find((l) => l.locked_by === s.username);
305
310
  const commentCount = (await owner.one('select count(*)::int as n from meta.dev_comment where app_id = $1 and page_no = $2', [p.app_id, p.page_no])).n;
306
- const center = html`${blocking ? html`<div class="alert alert-error pd-lock" role="status">${icon('key')} ${lockText(blocking)} Your changes will be refused.</div>` : ''}
311
+ const center = html`${blocking ? html`<div class="alert alert-error pd-lock" role="status">${icon('key')} ${lockText(blocking)} Your changes will be refused.</div>` : ''}${await pageIssuesNote(p.app_id, p.page_no)}
307
312
  <div class="pd-tabs pd-tabs-center" data-tabs="pd-center" aria-label="Page">
308
313
  ${tab('pd-c-layout', 'Layout', layout, true)}
309
314
  ${tab('pd-c-search', 'Page search', pageSearch)}
@@ -3,6 +3,8 @@ import { owner } from '../db.ts';
3
3
  import { html, raw } from '../html.ts';
4
4
  import { icon } from '../icons.ts';
5
5
  import { appOr404 } from './forms.ts';
6
+ import { issuesFrom } from '../team.ts';
7
+ import { toIssueButton } from './team.ts';
6
8
  import { appHeader, back, BASE, csrf, developer, flash, region, select, send, shell, type Req } from './ui.ts';
7
9
 
8
10
  // Application → Feedback (APEX: Team Development → Feedback, migration 084):
@@ -28,6 +30,8 @@ export async function feedbackRoutes(app: FastifyInstance) {
28
30
  [a.id, status, kind])).rows;
29
31
  const counts = (await owner.query(`select status, count(*)::int as n from meta.feedback where app_id = $1 group by 1`, [a.id])).rows;
30
32
  const count = (st: string) => counts.find((c) => c.status === st)?.n ?? 0;
33
+ // (sprint 113) feedback turned into a Team Development issue links to it
34
+ const issues = await issuesFrom('feedback', rows.map((f) => Number(f.id)));
31
35
  const body = html`
32
36
  ${region('Feedback', html`
33
37
  <form method="post" action="${BASE}/apps/${a.id}/feedback/settings" class="u-mb1">${csrf(s)}
@@ -39,10 +43,11 @@ export async function feedbackRoutes(app: FastifyInstance) {
39
43
  ${select('status', 'Status', status, [['', 'All'], ...STATUSES])}
40
44
  ${select('kind', 'Kind', kind, [['', 'All'], ...KINDS])}
41
45
  <button class="btn btn-sm">${icon('filter')} Show</button></form>
42
- ${rows.length ? html`<ul class="feedback-admin">${rows.map((f) => html`<li class="feedback-item">
46
+ ${rows.length ? html`<ul class="feedback-admin">${rows.map((f) => html`<li class="feedback-item" id="feedback-${f.id}">
43
47
  <div class="feedback-meta"><span class="tag">${KINDS.find(([v]) => v === f.kind)?.[1]}</span>
44
48
  <b>${f.username}</b> <span class="muted">${when(f.created_at)}${f.page_no ? html` · <a href="/a/${a.alias}/${f.page_no}" target="_blank" rel="noopener">page ${f.page_no}</a>` : ''}${f.rating ? ` · ${'★'.repeat(f.rating)}` : ''}${f.user_agent ? ` · ${f.user_agent}` : ''}</span></div>
45
49
  <p class="feedback-body">${f.body}</p>
50
+ <p class="feedback-issue">${toIssueButton(s, 'feedback', Number(f.id), issues.get(Number(f.id)))}</p>
46
51
  <form method="post" action="${BASE}/apps/${a.id}/feedback/${f.id}">${csrf(s)}
47
52
  <div class="form-grid">
48
53
  ${select('status', 'Status', f.status, STATUSES)}
@@ -1,4 +1,4 @@
1
- import type { FastifyInstance } from 'fastify';
1
+ import type { FastifyInstance, FastifyReply } from 'fastify';
2
2
  import { owner } from '../db.ts';
3
3
  import { html, raw, type Raw } from '../html.ts';
4
4
  import { icon } from '../icons.ts';
@@ -90,9 +90,12 @@ async function recentApps(s: Session) {
90
90
 
91
91
  export async function homeRoutes(app: FastifyInstance) {
92
92
  // ---------------------------------------------------------------- App Builder home
93
- app.get(BASE, async (req: Req, reply) => {
93
+ // (sprint 109) at /builder/apps; /builder (links from before the Workspace home) shows it too, or redirects to the
94
+ // Workspace home when the workspace's preferences say so (meta.workspace.builder_home, migration 119)
95
+ const appBuilder = async (req: Req, reply: FastifyReply) => {
94
96
  const s = await developer(req, reply);
95
97
  if (!s) return;
98
+ if (s.workspace?.builder_home === 'home' && req.url === BASE) return reply.redirect(`${BASE}/home`);
96
99
  const q = String(req.query.q ?? '').trim().slice(0, 100);
97
100
  // the view and sort are remembered for the session
98
101
  if (req.query.view === 'grid' || req.query.view === 'report') s.state.__BVIEW = req.query.view;
@@ -124,13 +127,13 @@ export async function homeRoutes(app: FastifyInstance) {
124
127
  if (q) p.set('q', q);
125
128
  if (o.view) p.set('view', o.view);
126
129
  if (o.sort) p.set('sort', o.sort);
127
- return `${BASE}?${p}`;
130
+ return `${BASE}/apps?${p}`;
128
131
  };
129
132
  const th = (key: Sort, label: string, cls = '') =>
130
133
  html`<th scope="col"${cls ? raw(` class="${cls}"`) : ''}${sort === key ? raw(' aria-sort="' + (key === 'pages' || key === 'updated' ? 'descending' : 'ascending') + '"') : ''}><a href="${link({ sort: key })}">${label}${sort === key ? html`<span class="ab-sorted" aria-hidden="true">${key === 'pages' || key === 'updated' ? '↓' : '↑'}</span>` : ''}</a></th>`;
131
134
  const rows = apps.rows;
132
135
  const list = rows.length === 0
133
- ? html`<p class="ab-empty">${total.n ? html`No application ${group ? html`in the group ${group.name}${q ? html` matches “${q}”` : ''}` : html`matches “${q}”`}. <a href="${BASE}?q=&amp;group=">Show all</a>` : html`No applications yet. <a href="${BASE}/create">Create one</a> or <a href="${BASE}/import">import one</a>.`}</p>`
136
+ ? html`<p class="ab-empty">${total.n ? html`No application ${group ? html`in the group ${group.name}${q ? html` matches “${q}”` : ''}` : html`matches “${q}”`}. <a href="${BASE}/apps?q=&amp;group=">Show all</a>` : html`No applications yet. <a href="${BASE}/create">Create one</a> or <a href="${BASE}/import">import one</a>.`}</p>`
134
137
  : view === 'grid'
135
138
  ? html`<div class="ab-cards">${rows.map((a) => html`<article class="ab-card" data-filter-row>
136
139
  <a class="ab-card-main" href="${BASE}/apps/${a.id}">${appIcon(a)}<span><strong>${a.name}</strong><small>${a.id} · /a/${a.alias}</small></span></a>
@@ -162,12 +165,12 @@ export async function homeRoutes(app: FastifyInstance) {
162
165
  ${s.workspace?.message ? html`<div class="alert alert-info ab-message" role="status">${icon('bell')}<div><strong>${s.workspace.name}</strong><p>${s.workspace.message}</p></div></div>` : ''}
163
166
  ${tiles()}
164
167
  <div class="ab-toolbar">
165
- <form class="ab-search" method="get" action="${BASE}" role="search">
168
+ <form class="ab-search" method="get" action="${BASE}/apps" role="search">
166
169
  <label class="sr-only" for="ab-q">Search applications</label>${icon('search')}
167
170
  <input id="ab-q" name="q" type="search" value="${q}" placeholder="Search" autocomplete="off" data-filter-list=".ab-home [data-filter-row]">
168
171
  </form>
169
172
  <div class="ab-views" role="group" aria-label="View">${viewButton('grid', 'grid', 'Cards')}${viewButton('report', 'list', 'Report')}</div>
170
- ${groups.length ? html`<form method="get" action="${BASE}" class="ab-group"><label class="sr-only" for="ab-group">Application group</label>
173
+ ${groups.length ? html`<form method="get" action="${BASE}/apps" class="ab-group"><label class="sr-only" for="ab-group">Application group</label>
171
174
  <select id="ab-group" name="group" data-autosubmit><option value="">All groups</option>${groups.map((g) => html`<option value="${g.id}"${group?.id === g.id ? raw(' selected') : ''}>${g.name}</option>`)}</select>
172
175
  <noscript><button class="btn btn-sm">Show</button></noscript></form>` : ''}
173
176
  <details class="menu ab-menu"><summary class="btn">Actions ${icon('chevron')}</summary>
@@ -187,7 +190,9 @@ export async function homeRoutes(app: FastifyInstance) {
187
190
  ${aside(recent, 'The App Builder creates, edits and runs the applications of this workspace: pages and regions on your PostgreSQL tables, with sign-in, roles and row level security.', TASKS)}
188
191
  </div>`;
189
192
  return send(reply, s, shell(s, 'App Builder', [['App Builder']], main));
190
- });
193
+ };
194
+ app.get(BASE, appBuilder);
195
+ app.get(`${BASE}/apps`, appBuilder);
191
196
 
192
197
  // ---------------------------------------------------------------- create and import
193
198
  // (sprint 73) GET /create, the Create Application wizard, is in appwizard.ts
@@ -3,6 +3,7 @@ import { html } from '../html.ts';
3
3
  import { configurationValue, CONFIGURATION, INSTANCE_SETTINGS, instanceSetting, origin, refreshInstanceSettings, saveInstanceSettings } from '../instance.ts';
4
4
  import { clientIp, logActivity, type Session } from '../session.ts';
5
5
  import { isAdmin } from './locks.ts';
6
+ import { releaseCheckRegion } from './workspace-home.ts';
6
7
  import { back, BASE, csrf, developer, flash, region, send, shell, type Req } from './ui.ts';
7
8
 
8
9
  // Workspace utilities → Instance settings (administrators; APEX: instance
@@ -37,6 +38,7 @@ export async function instanceRoutes(app: FastifyInstance) {
37
38
  <small class="help">${x.help} In effect: <b>${instanceSetting(x.key)}</b> (${ORIGIN_TEXT[from]}; <code>${x.env}</code>, default ${x.default}).</small></div>`;
38
39
  })}</div>
39
40
  <div class="buttons"><button class="btn btn-hot">Save</button></div></form>`)}
41
+ ${await releaseCheckRegion(s)}
40
42
  ${region('Configuration', html`<p class="muted u-mt0">Environment variables of this server (chapter 1 of the guide). Secrets show only whether they are set.</p>
41
43
  <div class="table-wrap"><table class="report report-reflow"><thead><tr><th>Variable</th><th>Value</th><th>Purpose</th></tr></thead>
42
44
  <tbody>${CONFIGURATION.map((c) => {
@@ -4,6 +4,7 @@ import { html, raw, type Raw } from '../html.ts';
4
4
  import { icon } from '../icons.ts';
5
5
  import { clientIp, logActivity, type Session } from '../session.ts';
6
6
  import { back, BASE, csrf, developer, flash, type Req } from './ui.ts';
7
+ import { issuesFrom } from '../team.ts';
7
8
 
8
9
  // Page locks, the application lock and developer comments (APEX: page locks,
9
10
  // application lock in 26.1, developer comments). A developer locks a page
@@ -96,6 +97,8 @@ export async function lockPanel(s: Session, appId: number, pageNo: number, opts:
96
97
  owner.query('select id, author, body, created_at::text from meta.dev_comment where app_id = $1 and page_no = $2 order by created_at desc, id desc limit 200', [appId, pageNo]),
97
98
  isAdmin(s.username),
98
99
  ]);
100
+ // (sprint 113) a comment turned into a Team Development issue links to it
101
+ const issues = await issuesFrom('comment', comments.rows.map((c) => Number(c.id)));
99
102
  const own = locks.find((l) => l.page_no === pageNo);
100
103
  const appLock = pageNo ? locks.find((l) => l.page_no === 0) : undefined;
101
104
  const what = pageNo ? `page ${pageNo}` : 'the application';
@@ -126,7 +129,10 @@ export async function lockPanel(s: Session, appId: number, pageNo: number, opts:
126
129
  <div class="dev-comment-head"><b>${c.author}</b> <span class="muted">${String(c.created_at).slice(0, 16)}</span>
127
130
  ${c.author === s.username || admin
128
131
  ? html`<form method="post" action="${BASE}/apps/${appId}/comments/${c.id}/delete" class="u-inline">${csrf(s)}<button class="link-button" data-confirm="Delete this comment?">Delete</button></form>`
129
- : ''}</div>
132
+ : ''}
133
+ ${issues.get(Number(c.id))
134
+ ? html`<a class="small" href="/builder/team/issues/${issues.get(Number(c.id))}">${icon('kanban')} Issue #${issues.get(Number(c.id))}</a>`
135
+ : html`<form method="post" action="/builder/team/from-comment" class="u-inline">${csrf(s)}<input type="hidden" name="comment" value="${c.id}"><button class="link-button">Make an issue</button></form>`}</div>
130
136
  <p class="dev-comment-body">${c.body}</p></li>`)}</ul>`
131
137
  : html`<p class="muted">No comments yet.</p>`}
132
138
  </div>`;
@@ -22,8 +22,8 @@ export const REGION_CONFIG_HELP: [string[], string][] = [
22
22
  [['report', 'chart', 'cards', 'dynamic', 'tree', 'template_component'], '{"lazy":true} loads it after the page shows, {"cache":{"scope":"user"|"session"|"all","seconds":300}} keeps its HTML (a submit of the page empties it)'],
23
23
  [['data_reporter'], '{"sources":[{"id":"orders","label":"Orders","description":"…","schema":"sales","table":"order_v","columns":[{"name":"total","label":"Total","format":"FML999G990D00"}]}],"sharing":true,"share_authz":"SCHEME","page_size":25} (the Data Reporter settings below edit it)'],
24
24
  [['form_designer'], '{"sources":[{"id":"orders","label":"Orders","description":"…","schema":"sales","table":"orders","key":"id","columns":[{"name":"customer","label":"Customer"},{"name":"status","lov":"LOV:ORDER_STATUS"}],"insert":true,"update":true,"delete":false}],"design_authz":"SCHEME","page_size":25} (the Form Designer region\'s Settings; users that pass design_authz design forms)'],
25
- [['ai_assistant'], '{"service":"NAME","system":"…","welcome":"…","context":[{"name":"policy","sql":"select … :AI_PROMPT …"}],"tools":[{"name":"my_leave","description":"…","sql":"select … where status = :STATUS","parameters":{"STATUS":{"type":"string","enum":["PENDING"]}}},{"name":"dept","type":"rest","source":"DEPARTMENT","description":"…"}],"max_rounds":5,"max_turns":20} (the AI assistant settings below edit it)'],
26
- [['report'], '{"ai_filter":{"service":"NAME"}} adds an "Ask in your own words" box (natural-language filters)'],
25
+ [['ai_assistant'], '{"service":"NAME","system":"…","welcome":"…","context":[{"name":"policy","sql":"select … :AI_PROMPT …"}],"tools":[{"name":"my_leave","description":"…","sql":"select … where status = :STATUS","parameters":{"STATUS":{"type":"string","enum":["PENDING"]}}},{"name":"dept","type":"rest","source":"DEPARTMENT","description":"…"}],"max_rounds":5,"max_turns":20}; or {"agent":"SALES_AGENT","welcome":"…"} for an AI agent of Shared Components (the AI assistant settings below edit it)'],
26
+ [['report'], '{"ai_filter":{}} adds an "Ask in your own words" box: the question becomes the report\'s settings, shown as chips (built-in phrases; {"service":"NAME"} uses an AI service)'],
27
27
  [['plugin'], '{"plugin":"name","attributes":{"NAME":"value"}} (a region plug-in; a Source SELECT feeds its template)'],
28
28
  [['form'], '{"lost_update":false} saves without checking that the row is unchanged since it was shown'],
29
29
  [['login'], '(no attributes) the sign-in form of the application\'s login page (Application settings → Login page): providers, user name and password, "Keep me signed in", "Forgot password?"'],
@@ -65,7 +65,7 @@ const clip = (v: string | undefined, max: number) => (v ?? '').trim().slice(0, m
65
65
  * except binary ones.
66
66
  */
67
67
  export async function mergeReporterSettings(
68
- config: Config, b: Body, a: { authz: Set<string> },
68
+ config: Config, b: Body, a: { authz: Set<string>; datasets?: Set<string> },
69
69
  lookup: { byName: (schema: string, table: string) => Promise<DbObject | null>; byOid: (oid: number) => Promise<DbObject | null> } = { byName: findObject, byOid: objectByOid },
70
70
  ): Promise<{ config: Config; errors: string[] }> {
71
71
  const out: Config = { ...config };
@@ -80,6 +80,13 @@ export async function mergeReporterSettings(
80
80
  delete out.share_authz;
81
81
  if (b.sharing === 'off') out.sharing = false;
82
82
  else if (b.sharing?.startsWith('authz:') && a.authz.has(b.sharing.slice(6).toUpperCase())) out.share_authz = b.sharing.slice(6);
83
+ // (sprint 110) who may edit reports, who may unpublish and delete anyone's, published reports
84
+ for (const k of ['edit_authz', 'admin_authz'] as const) {
85
+ delete out[k];
86
+ if (b[k] && a.authz.has(b[k]!.toUpperCase())) out[k] = b[k];
87
+ }
88
+ delete out.publishing;
89
+ if (b.publishing === 'true') out.publishing = true;
83
90
 
84
91
  const sources: Source[] = [];
85
92
  const existing = sourcesOf({ config });
@@ -87,6 +94,13 @@ export async function mergeReporterSettings(
87
94
  const s = existing.find((x) => x.id === b[`s${i}_key`]);
88
95
  if (!s || sources.some((x) => x.id === s.id)) continue;
89
96
  if (b[`s${i}_remove`] === 'true') continue;
97
+ if (s.dataset) {
98
+ // (sprint 110) a dataset: its columns are the dataset's (SQL Workshop → Data Reporter); label and description may differ here
99
+ const label = clip(b[`s${i}_label`], 80);
100
+ const description = clip(b[`s${i}_description`], 300);
101
+ sources.push({ id: s.id, dataset: s.dataset, ...(label ? { label } : {}), ...(description ? { description } : {}) } as Source);
102
+ continue;
103
+ }
90
104
  const obj = await lookup.byName(s.schema, s.table);
91
105
  const names = new Set(obj?.columns.map((c) => c.name));
92
106
  const columns: SourceColumn[] = [];
@@ -129,6 +143,17 @@ export async function mergeReporterSettings(
129
143
  sources.push({ id, label, schema: obj.schema, table: obj.table, columns });
130
144
  }
131
145
  }
146
+ // (sprint 110) a dataset of the workspace as a new source
147
+ if (b.new_dataset) {
148
+ const name = b.new_dataset.trim().toLowerCase();
149
+ if (!a.datasets?.has(name)) errors.push('Choose one of the workspace\'s datasets.');
150
+ else if (sources.length >= MAX_SOURCES) errors.push(`A region offers at most ${MAX_SOURCES} data sources.`);
151
+ else {
152
+ let id = name.slice(0, 36);
153
+ for (let n = 2; sources.some((s) => s.id === id); n++) id = `${name.slice(0, 36)}_${n}`;
154
+ sources.push({ id, dataset: name } as Source);
155
+ }
156
+ }
132
157
  if (sources.length) out.sources = sources;
133
158
  else delete out.sources;
134
159
  return { config: out, errors };
@@ -145,8 +170,23 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
145
170
  const objects = await objectList(app?.db_role ?? null);
146
171
  const sources = sourcesOf({ config: cfg });
147
172
  const sharing = cfg.sharing === false ? 'off' : typeof cfg.share_authz === 'string' && cfg.share_authz ? `authz:${cfg.share_authz}` : '';
173
+ const datasets = (await owner.query<{ name: string; label: string }>('select name, label from meta.dataset where workspace_id = meta.app_workspace($1) order by name', [appId])).rows;
148
174
  const sourceSets = await Promise.all(
149
175
  sources.map(async (src, i) => {
176
+ if (src.dataset) {
177
+ const d = datasets.find((x) => x.name === src.dataset);
178
+ return html`<fieldset class="prop-group"><legend>${src.label || d?.label || src.id} <span class="muted">(dataset ${src.dataset})</span></legend>
179
+ <input type="hidden" name="s${i}_key" value="${src.id}">
180
+ ${!d ? html`<div class="alert alert-error" role="alert">The workspace has no dataset ${src.dataset} (any more).</div>` : ''}
181
+ <div class="form-grid">
182
+ <div class="field"><label class="label" for="${id(`s${i}_id`)}">Static id</label><input id="${id(`s${i}_id`)}" value="${src.id}" readonly></div>
183
+ <div class="field"><label class="label" for="${id(`s${i}_label`)}">Label</label><input id="${id(`s${i}_label`)}" name="s${i}_label" maxlength="80" value="${src.label ?? ''}" placeholder="${d?.label ?? ''}"></div>
184
+ <div class="field" data-wide><label class="label" for="${id(`s${i}_description`)}">Description (shown to users)</label><input id="${id(`s${i}_description`)}" name="s${i}_description" maxlength="300" value="${src.description ?? ''}" placeholder="the dataset's"></div>
185
+ </div>
186
+ <p class="muted">Its tables, columns, labels, masks and row filter are the dataset's: <a href="${BASE}/reporter">App Builder → Data Reporter</a>.</p>
187
+ <div class="field"><label class="check"><input type="checkbox" name="s${i}_remove" value="true"> Remove this data source (users' reports on it stop working)</label></div>
188
+ </fieldset>`;
189
+ }
150
190
  const obj = await findObject(src.schema, src.table);
151
191
  const offered = new Map(src.columns.map((c) => [c.name, c]));
152
192
  const all = [...(obj?.columns ?? []).map((c) => ({ name: c.name, type: c.type, missing: false })),
@@ -184,6 +224,12 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
184
224
  <select id="${id('sharing')}" name="sharing">${opt('', 'Every signed-in user', sharing)}${opt('off', 'Nobody (private reports only)', sharing)}${schemes.map((n) => opt(`authz:${n}`, `Authorization: ${n}`, sharing))}</select></div>
185
225
  <div class="field"><label class="label" for="${id('page_size')}">Rows per page</label>
186
226
  <input id="${id('page_size')}" name="page_size" type="number" min="5" max="200" value="${cfg.page_size ?? ''}" placeholder="25"></div>
227
+ <div class="field"><label class="label" for="${id('edit_authz')}">Who may build and save reports</label>
228
+ <select id="${id('edit_authz')}" name="edit_authz">${opt('', 'Every user', cfg.edit_authz ?? '')}${schemes.map((n) => opt(n, `Authorization: ${n}`, cfg.edit_authz ?? ''))}</select>
229
+ <small class="help">Others only run shared reports.</small></div>
230
+ <div class="field"><label class="label" for="${id('admin_authz')}">Who may unpublish and delete anyone's reports</label>
231
+ <select id="${id('admin_authz')}" name="admin_authz">${opt('', 'Nobody', cfg.admin_authz ?? '')}${schemes.map((n) => opt(n, `Authorization: ${n}`, cfg.admin_authz ?? ''))}</select></div>
232
+ <div class="field"><label class="check"><input type="checkbox" name="publishing" value="true"${cfg.publishing === true ? raw(' checked') : ''}> Shared reports are published: a stable URL, pins</label></div>
187
233
  <div class="field" data-wide><label class="label" for="${id('empty')}">Text when there are no rows</label>
188
234
  <input id="${id('empty')}" name="empty" maxlength="200" value="${cfg.empty ?? ''}" placeholder="No data found"></div>
189
235
  </div></fieldset>
@@ -194,7 +240,9 @@ export async function reporterSettingsForm(pageId: number, appId: number, r: { i
194
240
  <div class="field"><label class="label" for="${id('new_id')}">Static id</label><input id="${id('new_id')}" name="new_id" maxlength="40" pattern="[a-z][a-z0-9_]*" placeholder="from the name"></div>
195
241
  <div class="field"><label class="label" for="${id('new_label')}">Label</label><input id="${id('new_label')}" name="new_label" maxlength="80"></div>
196
242
  </div>
197
- <small class="help">All columns are offered at first (except binary ones); untick those users should not see. Prefer a view that shows exactly what business users may report on.</small></fieldset>
243
+ <small class="help">All columns are offered at first (except binary ones); untick those users should not see. Prefer a view that shows exactly what business users may report on.</small>
244
+ ${datasets.length ? html`<div class="form-grid"><div class="field" data-wide><label class="label" for="${id('new_dataset')}">Or a dataset of the workspace</label>
245
+ <select id="${id('new_dataset')}" name="new_dataset"><option value="">- none -</option>${datasets.map((d) => html`<option value="${d.name}">${d.label} (${d.name})</option>`)}</select></div></div>` : ''}</fieldset>
198
246
  <div class="buttons"><button class="btn btn-hot">Save Data Reporter settings</button></div>
199
247
  </form>`;
200
248
  }
@@ -210,7 +258,8 @@ export async function reporterBuilderRoutes(app: FastifyInstance) {
210
258
  : undefined;
211
259
  if (!r) return reply.code(404).send('Not found');
212
260
  const schemes = (await owner.query<{ name: string }>('select name from meta.authz_scheme where app_id = $1', [r.app_id])).rows;
213
- const { config, errors } = await mergeReporterSettings(r.config ?? {}, (req.body ?? {}) as Body, { authz: new Set(schemes.map((x) => x.name.toUpperCase())) });
261
+ const datasets = (await owner.query<{ name: string }>('select name from meta.dataset where workspace_id = meta.app_workspace($1)', [r.app_id])).rows;
262
+ const { config, errors } = await mergeReporterSettings(r.config ?? {}, (req.body ?? {}) as Body, { authz: new Set(schemes.map((x) => x.name.toUpperCase())), datasets: new Set(datasets.map((x) => x.name)) });
214
263
  await owner.query('update meta.region set config = $2 where id = $1', [r.id, JSON.stringify(config)]);
215
264
  if (errors.length) flash(s, errors.join(' '), 'error');
216
265
  else flash(s, 'Settings saved.');
@@ -2,6 +2,7 @@ import { advise } from './advisor.ts';
2
2
  import { appLocks, isAdmin, lockPanel, lockText } from './locks.ts';
3
3
  import { parseRoleList, validRoleName } from '../dbauth.ts';
4
4
  import { DEFAULT_HEADER, headerProxiesConfigured } from '../headerauth.ts';
5
+ import { appIssues } from './team.ts';
5
6
  import type { FastifyInstance } from 'fastify';
6
7
  import { owner } from '../db.ts';
7
8
  import { html, raw } from '../html.ts';
@@ -43,11 +44,11 @@ export async function builderRoutes(app: FastifyInstance) {
43
44
  }
44
45
  };
45
46
  /** Where to go after signing in: a builder page only. */
46
- const safeNext = (v: unknown) => (typeof v === 'string' && /^\/builder(\/[A-Za-z0-9_/-]{0,200})?$/.test(v) ? v : BASE);
47
+ const safeNext = (v: unknown) => (typeof v === 'string' && /^\/builder(\/[A-Za-z0-9_/-]{0,200})?$/.test(v) ? v : `${BASE}/home`);
47
48
 
48
49
  app.get(`${BASE}/login`, async (req: Req, reply) => {
49
50
  const s = await getSession(req, reply, null, BASE);
50
- if (s.username) return reply.redirect(BASE);
51
+ if (s.username) return reply.redirect(`${BASE}/home`);
51
52
  const error = takeFlash(s, '__ERROR');
52
53
  await saveState(s);
53
54
  const r = remembered(req);
@@ -99,7 +100,7 @@ export async function builderRoutes(app: FastifyInstance) {
99
100
  const { username = '', password = '' } = req.body ?? {};
100
101
  const workspace = String(req.body?.workspace ?? '').trim().slice(0, 60);
101
102
  const next = safeNext(req.body?.next);
102
- const again = next === BASE ? `${BASE}/login` : `${BASE}/login?next=${encodeURIComponent(next)}`;
103
+ const again = next === `${BASE}/home` ? `${BASE}/login` : `${BASE}/login?next=${encodeURIComponent(next)}`;
103
104
  const ip = clientIp(req);
104
105
  if (req.body?.__csrf !== s.csrf_token) {
105
106
  flash(s, 'Your session expired. Please try again.', 'error');
@@ -259,6 +260,7 @@ export async function builderRoutes(app: FastifyInstance) {
259
260
  const locks = new Map((await appLocks(a.id)).map((l) => [l.page_no, l]));
260
261
  const commentsPerPage = new Map((await owner.query('select page_no, count(*)::int as n from meta.dev_comment where app_id = $1 group by 1', [a.id])).rows.map((r) => [r.page_no, r.n]));
261
262
  const appLock = locks.get(0);
263
+ const issues = await appIssues(a.id);
262
264
 
263
265
  const main = html`
264
266
  ${appHeader(a, 'pages')}
@@ -282,7 +284,7 @@ export async function builderRoutes(app: FastifyInstance) {
282
284
  : html`<div class="table-wrap"><table class="report">
283
285
  <thead><tr><th class="num">Page</th><th>Name</th>${grouped ? html`<th>Group</th>` : ''}<th>Mode</th><th class="num">Regions</th><th class="num">Items</th><th class="num">DAs</th><th class="num">Processes</th><th>Authorization</th><th>Protection</th><th>Lock</th><th></th></tr></thead>
284
286
  <tbody id="pages-rows">${shownPages.map((p) => html`<tr>
285
- <td class="num">${p.page_no}</td><td><a href="${designerUrl(a.id, p.page_no)}">${p.name}</a>${commentsPerPage.get(p.page_no) ? html` <span class="tag" title="Developer comments">${commentsPerPage.get(p.page_no)} comment${commentsPerPage.get(p.page_no) === 1 ? '' : 's'}</span>` : ''}</td>${grouped ? html`<td>${p.page_group ?? '—'}</td>` : ''}<td>${p.mode}</td>
287
+ <td class="num">${p.page_no}</td><td><a href="${designerUrl(a.id, p.page_no)}">${p.name}</a>${commentsPerPage.get(p.page_no) ? html` <span class="tag" title="Developer comments">${commentsPerPage.get(p.page_no)} comment${commentsPerPage.get(p.page_no) === 1 ? '' : 's'}</span>` : ''}${issues.tag(p.page_no)}</td>${grouped ? html`<td>${p.page_group ?? '—'}</td>` : ''}<td>${p.mode}</td>
286
288
  <td class="num">${p.regions}</td><td class="num">${p.items}</td><td class="num">${p.das}</td><td class="num">${p.processes}</td>
287
289
  <td>${p.requires_auth ? (p.authz ?? '—') : 'public'}</td><td>${p.protection}</td>
288
290
  <td>${((l) => (l ? html`<span class="lock-tag" title="${lockText(l)}">${icon('key')}<span>${l.locked_by === s.username ? 'you' : l.locked_by}</span></span>` : '—'))(locks.get(p.page_no))}</td>
@@ -323,6 +325,7 @@ export async function builderRoutes(app: FastifyInstance) {
323
325
  <li><a href="${BASE}/apps/${a.id}/backups">${icon('history')} Backups</a></li>
324
326
  <li><a href="${BASE}/apps/${a.id}/supporting-objects">${icon('database')} Supporting objects</a></li>
325
327
  <li><a href="#app-lock">${icon('lock')} Lock the application</a></li>
328
+ ${issues.task}
326
329
  <li><a href="${BASE}/apps/${a.id}/settings?tab=definition">${icon('trash')} Delete the application</a></li>
327
330
  </ul></aside>
328
331
  </div>`;
@@ -71,7 +71,7 @@ export function sharedGroups(appId: number): { key: string; title: string; icon:
71
71
  { key: 'data', title: 'Data Sources', icon: 'database', items: [t('rest_source', 'REST Data Sources'), t('web_credential', 'Web Credentials'), t('rest_module', 'RESTful Services'), t('data_load_def', 'Data Load Definitions')] },
72
72
  { key: 'workflows', title: 'Workflows and Automations', icon: 'activity', items: [t('workflow_definition', 'Workflows'), t('task_definition', 'Task Definitions'), t('automation', 'Automations')] },
73
73
  { key: 'globalization', title: 'Globalization', icon: 'globe', items: [page('globalization', 'Translations and Text Messages'), t('dynamic_translation', 'Dynamic Translations'), settings('globalization', 'Globalization Attributes')] },
74
- { key: 'ai', title: 'Generative AI', icon: 'lightbulb', items: [page('ai', 'AI Services')] },
74
+ { key: 'ai', title: 'Generative AI', icon: 'lightbulb', items: [page('ai', 'AI Services'), page('ai-agents', 'AI Agents')] },
75
75
  ];
76
76
  }
77
77
 
@@ -23,6 +23,7 @@ const TYPE_HELP: Record<AppType, string> = {
23
23
  theme: 'Its theme (colours, navigation, Theme Roller styles) and template components are offered to other applications.',
24
24
  library: 'Its lists of values, authorization schemes, build options, template components and lists are offered to other applications.',
25
25
  boilerplate: 'A starting point: Create application can copy it.',
26
+ reporting: 'Made by App Builder → Data Reporter on datasets of the workspace: its users build, publish and share reports.',
26
27
  };
27
28
 
28
29
  const what = (kind: Kind, name: string) => (kind === 'theme' ? 'Theme' : `${KINDS[kind].label} ${name}`);