@quartal/messages-client 0.2.0 → 0.5.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 CHANGED
@@ -1,37 +1,37 @@
1
- # @quartal/messages-client
2
-
3
- The browser SDK of the **Quartal Messages API**. `MessagesApi` bundles every resource the UI reads
4
- and writes — channels and their listed companies, threads, messages, channel agents, the model /
5
- agent / skill catalog, companies and the signed-in user — plus the live event stream
6
- (`POST /events`, Server-Sent Events), all over HTTP with the user's bearer token. The API's access
7
- rules decide what each call sees.
8
-
9
- A pnpm workspace package of this repo (`workspace:*`); it is not published.
10
-
11
- ## Usage
12
-
13
- ```ts
14
- import { MessagesApi } from '@quartal/messages-client';
15
-
16
- const api = new MessagesApi('http://localhost:8002', () => currentAccessToken());
17
-
18
- const channels = await api.channels.getOData({ $filter: { advisory } });
19
- const threads = await api.threads.list('salaxy-payroll');
20
- await api.messages.create(threads[0].id, [{ id: crypto.randomUUID(), type: 'text', text: 'Hei', state: 'active' }]);
21
-
22
- const stop = api.events.subscribe((event) => {
23
- if (event.type === 'message') console.log(event.message.threadId, event.message.parts);
24
- });
25
- ```
26
-
27
- The catalog and channel resources (`channels`, `models`, `agents`, `skills`) keep the
28
- `ICrudApiBase` shape: `getBlank` and `validate` run locally, the API validates again on write.
29
- Failed calls reject with an `ApiError` carrying the HTTP status and the API's message.
30
-
31
- `loadClientConfig()` reads the browser settings (`VITE_MESSAGES_API_URL`, `VITE_OIDC_*`,
32
- `VITE_IAM_API_URL`); `@quartal/ui-messages` uses it to create the shared client.
33
-
34
- The CRUD shapes (`ApiCrudItem`, `ODataResult`, `ValidationResult`, …) come from
35
- [`@quartal/core`](https://www.npmjs.com/package/@quartal/core) — import them from there. Only
36
- `ODataQuery` is re-defined here, with its `$filter` typed as a domain-shaped object instead of an
37
- OData filter string.
1
+ # @quartal/messages-client
2
+
3
+ The browser SDK of the **Quartal Messages API**. `MessagesApi` bundles every resource the UI reads
4
+ and writes — channels and their listed companies, threads, messages, channel agents, the model /
5
+ agent / skill catalog, companies and the signed-in user — plus the live event stream
6
+ (`POST /events`, Server-Sent Events), all over HTTP with the user's bearer token. The API's access
7
+ rules decide what each call sees.
8
+
9
+ A pnpm workspace package of this repo (`workspace:*`); it is not published.
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { MessagesApi } from '@quartal/messages-client';
15
+
16
+ const api = new MessagesApi('http://localhost:8002', () => currentAccessToken());
17
+
18
+ const channels = await api.channels.getOData({ $filter: { advisory } });
19
+ const threads = await api.threads.list('salaxy-payroll');
20
+ await api.messages.create(threads[0].id, [{ id: crypto.randomUUID(), type: 'text', text: 'Hei', state: 'active' }]);
21
+
22
+ const stop = api.events.subscribe((event) => {
23
+ if (event.type === 'message') console.log(event.message.threadId, event.message.parts);
24
+ });
25
+ ```
26
+
27
+ The catalog and channel resources (`channels`, `models`, `agents`, `skills`) keep the
28
+ `ICrudApiBase` shape: `getBlank` and `validate` run locally, the API validates again on write.
29
+ Failed calls reject with an `ApiError` carrying the HTTP status and the API's message.
30
+
31
+ `loadClientConfig()` reads the browser settings (`VITE_MESSAGES_API_URL`, `VITE_OIDC_*`,
32
+ `VITE_IAM_API_URL`); `@quartal/ui-messages` uses it to create the shared client.
33
+
34
+ The CRUD shapes (`ApiCrudItem`, `ODataResult`, `ValidationResult`, …) come from
35
+ [`@quartal/core`](https://www.npmjs.com/package/@quartal/core) — import them from there. Only
36
+ `ODataQuery` is re-defined here, with its `$filter` typed as a domain-shaped object instead of an
37
+ OData filter string.
package/dist/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ApiCrudItem, ApiListItem, FsContent, FsEncoding, FsEntry, FsWriteResult, ODataQueryOptions, ODataResult, QFsSource, ValidationResult } from "@quartal/core";
2
- import { Agent, AgentPlugin, CatalogRepositoryInfo, Channel, ChannelAgentAssignment, ChannelAgentSchedule, ChannelAgentTrigger, ChannelCompany, ChannelDefinition, ChannelDefinitionInfo, ChannelMessageFile, ChannelSyncResult, ChannelsStats, ChatMessage, CompanyStats, CompanySummary, ExternalPlugin, HomeView, HostedPlugin, HostedPluginContent, HubConfigurationInfo, HubConfigurationPatch, HubToolSetting, LiveEvent, MessageFileContent, MessageUsage, Model, ModelCatalogRefreshResult, ModelGateway, PluginAgent, PluginCodeAttachment, PluginCodeChat, PluginCodeChatSummary, PluginHostGitCommit, PluginHostGitDiscardResult, PluginHostGitDiscardScope, PluginHostGitFileVersions, PluginHostGitResetMode, PluginHostGitResetResult, PluginHostGitStatus, PluginHostInfo, PluginHostPullResult, PluginHostPushResult, PluginInfo, PluginSyncResult, PluginTestSubject, PluginTestToken, PluginTestTool, ShownHomeView, ThreadSummary, UIFilePart, UIMessagePart, UIWidgetContextPart, UserInfo, WidgetResource, WidgetToolResult } from "@quartal/messages-types";
2
+ import { Agent, AgentPlugin, CatalogRepositoryInfo, Channel, ChannelAgentAssignment, ChannelAgentSchedule, ChannelAgentTrigger, ChannelCompany, ChannelDefinition, ChannelDefinitionInfo, ChannelMessageFile, ChannelSyncResult, ChannelsStats, ChatMessage, CompanyStats, CompanySummary, ExternalPlugin, HomeView, HostedPlugin, HostedPluginContent, HubConfigurationInfo, HubConfigurationPatch, HubToolSetting, LiveEvent, MessageFileContent, MessageUsage, Model, ModelCatalogRefreshResult, ModelGateway, PluginAgent, PluginCodeAttachment, PluginCodeChat, PluginCodeChatSummary, PluginHostGitCommit, PluginHostGitDiscardResult, PluginHostGitDiscardScope, PluginHostGitFileVersions, PluginHostGitResetMode, PluginHostGitResetResult, PluginHostGitStatus, PluginHostInfo, PluginHostPullResult, PluginHostPushResult, PluginInfo, PluginSyncResult, PluginTestSubject, PluginTestToken, PluginTestTool, SeedDataInfo, SeedResetResult, ShownHomeView, ThreadSummary, UIFilePart, UIMessagePart, UIWidgetContextPart, UserInfo, WidgetResource, WidgetToolResult } from "@quartal/messages-types";
3
3
 
4
4
  //#region src/ICrudApiBase.d.ts
5
5
  /**
@@ -95,8 +95,16 @@ interface ClientConfig {
95
95
  iamApiUrl: string;
96
96
  }
97
97
  /**
98
- * Reads `ClientConfig` from `import.meta.env`. Throws when a required variable is missing so the
99
- * failure surfaces at app startup, not at the first call.
98
+ * Sets the configuration at runtime, over `import.meta.env`: for an app that is not built with the
99
+ * `VITE_*` variables, such as a channel plugin's page that learns the API's address from the Hub.
100
+ * Such an app needs only what it uses: {@link loadClientConfig} then requires `messagesApiUrl` alone.
101
+ * @param config The values to use; a later call adds to and overrides the earlier ones.
102
+ */
103
+ declare function configureClient(config: Partial<ClientConfig>): void;
104
+ /**
105
+ * Reads `ClientConfig` from `import.meta.env` and the values given with {@link configureClient}.
106
+ * Throws when a required value is missing so the failure surfaces at app startup, not at the first
107
+ * call.
100
108
  */
101
109
  declare function loadClientConfig(): ClientConfig;
102
110
  //#endregion
@@ -423,6 +431,20 @@ declare class MessagesApi {
423
431
  /** The configuration of an organization the user is a direct member of; empty without the file. */get: (companyId: string) => Promise<HubConfigurationInfo>; /** Sets the keys given (null removes one) for an organization the user is a direct admin of. */
424
432
  update: (companyId: string, configuration: HubConfigurationPatch) => Promise<HubConfigurationInfo>;
425
433
  };
434
+ /**
435
+ * Seed data of a test environment: resetting an organization to the starting point of its demo,
436
+ * a branch of its plugin repository. Offered only where the API has `HUB_SEED_REF`, to the
437
+ * organization's direct admins.
438
+ */
439
+ readonly seedData: {
440
+ /** Whether the organization can be reset, the ref it goes to and the customers to choose from. */info: (owner: string) => Promise<SeedDataInfo>;
441
+ /**
442
+ * Resets the organization to its seed data, building the demo around the customers given (in
443
+ * order, at most five). Changes in the plugin repository that are not in the seed are lost, and
444
+ * so are the organization's channels, threads and messages.
445
+ */
446
+ reset: (owner: string, customers: string[]) => Promise<SeedResetResult>;
447
+ };
426
448
  /** The Quartal Hub plugin catalog. */
427
449
  readonly plugins: {
428
450
  /** Every plugin: synced ones first, then the placeholders. */list: () => Promise<PluginInfo[]>; /** One plugin by id. */
@@ -677,6 +699,15 @@ declare class MessagesApi {
677
699
  callTool: (subject: PluginTestSubject, pluginId: string, name: string, args?: Record<string, unknown>, forWidget?: boolean) => Promise<WidgetToolResult>; /** The widget document of a tool. */
678
700
  getWidget: (subject: PluginTestSubject, pluginId: string, uri: string) => Promise<WidgetResource>;
679
701
  };
702
+ /**
703
+ * Concept pictures of channels (a channel's overview, the workflow of its statuses), drawn and
704
+ * read by the concepts plugin (`hub-concepts`). The plugin keeps nothing: read the pictures from the
705
+ * channel plugin's `docs/` and store what the person saves.
706
+ */
707
+ readonly channelConcepts: {
708
+ /** The editor widget's document. */getWidget: () => Promise<WidgetResource>; /** Calls a tool of the concepts plugin (`showConcept`, `conceptFile`, …). */
709
+ callTool: (name: string, args?: Record<string, unknown>) => Promise<WidgetToolResult>;
710
+ };
680
711
  /**
681
712
  * The views of the Hub's front page besides the chats: the saved dashboards of the dashboards
682
713
  * plugins the organization's channels use, each shown with its plugin's widget as the person.
@@ -714,4 +745,4 @@ type FilesResource = Omit<MessagesApi['files'], 'forOwner' | 'createDemo'>;
714
745
  */
715
746
  declare function filesSource(files: FilesResource, owner: string): QFsSource;
716
747
  //#endregion
717
- export { type AgentPatch, AgentsApi, ApiError, type ChannelAgentPatch, type ChannelCreateInput, ChannelsApi, type ChannelsFilter, type ChannelsRefreshResult, type ClientConfig, type FilesResource, HttpClient, type IChannelsApi, type ICrudApiBase, ID_FORMAT_PATTERN, type IModelsApi, type LiveEventHandler, LiveEvents, MessagesApi, ModelsApi, type ModelsFilter, type ODataQuery, type Query, type RequestOptions, type ThreadPatch, type TokenProvider, base64ToBytes, blobToBase64, bytesToBase64, filesSource, isValidId, loadClientConfig, toFsError };
748
+ export { type AgentPatch, AgentsApi, ApiError, type ChannelAgentPatch, type ChannelCreateInput, ChannelsApi, type ChannelsFilter, type ChannelsRefreshResult, type ClientConfig, type FilesResource, HttpClient, type IChannelsApi, type ICrudApiBase, ID_FORMAT_PATTERN, type IModelsApi, type LiveEventHandler, LiveEvents, MessagesApi, ModelsApi, type ModelsFilter, type ODataQuery, type Query, type RequestOptions, type ThreadPatch, type TokenProvider, base64ToBytes, blobToBase64, bytesToBase64, configureClient, filesSource, isValidId, loadClientConfig, toFsError };
package/dist/mod.js CHANGED
@@ -26,19 +26,39 @@ function isValidId(id) {
26
26
  //#region src/config/ClientConfig.ts
27
27
  /** Default scopes: profile plus the IAM API and Messages API audiences. */
28
28
  const DEFAULT_SCOPE = "openid profile email iam-api quartal-hub-test";
29
+ /** The values given with {@link configureClient}; null when the app uses `import.meta.env` only. */
30
+ let configured = null;
29
31
  /**
30
- * Reads `ClientConfig` from `import.meta.env`. Throws when a required variable is missing so the
31
- * failure surfaces at app startup, not at the first call.
32
+ * Sets the configuration at runtime, over `import.meta.env`: for an app that is not built with the
33
+ * `VITE_*` variables, such as a channel plugin's page that learns the API's address from the Hub.
34
+ * Such an app needs only what it uses: {@link loadClientConfig} then requires `messagesApiUrl` alone.
35
+ * @param config The values to use; a later call adds to and overrides the earlier ones.
36
+ */
37
+ function configureClient(config) {
38
+ configured = {
39
+ ...configured,
40
+ ...config
41
+ };
42
+ }
43
+ /**
44
+ * Reads `ClientConfig` from `import.meta.env` and the values given with {@link configureClient}.
45
+ * Throws when a required value is missing so the failure surfaces at app startup, not at the first
46
+ * call.
32
47
  */
33
48
  function loadClientConfig() {
34
- const env = import.meta.env;
49
+ const env = import.meta.env ?? {};
35
50
  const config = {
36
51
  messagesApiUrl: env.VITE_MESSAGES_API_URL ?? "",
37
52
  oidcAuthority: env.VITE_OIDC_AUTHORITY ?? "",
38
53
  oidcClientId: env.VITE_OIDC_CLIENT_ID ?? "",
39
54
  oidcScope: env.VITE_OIDC_SCOPE || DEFAULT_SCOPE,
40
- iamApiUrl: env.VITE_IAM_API_URL ?? ""
55
+ iamApiUrl: env.VITE_IAM_API_URL ?? "",
56
+ ...configured
41
57
  };
58
+ if (configured) {
59
+ if (!config.messagesApiUrl) throw new Error("configureClient() was called without messagesApiUrl.");
60
+ return config;
61
+ }
42
62
  const missing = Object.entries(config).filter(([, v]) => !v).map(([k]) => k);
43
63
  if (missing.length) throw new Error(`Missing ${missing.join(", ")} (VITE_MESSAGES_API_URL, VITE_OIDC_AUTHORITY, VITE_OIDC_CLIENT_ID, VITE_IAM_API_URL). Copy .env.example to .env at the repo root and fill in the values.`);
44
64
  return config;
@@ -544,6 +564,18 @@ var MessagesApi = class {
544
564
  get: (companyId) => this.http.get(`/api/hub-configuration/${seg(companyId)}`),
545
565
  update: (companyId, configuration) => this.http.put(`/api/hub-configuration/${seg(companyId)}`, { configuration })
546
566
  };
567
+ /**
568
+ * Seed data of a test environment: resetting an organization to the starting point of its demo,
569
+ * a branch of its plugin repository. Offered only where the API has `HUB_SEED_REF`, to the
570
+ * organization's direct admins.
571
+ */
572
+ seedData = {
573
+ info: (owner) => this.http.get("/api/seed-data/info", { query: { owner } }),
574
+ reset: (owner, customers) => this.http.post("/api/seed-data/reset", {
575
+ owner,
576
+ customers
577
+ })
578
+ };
547
579
  /** The Quartal Hub plugin catalog. */
548
580
  plugins = {
549
581
  list: async () => (await this.http.get("/api/plugins")).plugins,
@@ -917,6 +949,18 @@ var MessagesApi = class {
917
949
  } })
918
950
  };
919
951
  /**
952
+ * Concept pictures of channels (a channel's overview, the workflow of its statuses), drawn and
953
+ * read by the concepts plugin (`hub-concepts`). The plugin keeps nothing: read the pictures from the
954
+ * channel plugin's `docs/` and store what the person saves.
955
+ */
956
+ channelConcepts = {
957
+ getWidget: () => this.http.get("/api/channel-concepts/widget"),
958
+ callTool: (name, args = {}) => this.http.post("/api/channel-concepts/call-tool", {
959
+ name,
960
+ args
961
+ })
962
+ };
963
+ /**
920
964
  * The views of the Hub's front page besides the chats: the saved dashboards of the dashboards
921
965
  * plugins the organization's channels use, each shown with its plugin's widget as the person.
922
966
  */
@@ -945,4 +989,4 @@ var MessagesApi = class {
945
989
  };
946
990
  };
947
991
  //#endregion
948
- export { AgentsApi, ApiError, ChannelsApi, HttpClient, ID_FORMAT_PATTERN, LiveEvents, MessagesApi, ModelsApi, base64ToBytes, blobToBase64, bytesToBase64, filesSource, isValidId, loadClientConfig, toFsError };
992
+ export { AgentsApi, ApiError, ChannelsApi, HttpClient, ID_FORMAT_PATTERN, LiveEvents, MessagesApi, ModelsApi, base64ToBytes, blobToBase64, bytesToBase64, configureClient, filesSource, isValidId, loadClientConfig, toFsError };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quartal/messages-client",
3
3
  "description": "The browser SDK of the Quartal Messages API",
4
- "version": "0.2.0",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "author": "Quartal Accounting Software Oy",
7
7
  "repository": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@quartal/core": "^1.5.1",
29
- "@quartal/messages-types": "0.2.0"
29
+ "@quartal/messages-types": "0.4.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "tsdown": "^0.21.9",