@abgov/adsp-sdk-mcp-server 1.20.1 → 1.21.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.
- package/README.md +5 -0
- package/assets/docs/platform/deployment.md +0 -1
- package/assets/docs/platform/getting-started.md +0 -1
- package/assets/docs/platform/operations.md +0 -1
- package/assets/docs/platform/platform-django-sdk.md +0 -1
- package/assets/docs/platform/platform-dotnet-sdk.md +0 -1
- package/assets/docs/platform/platform-flask-sdk.md +0 -1
- package/assets/docs/platform/platform-node-sdk.md +0 -1
- package/assets/docs/platform/platform-spring-sdk.md +0 -1
- package/assets/docs/services/access-service-backup-disaster-recovery.md +0 -1
- package/assets/docs/services/access-service.md +0 -1
- package/assets/docs/services/agent-service.md +28 -1
- package/assets/docs/services/audit-service.md +8 -2
- package/assets/docs/services/cache-service.md +111 -24
- package/assets/docs/services/calendar-service.md +96 -18
- package/assets/docs/services/comment-service.md +179 -49
- package/assets/docs/services/configuration-service.md +5 -1
- package/assets/docs/services/directory-service.md +134 -16
- package/assets/docs/services/event-service.md +0 -1
- package/assets/docs/services/export-service.md +135 -0
- package/assets/docs/services/feedback-service.md +46 -10
- package/assets/docs/services/file-service.md +0 -1
- package/assets/docs/services/form-service.md +30 -1
- package/assets/docs/services/notification-service.md +251 -2
- package/assets/docs/services/pdf-service.md +113 -44
- package/assets/docs/services/pii-service.md +0 -1
- package/assets/docs/services/project-planner-service.md +215 -43
- package/assets/docs/services/push-service.md +159 -73
- package/assets/docs/services/status-service.md +1 -2
- package/assets/docs/services/task-service.md +262 -99
- package/assets/docs/services/tenant-service.md +113 -2
- package/assets/docs/services/token-handler.md +0 -1
- package/assets/docs/services/value-service.md +13 -1
- package/assets/docs/services/verify-service.md +60 -36
- package/assets/docs/tutorials/access-service/access-service.md +0 -1
- package/assets/docs/tutorials/feedback-service/feedback-service.md +0 -1
- package/assets/docs/tutorials/file-service/file-service.md +0 -1
- package/assets/docs/tutorials/form-service/form-service.md +0 -1
- package/assets/docs/tutorials/notification-service/notification-service.md +0 -1
- package/assets/docs/tutorials/pdf-service/building-a-template.md +2 -2
- package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +17 -10
- package/assets/docs/tutorials/pdf-service/pdf-service.md +0 -1
- package/assets/docs/tutorials/status-service/notifications.md +1 -1
- package/assets/docs/tutorials/status-service/status-service.md +0 -1
- package/assets/docs/tutorials/task-service/introduction.md +1 -1
- package/assets/docs/tutorials/task-service/task-definitions.md +1 -1
- package/assets/docs/tutorials/task-service/task-queues.md +13 -11
- package/assets/docs/tutorials/task-service/task-service.md +0 -1
- package/package.json +1 -1
- package/src/http.d.ts +10 -0
- package/src/http.js +105 -0
- package/src/http.js.map +1 -0
- package/src/main.js +4 -82
- package/src/main.js.map +1 -1
- package/src/sdk-reference/reference.js +21 -2
- package/src/sdk-reference/reference.js.map +1 -1
- package/src/server.d.ts +6 -0
- package/src/server.js +17 -6
- package/src/server.js.map +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: Project planner service
|
|
4
|
-
nav_order: 20
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
8
7
|
# Project planner service
|
|
9
8
|
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
10
11
|
Project planner service helps people new to ADSP describe a business problem and turn it into a plan for using ADSP services. It builds a structured _business model_ of the problem, matches it to known GoA _business patterns_, proposes _solution hypotheses_ with recommended services, and points the user to each service's workspace.
|
|
11
12
|
|
|
12
13
|
Recommendations are hypotheses for the user to refine; the planner is not a replacement for early discovery or business analysis.
|
|
@@ -20,18 +21,75 @@ client `urn:ads:platform:project-planner-service`
|
|
|
20
21
|
| planner-admin | Administrator role. Allows access to all solutions in the tenant. |
|
|
21
22
|
| planner-user | User role. Allows creating and working on own solutions. |
|
|
22
23
|
|
|
24
|
+
Every endpoint requires one of these roles. `planner-admin` is part of the tenant admin role, and is also required to create, update, and delete business patterns.
|
|
25
|
+
|
|
26
|
+
## Tenancy
|
|
27
|
+
|
|
28
|
+
- **Tenant users only.** Users act on the tenant of their token, and need `planner-user` or `planner-admin` in that tenant. Core (platform) users aren't granted access: requests from a core user respond `403`, or `400` when they don't set a `tenantId` query parameter, because there is no tenant context.
|
|
29
|
+
- **Solutions** belong to the tenant and to the user who created them. A `planner-user` sees and works on only their own solutions; a `planner-admin` can see and work on all solutions in the tenant. Only the user who created a solution can delete it, even if another user is a `planner-admin`. Other users receive `403`.
|
|
30
|
+
- **Saved versions** belong to their solution, and follow the same access rules.
|
|
31
|
+
- **Specialist chats** are private to the user who had the conversation, including from `planner-admin`. Chats of other users respond `404`.
|
|
32
|
+
- **Business patterns** combine platform and tenant data. The built-in patterns are the same for every tenant. A tenant overrides them with patterns in its configuration (`patterns`, in the `platform:project-planner-service` configuration), and those are in turn overridden by patterns stored through the API. Patterns stored through the API belong to the tenant.
|
|
33
|
+
- **Isolation.** IDs of solutions, versions, and chats from another tenant respond `404`, not `403`.
|
|
34
|
+
|
|
35
|
+
## API overview
|
|
36
|
+
|
|
37
|
+
All endpoints are under `https://project-planner-service.adsp.alberta.ca/planner/v1` and require a bearer token. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
|
|
38
|
+
|
|
39
|
+
| Area | Endpoints | Required role |
|
|
40
|
+
| :----------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------- |
|
|
41
|
+
| Analysis options | `GET /analysis/options` | planner-user or planner-admin |
|
|
42
|
+
| Business patterns | `GET /patterns`, `GET /patterns/{patternId}`, `POST /patterns/match` | planner-user or planner-admin |
|
|
43
|
+
| | `POST /patterns`, `PUT /patterns/{patternId}`, `DELETE /patterns/{patternId}` | planner-admin |
|
|
44
|
+
| Problem statement upload | `POST /documents/extract` | planner-user or planner-admin |
|
|
45
|
+
| Solutions | `GET /solutions`, `POST /solutions` | planner-user (own solutions) or planner-admin (all in the tenant) |
|
|
46
|
+
| | `GET /solutions/{id}`, `PATCH /solutions/{id}` | planner-user (creator) or planner-admin |
|
|
47
|
+
| | `DELETE /solutions/{id}` | planner-user or planner-admin, and the creator of the solution |
|
|
48
|
+
| Planner workflow | `POST /solutions/{id}/analyze`, `/discovery`, `/chat`, `/blueprint`, `/consult/{service}`, `PUT /solutions/{id}/components/{order}/review` | planner-user (creator) or planner-admin |
|
|
49
|
+
| Versions and export | `GET /solutions/{id}/export`, `GET /solutions/{id}/versions`, `POST /solutions/{id}/versions/checkpoint`, `PATCH /solutions/{id}/versions/{number}`, `GET /solutions/{id}/versions/{number}/export` | planner-user (creator) or planner-admin |
|
|
50
|
+
| Specialists | `GET /specialists`, `POST /specialists/{service}/chat` | planner-user or planner-admin |
|
|
51
|
+
| Saved specialist chats | `GET /specialists/chats`, `GET /specialists/chats/export`, `GET /specialists/chats/{chatId}`, `GET /specialists/chats/{chatId}/export`, `DELETE /specialists/chats/{chatId}` | planner-user or planner-admin (own chats only) |
|
|
52
|
+
|
|
53
|
+
The export endpoints return JSON with a `Content-Disposition: attachment` header. `POST /solutions/{id}/chat` returns the updated solution as JSON; it isn't a stream.
|
|
54
|
+
|
|
55
|
+
Tenant patterns can also be set in the configuration service; see [Business pattern library](#business-pattern-library).
|
|
56
|
+
|
|
23
57
|
## Concepts
|
|
24
58
|
|
|
25
59
|
### Solution
|
|
26
60
|
|
|
27
61
|
The persistent state of a planning effort: problem statement, business concepts (actors, goals, activities, decisions, evidence, business rules, constraints, evaluation criteria, workflows, outcomes, documents, events, external systems, assumptions, unknowns), decisions with the reasons they were made, open questions, pattern matches, hypotheses, specialist progress, artifacts and next steps. A solution survives across sessions so users do not need to repeat information.
|
|
28
62
|
|
|
63
|
+
### Discovery
|
|
64
|
+
|
|
65
|
+
`POST /solutions/{id}/discovery` is a discovery conversation. The planner replies with one message of clarifying questions and scores six factors (problem, users, process, information, communication, constraints). The solution is analyzed and presented (`state.discovery.ready`) once the average (`state.confidence.score`) reaches 75 and every individual factor is at least 40, or when `force` is true. `restart` clears the discovery thread. Replies keep working after the solution is presented: each one re-runs the analysis, so the solution is refined from the discovery answers.
|
|
66
|
+
|
|
67
|
+
`POST /solutions/{id}/chat` sends a message after analysis; the analysis is refined using the answers and conversation, and the reply is appended to `state.conversation`.
|
|
68
|
+
|
|
69
|
+
### Blueprint
|
|
70
|
+
|
|
71
|
+
`POST /solutions/{id}/blueprint` generates the complete project blueprint (`state.blueprint`): overview, technical architecture (layers and diagram), ADSP service mapping, notes from specialist consultations of every recommended service, components to set up, core workflows, data and governance, delivery plan, and acceptance criteria. Saved consultations are reused unless `refreshConsultations` is true. The solution must be analyzed first. Users review each component (`PUT /solutions/{id}/components/{order}/review`); rejected components are left out of exports.
|
|
72
|
+
|
|
73
|
+
### Versions
|
|
74
|
+
|
|
75
|
+
A solution's content is saved as a numbered version whenever an operation changes it. `PATCH /solutions/{id}`, `/analyze` and `/blueprint` accept `checkpoint: false` to skip saving, which lets a client combine several calls into one version and then call `POST /solutions/{id}/versions/checkpoint`. Versions can be renamed and downloaded; `GET /solutions/{id}/export` downloads the current solution, including any unsaved changes.
|
|
76
|
+
|
|
29
77
|
### Business pattern
|
|
30
78
|
|
|
31
79
|
A template describing a typical GoA application type: domain language, strong and weak signals, likely service mappings, clarifying questions, assumptions and known unknowns. The 19 application types from the planner requirements are built in (Case Management is fully specified). Tenants can extend or override patterns through configuration in the `platform:project-planner-service` namespace and name.
|
|
32
80
|
|
|
33
81
|
Matching is deterministic: each domain term counts 1 and each strong signal counts 2. Weak signals never add to the score. A score of 8 or more is high confidence, 4 or more is medium, otherwise low; low confidence results include the pattern's clarifying questions.
|
|
34
82
|
|
|
83
|
+
### Business pattern library
|
|
84
|
+
|
|
85
|
+
The service ships 19 built-in business patterns (case management, grant applications, permit/licence, registration, inspection, complaint intake, consultation, eligibility, booking, document submission, incident reporting, FOIP-style requests, referral routing, status tracking, audit trail, public reporting, document generation, notification subscriptions, internal service requests). Each pattern provides: name, purpose, domain language, common features (`commonFeatures`), strong signals, weak or misleading signals, likely ADSP service mappings (each with a reason), clarifying questions, assumptions and known unknowns. Tenants manage patterns through the API (`planner-admin` role only for writes):
|
|
86
|
+
|
|
87
|
+
- `POST /patterns` creates a custom pattern. The `id` is optional and defaults to a slug of the name.
|
|
88
|
+
- `PUT /patterns/{id}` updates a pattern. Updating a built-in pattern stores a tenant copy that overrides it.
|
|
89
|
+
- `DELETE /patterns/{id}` deletes a custom pattern. Deleting a customized built-in pattern restores the built-in version. Built-in patterns themselves cannot be deleted.
|
|
90
|
+
|
|
91
|
+
Each pattern returned by the API has a `source` of `built-in`, `customized` or `custom`. The effective catalogue is built-in patterns, overridden by configuration (`patterns`), overridden by tenant patterns stored through the API, and it feeds both rule-based matching and AI analysis. Service mappings must reference a known specialist service.
|
|
92
|
+
|
|
35
93
|
### Specialist
|
|
36
94
|
|
|
37
95
|
Each ADSP service has a specialist definition with questions, dependencies, risks and a workspace path. Consulting a specialist reports fit for the solution, questions to ask, dependency status and risks.
|
|
@@ -41,38 +99,11 @@ Specialists have two responsibilities:
|
|
|
41
99
|
1. **Guide the planner.** When the planner consults a specialist (`POST /solutions/{id}/consult/{service}`), the result states whether the service is a good fit (`fit`), which parts of the solution it can support (`supports`), constraints, dependencies and risks the planner may not have considered, and, when a plan is supplied in `proposal`, a `validation` verdict (`sound`, `needs-changes` or `not-a-fit`) with findings.
|
|
42
100
|
2. **Guide a user directly.** `POST /specialists/{service}/chat` is a multi-turn conversation with a single service specialist and needs no planner session. The `intent` selects the task: `ask` (answer questions), `recommend` (service-specific solutions), `design` (refine a service-specific design), `validate` (verdict and findings) or `sample` (sample code or configuration). The response contains `chatId`, `reply`, `suggestions`, `samples`, `validation` and `followUps`. An optional `solutionId` gives the specialist the solution context. Without AI, a rule-based reply with the service's questions and pitfalls is returned.
|
|
43
101
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| :----------------- | :------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
50
|
-
| GET | /patterns, /patterns/{patternId} | Retrieve business patterns. |
|
|
51
|
-
| POST | /patterns/match | Match free text against patterns. |
|
|
52
|
-
| POST | /patterns | Create a custom pattern (admin). |
|
|
53
|
-
| PUT | /patterns/{id} | Update or customize a pattern (admin). |
|
|
54
|
-
| DELETE | /patterns/{id} | Delete a custom pattern or reset a customized built-in (admin). |
|
|
55
|
-
| GET | /specialists | Retrieve service specialists. |
|
|
56
|
-
| GET, POST | /solutions | List own solutions (all for planner-admin) or create one. |
|
|
57
|
-
| GET, PATCH, DELETE | /solutions/{id} | Retrieve, update, or delete a solution. |
|
|
58
|
-
| POST | /solutions/{id}/analyze | Extract concepts, match patterns, generate hypotheses and next steps. Body `mode` is `ai` (default when a model is configured) or `rules`. |
|
|
59
|
-
| POST | /solutions/{id}/consult/{service} | Consult a service specialist. Optional body `question`, `proposal` and `mode`. |
|
|
60
|
-
| POST | /specialists/{service}/chat | Converse directly with a service specialist. Body `message` (required), `chatId` (continues a saved chat), `intent`, `solutionId`, `mode`. The server keeps the history. |
|
|
61
|
-
| GET | /specialists/chats | List your saved specialist chats (filters service, solutionId). |
|
|
62
|
-
| GET | /specialists/chats/export | Download all your chats as JSON. |
|
|
63
|
-
| GET | /specialists/chats/{chatId} | Load a saved chat. |
|
|
64
|
-
| GET | /specialists/chats/{chatId}/export | Download one chat as JSON. |
|
|
65
|
-
| DELETE | /specialists/chats/{chatId} | Delete a saved chat. |
|
|
66
|
-
| POST | /solutions/{id}/chat | Send a message (`{message, mode}`); the analysis is refined using the answers and conversation and the reply is appended to `state.conversation`. |
|
|
67
|
-
| POST | /solutions/{id}/blueprint | Generates the complete project blueprint (`state.blueprint`): overview, technical architecture (layers and diagram), ADSP service mapping, notes from specialist consultations of every recommended service, core workflows, data and governance, and delivery plan. Saved consultations are reused; body `{mode?, refreshConsultations?}`. Requires an analyzed solution (400 otherwise). |
|
|
68
|
-
| POST | /solutions/{id}/discovery | Discovery conversation (Compressed View Mode 2). Body `{message?, mode?, force?, restart?}`. The planner replies with one message of clarifying questions and scores six factors (problem, users, process, information, communication, constraints). The solution is analyzed and presented (`state.discovery.ready`) once the average (`state.confidence.score`) reaches 75 AND every individual factor is at least 40, or when `force` is true. `restart` clears the discovery thread. Replies keep working after the solution is presented: each one re-runs the analysis, so the solution is refined from the discovery answers. |
|
|
69
|
-
| PUT | /solutions/{id}/questions/{questionId} | Answer a clarifying question (`{answer}`); an empty answer reopens it. |
|
|
70
|
-
| GET | /solutions/{id}/export | Download the solution as a JSON attachment. |
|
|
71
|
-
| GET | /analysis/options | Available analysis modes, the default mode and the model name. |
|
|
72
|
-
|
|
73
|
-
## AI analysis
|
|
74
|
-
|
|
75
|
-
AI analysis calls an OpenAI-compatible chat completions endpoint (the GoA Model as a Service) and is the default mode when `MAAS_API_KEY` is set. The result is validated against the pattern catalog and specialist list. If the model call fails or is not configured, the service falls back to rule-based analysis and records a warning in the solution `analysis` field. Requests retry up to 3 times with exponential backoff on 5xx, 429 and network errors.
|
|
102
|
+
A chat holds up to 200 messages; start a new chat when it is full.
|
|
103
|
+
|
|
104
|
+
### AI analysis
|
|
105
|
+
|
|
106
|
+
AI analysis calls an OpenAI-compatible chat completions endpoint (the GoA Model as a Service) and is the default mode when `MAAS_API_KEY` is set. `GET /analysis/options` reports the available modes, the default mode and the model name. The result is validated against the pattern catalog and specialist list. If the model call fails or is not configured, the service falls back to rule-based analysis and records a warning in the solution `analysis` field. Requests retry up to 3 times with exponential backoff on 5xx, 429 and network errors.
|
|
76
107
|
|
|
77
108
|
| environment variable | default | description |
|
|
78
109
|
| :------------------- | :---------------------------- | :-------------------------------------------------------------------------------- |
|
|
@@ -83,17 +114,158 @@ AI analysis calls an OpenAI-compatible chat completions endpoint (the GoA Model
|
|
|
83
114
|
|
|
84
115
|
## Events
|
|
85
116
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
| solution-
|
|
117
|
+
The service sends these domain events in the `project-planner-service` namespace. Each payload includes the solution's `id`, `name`, `scenario` and `status`, and the user who made the change. The service doesn't consume events.
|
|
118
|
+
|
|
119
|
+
| name | description |
|
|
120
|
+
| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
121
|
+
| solution-created | Signalled when a solution is created. |
|
|
122
|
+
| solution-updated | Signalled when a solution is updated, analyzed or consulted. `operation` is one of `update`, `analyze`, `chat`, `discovery`, `consult`, `blueprint`, `component-review`, `specialist-chat`, `version-saved` or `version-renamed`. |
|
|
123
|
+
| solution-deleted | Signalled when a solution is deleted. |
|
|
124
|
+
|
|
125
|
+
## Audit actions
|
|
126
|
+
|
|
127
|
+
Project planner service records audit events in the `project-planner-service` namespace of the [audit service](audit-service.md). Records are written to the tenant of the solution, pattern or chat, with the signed-in user (ID, name and roles, without the email address) as the actor. The correlation ID is the trace ID of the request when tracing is on. Metadata holds only IDs, counts and enumerated values: problem statements, conversation and chat messages, chat titles, AI prompts and responses, and blueprint content are never recorded. All actions are version 1. Actions do not set a retention class; the audit service derives it from the category (`compliance` for administrative and data-access actions, `standard` for runtime actions), as shown in the table.
|
|
128
|
+
|
|
129
|
+
| action | category | severity | retention class | recorded when |
|
|
130
|
+
|:-|:-|:-|:-|:-|
|
|
131
|
+
| planner.solution.created | administrative | info | compliance | A solution is created (`POST /solutions`), with the `scenario` in the metadata. |
|
|
132
|
+
| planner.solution.deleted | administrative | warning | compliance | A solution is deleted by its owner (`DELETE /solutions/{id}`), with its `scenario` and `status`. |
|
|
133
|
+
| planner.solution.exported | data-access | info | compliance | A solution is downloaded (`GET /solutions/{id}/export`, `scope: 'solution'` with the latest `version` and `unsavedChanges`) or a saved version is downloaded (`GET /solutions/{id}/versions/{number}/export`, `scope: 'version'` with the `version`). |
|
|
134
|
+
| planner.solution.admin-accessed | data-access | info | compliance | A `planner-admin` successfully reads, changes or exports a solution owned by another user, with the `ownerId` and the `operation` (`read`, `update` or `export`) in the metadata. Reading the solution or its versions is `read`; changes, analysis, discovery, chat, consultations, blueprints, component reviews and version checkpoints or renames are `update`. A specialist chat that uses the solution as context is `read`, or `update` when the chat changes the solution. |
|
|
135
|
+
| planner.solution.analyzed | runtime | info | standard | A request sends solution content to the AI model, with the `endpoint` (`analyze`, `discovery`, `chat`, `blueprint`, `consult` or `specialist-chat`), the `mode` of the result (`ai`, or `rules` after a fallback), the configured `model`, whether any model call in the request `fellBack` to rules, and the specialist `service` for consultations and specialist chats. |
|
|
136
|
+
| planner.pattern.created | administrative | info | compliance | A tenant pattern is created (`POST /patterns`), with `source: 'custom'`. |
|
|
137
|
+
| planner.pattern.updated | administrative | info | compliance | A pattern is updated or a built-in pattern is customized (`PUT /patterns/{id}`), with the `source` after the update and the `previousSource`. The change set holds the before and after values of the changed pattern fields. |
|
|
138
|
+
| planner.pattern.deleted | administrative | warning | compliance | A custom pattern is deleted or a customized built-in pattern is reset (`DELETE /patterns/{id}`), with the `source` (`custom` or `customized`) of the deleted pattern. |
|
|
139
|
+
| planner.specialist-chat.exported | data-access | info | compliance | A user downloads one saved specialist chat (`scope: 'single'`) or all of their chats (`scope: 'all'`), with the `chatCount`, the specialist `service` and the `solutionId` (the filters, for an export of all chats). |
|
|
140
|
+
| planner.specialist-chat.deleted | administrative | info | compliance | A saved specialist chat is deleted, with its specialist `service` and `solutionId`. |
|
|
141
|
+
|
|
142
|
+
Solution records use `{ type: 'solution', id: <solution ID>, name: <solution name> }` as the resource, pattern records use `{ type: 'pattern', id: <pattern ID>, name: <pattern name> }`, and chat records use `{ type: 'specialist-chat', id: <chat ID> }`. An export of all chats has no single chat, so it has no resource. A pattern change set that would exceed the 16 KB audit limit is omitted, with `changeSetOmitted: true` in the metadata.
|
|
143
|
+
|
|
144
|
+
`planner.solution.analyzed` is recorded only when the model is called: rule-based requests, and AI requests when no model is configured, send nothing to the model and are not recorded. It is recorded once per request when the request completes, including when the request fails after solution content was sent to the model. A failed request is recorded with status `failure` (client error) or `error` (server error) and without a `mode`, since there is no result.
|
|
145
|
+
|
|
146
|
+
Routine reads by the solution owner (listing and reading solutions, patterns, specialists, chats and versions) are not audited, and neither is a `planner-admin` listing the solutions of the tenant. Solution updates are not recorded as separate actions; they are covered by the `solution-updated` event. Patterns defined in the `patterns` configuration are managed in the [configuration service](configuration-service.md), which records those changes in the `configuration-service` namespace. Denied and failed operations are not recorded.
|
|
147
|
+
|
|
148
|
+
Records are sent after the operation succeeds and the response is sent. Audit failures are logged and do not fail the request. On shutdown, the service waits for in-flight requests to complete and delivers the audit records still being sent before exiting. The project planner service account requires the `audit-writer` role of `urn:ads:platform:audit-service`.
|
|
149
|
+
|
|
150
|
+
Audit recording is on by default. Set the environment variable `PROJECT_PLANNER_AUDIT_ENABLED=false` on project planner service to turn it off, or `true` to turn it on regardless of the SDK `AUDIT_ENABLED` variable, which applies when `PROJECT_PLANNER_AUDIT_ENABLED` is not set. The action catalog is still registered while recording is off, so turning it back on needs only a restart.
|
|
91
151
|
|
|
92
152
|
## Business pattern library
|
|
93
153
|
|
|
94
|
-
|
|
154
|
+
## Code examples
|
|
95
155
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
156
|
+
### Create and analyze a solution
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const plannerServiceUrl = 'https://project-planner-service.adsp.alberta.ca';
|
|
160
|
+
|
|
161
|
+
const createResponse = await fetch(`${plannerServiceUrl}/planner/v1/solutions`, {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
name: 'Small business grant',
|
|
166
|
+
scenario: 'new',
|
|
167
|
+
problemStatement: 'Applicants apply for a small business grant. Staff review each application and decide.',
|
|
168
|
+
}),
|
|
169
|
+
});
|
|
170
|
+
const { id } = await createResponse.json();
|
|
171
|
+
|
|
172
|
+
const analyzeResponse = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/analyze`, {
|
|
173
|
+
method: 'POST',
|
|
174
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
175
|
+
body: JSON.stringify({ mode: 'rules' }),
|
|
176
|
+
});
|
|
177
|
+
const { state } = await analyzeResponse.json();
|
|
178
|
+
// state.patternMatches[0].patternId, state.hypotheses[0].recommendations, state.questions
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Continue the discovery conversation
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
const response = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/discovery`, {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
187
|
+
body: JSON.stringify({
|
|
188
|
+
message: 'Small businesses apply online. Program staff review and approve each application.',
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
191
|
+
const { state } = await response.json();
|
|
192
|
+
// state.discovery.ready, state.discovery.confidence, state.discovery.messages
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Generate the blueprint
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const response = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/blueprint`, {
|
|
199
|
+
method: 'POST',
|
|
200
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
201
|
+
body: JSON.stringify({}),
|
|
202
|
+
});
|
|
203
|
+
const { state } = await response.json();
|
|
204
|
+
// state.blueprint.serviceMapping, state.blueprint.components, state.blueprint.acceptance
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Ask a service specialist
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const response = await fetch(`${plannerServiceUrl}/planner/v1/specialists/form-service/chat`, {
|
|
211
|
+
method: 'POST',
|
|
212
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
213
|
+
body: JSON.stringify({ message: 'Do applicants need to sign in?', intent: 'ask', solutionId: id }),
|
|
214
|
+
});
|
|
215
|
+
const { chatId, reply, followUps } = await response.json();
|
|
216
|
+
// Pass chatId in the next message to continue the same chat.
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Extract a problem statement from a document
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const form = new FormData();
|
|
223
|
+
form.append('file', file); // A .md, .docx, .doc (HTML export) or .pdf file up to 20 MB.
|
|
224
|
+
|
|
225
|
+
const response = await fetch(`${plannerServiceUrl}/planner/v1/documents/extract`, {
|
|
226
|
+
method: 'POST',
|
|
227
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
228
|
+
body: form,
|
|
229
|
+
});
|
|
230
|
+
const { text } = await response.json();
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Save, list and download versions
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
const checkpoint = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/versions/checkpoint`, {
|
|
237
|
+
method: 'POST',
|
|
238
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
239
|
+
});
|
|
240
|
+
const { number } = await checkpoint.json();
|
|
241
|
+
|
|
242
|
+
const versions = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/versions`, {
|
|
243
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
244
|
+
});
|
|
245
|
+
const { latest, unsavedChanges, results } = await versions.json();
|
|
246
|
+
|
|
247
|
+
const download = await fetch(`${plannerServiceUrl}/planner/v1/solutions/${id}/versions/${number}/export`, {
|
|
248
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
249
|
+
});
|
|
250
|
+
const exported = await download.json();
|
|
251
|
+
// exported.version, exported.changedSections, exported.state
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Add a tenant business pattern
|
|
255
|
+
|
|
256
|
+
Requires the `planner-admin` role.
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const response = await fetch(`${plannerServiceUrl}/planner/v1/patterns`, {
|
|
260
|
+
method: 'POST',
|
|
261
|
+
headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
|
|
262
|
+
body: JSON.stringify({
|
|
263
|
+
name: 'Grant application',
|
|
264
|
+
domainLanguage: ['grant', 'applicant', 'funding', 'award'],
|
|
265
|
+
strongSignals: [{ description: 'Applicants apply for funding', keywords: ['grant', 'funding'] }],
|
|
266
|
+
serviceMappings: [{ service: 'form-service', reason: 'Collects the application.' }],
|
|
267
|
+
}),
|
|
268
|
+
});
|
|
269
|
+
const { id: patternId, source } = await response.json();
|
|
270
|
+
// patternId is 'grant-application' and source is 'custom'.
|
|
271
|
+
```
|
|
@@ -1,106 +1,192 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: Push service
|
|
4
|
-
nav_order: 7
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
8
7
|
# Push service
|
|
9
|
-
Push service provides push mode gateway to events emitted in the [event service](event-service.md). It supports server side events and web sockets via [socket.io](https://socket.io).
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Push service provides a push mode gateway to domain events sent through the [event service](event-service.md). Applications subscribe to a configured stream and receive matching events as they happen, using [socket.io](https://socket.io) or server-sent events, instead of polling.
|
|
12
|
+
|
|
13
|
+
The push service also calls tenant configured webhooks when matching domain events occur.
|
|
12
14
|
|
|
13
15
|
## Client roles
|
|
16
|
+
|
|
14
17
|
client `urn:ads:platform:push-service`
|
|
15
18
|
|
|
16
|
-
| name
|
|
17
|
-
|
|
18
|
-
| stream-listener |
|
|
19
|
+
| name | description |
|
|
20
|
+
| :-------------- | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
21
|
+
| stream-listener | Allows an account to subscribe to any stream of its tenant, including streams that are not public. Included in the tenant admin role. |
|
|
22
|
+
|
|
23
|
+
Access to each stream is mainly controlled by the stream's configuration: `publicSubscribe` lets anyone subscribe, including anonymous users, and `subscriberRoles` lists the roles that grant access in addition to `stream-listener`. Roles must be held in the stream's tenant, or by a core (platform) user.
|
|
24
|
+
|
|
25
|
+
## Tenancy
|
|
26
|
+
|
|
27
|
+
Streams and webhooks are configured per tenant in the [configuration service](configuration-service.md) under `platform:push-service`. Platform streams in the core configuration are also available to every tenant. When a tenant and the core configuration have a stream with the same ID, the core stream is used. A core stream used in a tenant's context only includes that tenant's events.
|
|
28
|
+
|
|
29
|
+
Which tenant a request acts on depends on how the caller connects:
|
|
30
|
+
|
|
31
|
+
| Connection | Tenant used |
|
|
32
|
+
| :-------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `GET /stream/v1/streams` | The `tenant` query parameter (tenant ID, for example `61f2e3a8c9b1d2e3f4a5b6c7`) if set, otherwise the tenant of the caller's token. |
|
|
34
|
+
| `GET /stream/v1/streams/{stream}` | The tenant named in the `tenant` query parameter (kebab case, for example `my-tenant`) if it exists, otherwise the token's tenant. |
|
|
35
|
+
| socket.io tenant namespace | The tenant named by the namespace (kebab case, for example `/my-tenant`) if it exists, otherwise the token's tenant. |
|
|
36
|
+
| socket.io default namespace (`/`) | The tenant of the caller's token. |
|
|
37
|
+
|
|
38
|
+
- Anonymous callers must name a tenant, and can only list and subscribe to public streams. A request with no tenant responds 400, or fails to connect on socket.io.
|
|
39
|
+
- Tenant users and service accounts can name another tenant, but can only subscribe to its public streams, since roles must be held in the stream's tenant.
|
|
40
|
+
- A core user who doesn't name a tenant subscribes to a **cross-tenant** stream from the core configuration. It includes matching events from every tenant, and needs the `stream-listener` role or one of the stream's `subscriberRoles`. Listing streams always needs a tenant.
|
|
41
|
+
- Streams of other tenants are only found when that tenant is named. Otherwise the stream responds 404.
|
|
42
|
+
|
|
43
|
+
## API overview
|
|
19
44
|
|
|
20
|
-
|
|
45
|
+
See the [API reference](https://api.adsp.alberta.ca) for request and response details of the REST endpoints.
|
|
46
|
+
|
|
47
|
+
| Endpoint | Description | Required roles |
|
|
48
|
+
| :------------------------------------ | :------------------------------------------------- | :------------------------------------------------------------------ |
|
|
49
|
+
| `GET /stream/v1/streams` | List the streams that the caller can subscribe to. | None. The result only includes streams the caller can subscribe to. |
|
|
50
|
+
| `GET /stream/v1/streams/{stream}` | Subscribe to a stream using server-sent events. | `stream-listener` or one of `subscriberRoles`, or a public stream. |
|
|
51
|
+
| socket.io connection (not in OpenAPI) | Subscribe to a stream using socket.io. | `stream-listener` or one of `subscriberRoles`, or a public stream. |
|
|
52
|
+
|
|
53
|
+
The socket.io connection is not a REST endpoint, so it isn't in the OpenAPI documentation. It works as follows:
|
|
54
|
+
|
|
55
|
+
- **URL**: `https://push-service.adsp.alberta.ca/<namespace>` with the default socket.io path (`/socket.io`). The namespace is `/` (the default namespace), or a tenant name in kebab case, for example `/my-tenant`.
|
|
56
|
+
- **Stream ID**: the `stream` query parameter of the connection. An optional `criteria` query parameter holds JSON encoded criteria (`correlationId`, `context`) that each event must match.
|
|
57
|
+
- **Authentication**: send the access token in the socket.io `auth` option as `{ token }`, or in an `Authorization: Bearer` header. The default namespace needs a valid token. Tenant namespaces also accept anonymous connections, for public streams.
|
|
58
|
+
- **Events**: each matching domain event is emitted with the event name `<namespace>:<name>` (for example `status-service:health-check-started`). The event data is the stream item: the domain event, or the stream's projection of it, with `tenantId` as the tenant URN.
|
|
59
|
+
- **Errors**: when there is no tenant, the stream doesn't exist, or the caller can't subscribe, the connection fails and the client receives a `connect_error` with the error message.
|
|
60
|
+
|
|
61
|
+
Streams and webhooks have no endpoints in the push service. They are managed through the [configuration service](configuration-service.md).
|
|
21
62
|
|
|
22
63
|
## Concepts
|
|
64
|
+
|
|
23
65
|
### Stream
|
|
24
|
-
|
|
66
|
+
|
|
67
|
+
A stream is a set of domain events that clients can subscribe to through the gateway. Each stream event identifies a domain event by `namespace` and `name`, and can have:
|
|
68
|
+
|
|
69
|
+
- `criteria`: a `correlationId` and `context` values that the event must match to be included.
|
|
70
|
+
- `map`: a projection of the event, so that clients only receive a subset of the payload. Each key is a property of the stream item and each value is a path into the domain event, for example `payload.application.name`. Mapped items always include `tenantId`, `namespace`, `name`, `correlationId` and `context`.
|
|
71
|
+
|
|
72
|
+
Streams are configured in the [configuration service](configuration-service.md) under the `platform:push-service` namespace and name. Each stream is a top level key of the configuration, with its ID as the key.
|
|
73
|
+
|
|
74
|
+
### Webhook
|
|
75
|
+
|
|
76
|
+
A webhook is a URL that the push service posts a domain event to when the event matches the webhook's `events`. Webhooks are configured under the `webhooks` key of the same configuration. Webhooks with a `targetId` and `eventTypes` are application status webhooks, triggered by [status service](status-service.md) events for that application; see the [webhooks tutorial](../tutorials/status-service/webhooks.md).
|
|
77
|
+
|
|
78
|
+
## Events
|
|
79
|
+
|
|
80
|
+
The push service consumes every domain event routed by the [event service](event-service.md), and sends matching events to stream subscribers and webhooks.
|
|
81
|
+
|
|
82
|
+
It sends this domain event:
|
|
83
|
+
|
|
84
|
+
| Event | Description |
|
|
85
|
+
| :----------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| push-service:webhook-triggered | Signalled when a webhook is called. The payload includes the webhook, the triggering event, the response status, and the response time. |
|
|
25
87
|
|
|
26
88
|
## Code examples
|
|
89
|
+
|
|
27
90
|
### Configure a stream
|
|
91
|
+
|
|
28
92
|
Streams are configured using the [configuration service](configuration-service.md).
|
|
29
93
|
|
|
30
94
|
```typescript
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
);
|
|
95
|
+
const configurationServiceUrl = 'https://configuration-service.adsp.alberta.ca';
|
|
96
|
+
const request = {
|
|
97
|
+
operation: 'UPDATE',
|
|
98
|
+
update: {
|
|
99
|
+
'application-health': {
|
|
100
|
+
id: 'application-health',
|
|
101
|
+
name: 'Application Health',
|
|
102
|
+
description: 'Includes events indicating application health.',
|
|
103
|
+
publicSubscribe: true,
|
|
104
|
+
subscriberRoles: [],
|
|
105
|
+
events: [
|
|
106
|
+
{
|
|
107
|
+
namespace: 'status-service',
|
|
108
|
+
name: 'health-check-started',
|
|
109
|
+
map: {
|
|
110
|
+
// Optional projection of the event, for example:
|
|
111
|
+
application: 'payload.application.name',
|
|
112
|
+
},
|
|
113
|
+
criteria: {
|
|
114
|
+
// Optional criteria for events included in the stream.
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
await fetch(`${configurationServiceUrl}/configuration/v2/configuration/platform/push-service`, {
|
|
123
|
+
method: 'PATCH',
|
|
124
|
+
headers: {
|
|
125
|
+
Authorization: `Bearer ${accessToken}`,
|
|
126
|
+
'Content-Type': 'application/json',
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify(request),
|
|
129
|
+
});
|
|
68
130
|
```
|
|
69
131
|
|
|
70
|
-
###
|
|
71
|
-
Server side event with Authorization header may require a polyfill. Alternatively, use a token query parameter to provide the access token.
|
|
132
|
+
### List available streams
|
|
72
133
|
|
|
73
134
|
```typescript
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
eventSource.onmessage = function(e) {
|
|
81
|
-
// on message
|
|
82
|
-
}
|
|
83
|
-
eventSource.onerror = function(err) {
|
|
84
|
-
// on error
|
|
85
|
-
}
|
|
135
|
+
const response = await fetch('https://push-service.adsp.alberta.ca/stream/v1/streams', {
|
|
136
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
137
|
+
});
|
|
138
|
+
// Streams keyed by ID, for example { 'application-health': { id, name, description, events, ... } }
|
|
139
|
+
const streams = await response.json();
|
|
140
|
+
const streamIds = Object.keys(streams);
|
|
86
141
|
```
|
|
87
142
|
|
|
88
143
|
### Connect to a stream via socket.io
|
|
89
|
-
|
|
144
|
+
|
|
145
|
+
Socket.io connections to the default namespace act on the tenant of the access token. Use a tenant namespace, for example `/my-tenant`, to connect anonymously to a public stream.
|
|
90
146
|
|
|
91
147
|
```typescript
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
148
|
+
import { io } from 'socket.io-client';
|
|
149
|
+
|
|
150
|
+
const socket = io('https://push-service.adsp.alberta.ca/', {
|
|
151
|
+
query: {
|
|
152
|
+
stream: 'application-health',
|
|
153
|
+
// Optional criteria the events must match.
|
|
154
|
+
criteria: JSON.stringify({ context: { applicationId: '64b1f2e3a8c9b1d2e3f4a5b6' } }),
|
|
155
|
+
},
|
|
156
|
+
withCredentials: true,
|
|
157
|
+
auth: async (cb) => cb({ token: await getAccessToken() }),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
socket.on('status-service:health-check-started', (item) => {
|
|
161
|
+
// Stream item, for example { tenantId, namespace, name, correlationId, context, application }.
|
|
162
|
+
console.log(item.name, item.application);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
socket.on('connect_error', (err) => {
|
|
166
|
+
// For example, the stream does not exist or the user cannot subscribe.
|
|
167
|
+
console.error(err.message);
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Connect to a stream via server-sent events
|
|
172
|
+
|
|
173
|
+
Browser `EventSource` cannot set an `Authorization` header, so use an `EventSource` polyfill that supports headers (as below), or use socket.io. Anonymous callers can subscribe to a public stream without a token by naming the tenant, for example `?tenant=my-tenant`.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
102
177
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
178
|
+
const eventSource = new EventSourcePolyfill(
|
|
179
|
+
'https://push-service.adsp.alberta.ca/stream/v1/streams/application-health',
|
|
180
|
+
{
|
|
181
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
eventSource.onmessage = function (e) {
|
|
185
|
+
// Each message is a JSON stream item.
|
|
186
|
+
const item = JSON.parse(e.data);
|
|
187
|
+
console.log(`${item.namespace}:${item.name}`, item.correlationId);
|
|
188
|
+
};
|
|
189
|
+
eventSource.onerror = function (err) {
|
|
190
|
+
// On error.
|
|
191
|
+
};
|
|
106
192
|
```
|