@jskit-ai/assistant 0.1.75 → 0.1.76

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.
@@ -1,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  packageVersion: 1,
3
3
  packageId: "@jskit-ai/assistant",
4
- version: "0.1.75",
4
+ version: "0.1.76",
5
5
  kind: "generator",
6
6
  description: "Install assistant runtime/config for one surface and scaffold assistant pages at explicit target files.",
7
7
  options: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/assistant",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -9,6 +9,6 @@
9
9
  "./server/buildTemplateContext": "./src/server/buildTemplateContext.js"
10
10
  },
11
11
  "dependencies": {
12
- "@jskit-ai/kernel": "0.1.66"
12
+ "@jskit-ai/kernel": "0.1.67"
13
13
  }
14
14
  }
@@ -12,7 +12,10 @@ async function buildTemplateContext({ appRoot, options } = {}) {
12
12
  const settingsSurface = resolveSurfaceDefinition(appConfig, options?.["settings-surface"], "settings-surface");
13
13
  const configScope = normalizeConfigScope(options?.["config-scope"]);
14
14
 
15
- assertAssistantSurfaceIsAvailable(appConfig, runtimeSurface.id);
15
+ assertAssistantSurfaceIsAvailable(appConfig, runtimeSurface.id, {
16
+ settingsSurfaceId: settingsSurface.id,
17
+ configScope
18
+ });
16
19
 
17
20
  if (configScope === "workspace" && runtimeSurface.requiresWorkspace !== true) {
18
21
  throw new Error(
@@ -49,11 +49,25 @@ function resolveSurfaceDefinition(appConfig = {}, surfaceId = "", optionName = "
49
49
  });
50
50
  }
51
51
 
52
- function assertAssistantSurfaceIsAvailable(appConfig = {}, surfaceId = "") {
52
+ function assertAssistantSurfaceIsAvailable(appConfig = {}, surfaceId = "", expected = {}) {
53
53
  const assistantSurfaces =
54
54
  appConfig && typeof appConfig.assistantSurfaces === "object" && !Array.isArray(appConfig.assistantSurfaces)
55
55
  ? appConfig.assistantSurfaces
56
56
  : {};
57
+ const existingSurface = assistantSurfaces[surfaceId];
58
+ if (!existingSurface) {
59
+ return;
60
+ }
61
+
62
+ const expectedSettingsSurfaceId = normalizeSurfaceId(expected?.settingsSurfaceId);
63
+ const expectedConfigScope = normalizeConfigScope(expected?.configScope);
64
+ const existingSettingsSurfaceId = normalizeSurfaceId(existingSurface?.settingsSurfaceId);
65
+ const existingConfigScope = normalizeConfigScope(existingSurface?.configScope);
66
+
67
+ if (existingSettingsSurfaceId === expectedSettingsSurfaceId && existingConfigScope === expectedConfigScope) {
68
+ return;
69
+ }
70
+
57
71
  if (assistantSurfaces[surfaceId]) {
58
72
  throw new Error(`assistant generator surface "${surfaceId}" already has an assistant configured in config/public.js.`);
59
73
  }
@@ -84,7 +84,7 @@ test("buildTemplateContext rejects workspace config scope for a non-workspace as
84
84
  });
85
85
  });
86
86
 
87
- test("buildTemplateContext rejects duplicate assistant surfaces already configured in public config", async () => {
87
+ test("buildTemplateContext accepts an already-configured matching assistant surface", async () => {
88
88
  await withTempApp(async (appRoot) => {
89
89
  await writeFile(
90
90
  path.join(appRoot, "config", "public.js"),
@@ -104,13 +104,48 @@ test("buildTemplateContext rejects duplicate assistant surfaces already configur
104
104
  "utf8"
105
105
  );
106
106
 
107
+ const context = await buildTemplateContext({
108
+ appRoot,
109
+ options: {
110
+ surface: "app",
111
+ "settings-surface": "console",
112
+ "config-scope": "global"
113
+ }
114
+ });
115
+
116
+ assert.equal(context.__ASSISTANT_SETTINGS_SURFACE_ID__, "console");
117
+ assert.equal(context.__ASSISTANT_CONFIG_SCOPE__, "global");
118
+ });
119
+ });
120
+
121
+ test("buildTemplateContext rejects conflicting assistant surfaces already configured in public config", async () => {
122
+ await withTempApp(async (appRoot) => {
123
+ await writeFile(
124
+ path.join(appRoot, "config", "public.js"),
125
+ `export const config = {
126
+ surfaceDefinitions: {
127
+ app: { id: "app", enabled: true, requiresWorkspace: false, accessPolicyId: "authenticated" },
128
+ admin: { id: "admin", enabled: true, requiresWorkspace: true, accessPolicyId: "workspace_member" },
129
+ console: { id: "console", enabled: true, requiresWorkspace: false, accessPolicyId: "console_owner" }
130
+ },
131
+ assistantSurfaces: {
132
+ app: {
133
+ settingsSurfaceId: "console",
134
+ configScope: "global"
135
+ }
136
+ }
137
+ };
138
+ `,
139
+ "utf8"
140
+ );
141
+
107
142
  await assert.rejects(
108
143
  () =>
109
144
  buildTemplateContext({
110
145
  appRoot,
111
146
  options: {
112
147
  surface: "app",
113
- "settings-surface": "console",
148
+ "settings-surface": "admin",
114
149
  "config-scope": "global"
115
150
  }
116
151
  }),