@jskit-ai/assistant-core 0.1.1

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 (37) hide show
  1. package/package.descriptor.mjs +67 -0
  2. package/package.json +24 -0
  3. package/src/client/components/AssistantClientElement.vue +1316 -0
  4. package/src/client/components/AssistantSettingsFormCard.vue +76 -0
  5. package/src/client/index.js +5 -0
  6. package/src/client/lib/assistantApi.js +140 -0
  7. package/src/client/lib/assistantHttpClient.js +10 -0
  8. package/src/client/lib/markdownRenderer.js +31 -0
  9. package/src/server/index.js +21 -0
  10. package/src/server/lib/aiClient.js +43 -0
  11. package/src/server/lib/ndjson.js +47 -0
  12. package/src/server/lib/providers/anthropicClient.js +375 -0
  13. package/src/server/lib/providers/common.js +150 -0
  14. package/src/server/lib/providers/deepSeekClient.js +22 -0
  15. package/src/server/lib/providers/openAiClient.js +13 -0
  16. package/src/server/lib/providers/openAiCompatibleClient.js +69 -0
  17. package/src/server/lib/resolveWorkspaceSlug.js +24 -0
  18. package/src/server/lib/serviceToolCatalog.js +459 -0
  19. package/src/server/repositories/repositoryPersistenceUtils.js +48 -0
  20. package/src/shared/assistantPaths.js +77 -0
  21. package/src/shared/assistantResource.js +309 -0
  22. package/src/shared/assistantSettingsResource.js +90 -0
  23. package/src/shared/index.js +47 -0
  24. package/src/shared/queryKeys.js +84 -0
  25. package/src/shared/settingsEvents.js +5 -0
  26. package/src/shared/streamEvents.js +29 -0
  27. package/src/shared/support/conversationStatus.js +18 -0
  28. package/src/shared/support/jsonObject.js +18 -0
  29. package/src/shared/support/positiveInteger.js +9 -0
  30. package/test/aiConfigValidation.test.js +15 -0
  31. package/test/assistantApiSurfaceHeader.test.js +66 -0
  32. package/test/assistantPaths.test.js +51 -0
  33. package/test/assistantResource.test.js +49 -0
  34. package/test/assistantSettingsResource.test.js +32 -0
  35. package/test/queryKeys.test.js +44 -0
  36. package/test/resolveWorkspaceSlug.test.js +83 -0
  37. package/test/serviceToolCatalog.test.js +1235 -0
@@ -0,0 +1,51 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ buildAssistantApiPath,
5
+ buildAssistantSettingsApiPath,
6
+ resolveAssistantApiBasePath,
7
+ resolveAssistantSettingsApiPath
8
+ } from "../src/shared/assistantPaths.js";
9
+
10
+ test("assistant path helpers derive workspace and non-workspace API bases from surface workspace requirements", () => {
11
+ assert.equal(resolveAssistantApiBasePath({ requiresWorkspace: false }), "/api/assistant");
12
+ assert.equal(resolveAssistantApiBasePath({ requiresWorkspace: true }), "/api/w/:workspaceSlug/assistant");
13
+
14
+ assert.equal(resolveAssistantSettingsApiPath({ requiresWorkspace: false }), "/api/assistant/settings");
15
+ assert.equal(resolveAssistantSettingsApiPath({ requiresWorkspace: true }), "/api/w/:workspaceSlug/assistant/settings");
16
+ });
17
+
18
+ test("assistant path builders materialize workspace-aware and public API paths", () => {
19
+ assert.equal(
20
+ buildAssistantApiPath({
21
+ requiresWorkspace: false,
22
+ suffix: "/conversations"
23
+ }),
24
+ "/api/assistant/conversations"
25
+ );
26
+
27
+ assert.equal(
28
+ buildAssistantApiPath({
29
+ requiresWorkspace: true,
30
+ workspaceSlug: "acme",
31
+ suffix: "/conversations"
32
+ }),
33
+ "/api/w/acme/assistant/conversations"
34
+ );
35
+
36
+ assert.equal(
37
+ buildAssistantSettingsApiPath({
38
+ requiresWorkspace: false,
39
+ suffix: "/"
40
+ }),
41
+ "/api/assistant/settings"
42
+ );
43
+
44
+ assert.equal(
45
+ buildAssistantSettingsApiPath({
46
+ requiresWorkspace: true,
47
+ workspaceSlug: "acme"
48
+ }),
49
+ "/api/w/acme/assistant/settings"
50
+ );
51
+ });
@@ -0,0 +1,49 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { Check } from "typebox/value";
4
+ import { assistantResource } from "../src/shared/assistantResource.js";
5
+
6
+ test("assistant output schemas accept normalized paginated payloads", () => {
7
+ const conversationsListSchema = assistantResource.operations.conversationsList.outputValidator.schema;
8
+ const conversationMessagesSchema = assistantResource.operations.conversationMessagesList.outputValidator.schema;
9
+
10
+ const conversationsPayload = {
11
+ items: [],
12
+ nextCursor: null
13
+ };
14
+
15
+ const messagesPayload = {
16
+ conversation: {
17
+ id: 1,
18
+ workspaceId: 10,
19
+ title: "Conversation",
20
+ createdByUserId: 7,
21
+ status: "active",
22
+ provider: "openai",
23
+ model: "gpt-4.1",
24
+ surfaceId: "admin",
25
+ startedAt: "2026-03-16T10:00:00.000Z",
26
+ endedAt: null,
27
+ messageCount: 2,
28
+ metadata: {},
29
+ createdAt: "2026-03-16T10:00:00.000Z",
30
+ updatedAt: "2026-03-16T10:01:00.000Z"
31
+ },
32
+ entries: [],
33
+ page: 1,
34
+ pageSize: 200,
35
+ total: 0,
36
+ totalPages: 1
37
+ };
38
+
39
+ assert.equal(Check(conversationsListSchema, conversationsPayload), true);
40
+ assert.equal(Check(conversationMessagesSchema, messagesPayload), true);
41
+ });
42
+
43
+ test("assistant conversation message params accept numeric path strings and normalize to integer", () => {
44
+ const paramsValidator = assistantResource.operations.conversationMessagesList.paramsValidator;
45
+ assert.equal(Check(paramsValidator.schema, { conversationId: "2" }), true);
46
+ assert.deepEqual(paramsValidator.normalize({ conversationId: "2" }), {
47
+ conversationId: 2
48
+ });
49
+ });
@@ -0,0 +1,32 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { Check } from "typebox/value";
4
+ import { validateOperationSection } from "@jskit-ai/http-runtime/shared/validators/operationValidation";
5
+ import { assistantConfigResource } from "../src/shared/assistantSettingsResource.js";
6
+
7
+ test("assistant config resource exposes valid output schema", () => {
8
+ const viewSchema = assistantConfigResource.operations.view.outputValidator.schema;
9
+
10
+ assert.equal(
11
+ Check(viewSchema, {
12
+ targetSurfaceId: "app",
13
+ scopeKey: "app:global",
14
+ workspaceId: null,
15
+ settings: {
16
+ systemPrompt: ""
17
+ }
18
+ }),
19
+ true
20
+ );
21
+ });
22
+
23
+ test("assistant settings patch normalizer preserves omitted fields", () => {
24
+ const patch = validateOperationSection({
25
+ operation: assistantConfigResource.operations.patch,
26
+ section: "bodyValidator",
27
+ value: {}
28
+ });
29
+
30
+ assert.equal(patch.ok, true);
31
+ assert.deepEqual(patch.value, {});
32
+ });
@@ -0,0 +1,44 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import {
4
+ ASSISTANT_QUERY_KEY_PREFIX,
5
+ assistantRootQueryKey,
6
+ assistantScopeQueryKey,
7
+ assistantSettingsQueryKey,
8
+ assistantConversationsListQueryKey,
9
+ assistantConversationMessagesQueryKey
10
+ } from "../src/shared/queryKeys.js";
11
+
12
+ test("assistant query keys normalize scope and paging", () => {
13
+ assert.deepEqual(ASSISTANT_QUERY_KEY_PREFIX, ["assistant"]);
14
+ assert.deepEqual(assistantRootQueryKey(), ["assistant"]);
15
+
16
+ assert.deepEqual(assistantScopeQueryKey({ targetSurfaceId: "app" }), ["assistant", "app:global"]);
17
+ assert.deepEqual(assistantScopeQueryKey({ targetSurfaceId: "admin", workspaceSlug: "acme" }), ["assistant", "admin:slug:acme"]);
18
+ assert.deepEqual(assistantScopeQueryKey({ targetSurfaceId: "admin", workspaceId: "9" }), ["assistant", "admin:workspace:9"]);
19
+ assert.deepEqual(assistantSettingsQueryKey({ targetSurfaceId: "app" }), ["assistant", "app:global", "settings"]);
20
+
21
+ assert.deepEqual(assistantConversationsListQueryKey({ targetSurfaceId: "admin", workspaceSlug: "acme" }), [
22
+ "assistant",
23
+ "admin:slug:acme",
24
+ "conversations",
25
+ "list",
26
+ 20,
27
+ "all"
28
+ ]);
29
+
30
+ assert.deepEqual(
31
+ assistantConversationsListQueryKey({ targetSurfaceId: "admin", workspaceId: 9 }, { limit: 10, status: "ACTIVE" }),
32
+ ["assistant", "admin:workspace:9", "conversations", "list", 10, "active"]
33
+ );
34
+
35
+ assert.deepEqual(assistantConversationMessagesQueryKey({ targetSurfaceId: "admin", workspaceSlug: "acme" }, "22"), [
36
+ "assistant",
37
+ "admin:slug:acme",
38
+ "conversations",
39
+ "22",
40
+ "messages",
41
+ 1,
42
+ 200
43
+ ]);
44
+ });
@@ -0,0 +1,83 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { resolveWorkspaceSlug } from "../src/server/lib/resolveWorkspaceSlug.js";
4
+
5
+ test("resolveWorkspaceSlug follows fallback priority", () => {
6
+ const slug = resolveWorkspaceSlug(
7
+ {
8
+ workspace: {
9
+ slug: "workspace-primary"
10
+ },
11
+ requestMeta: {
12
+ resolvedWorkspaceContext: {
13
+ workspace: {
14
+ slug: "workspace-resolved"
15
+ }
16
+ },
17
+ request: {
18
+ input: {
19
+ params: {
20
+ workspaceSlug: "workspace-request"
21
+ }
22
+ }
23
+ }
24
+ }
25
+ },
26
+ {
27
+ workspaceSlug: "workspace-input"
28
+ }
29
+ );
30
+
31
+ assert.equal(slug, "workspace-primary");
32
+ });
33
+
34
+ test("resolveWorkspaceSlug resolves from requestMeta resolved workspace", () => {
35
+ const slug = resolveWorkspaceSlug({
36
+ requestMeta: {
37
+ resolvedWorkspaceContext: {
38
+ workspace: {
39
+ slug: "workspace-resolved"
40
+ }
41
+ }
42
+ }
43
+ });
44
+
45
+ assert.equal(slug, "workspace-resolved");
46
+ });
47
+
48
+ test("resolveWorkspaceSlug resolves from action input before request params", () => {
49
+ const slug = resolveWorkspaceSlug(
50
+ {
51
+ requestMeta: {
52
+ request: {
53
+ input: {
54
+ params: {
55
+ workspaceSlug: "workspace-request"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ {
62
+ workspaceSlug: "workspace-input"
63
+ }
64
+ );
65
+
66
+ assert.equal(slug, "workspace-input");
67
+ });
68
+
69
+ test("resolveWorkspaceSlug resolves from request params when needed", () => {
70
+ const slug = resolveWorkspaceSlug({
71
+ requestMeta: {
72
+ request: {
73
+ input: {
74
+ params: {
75
+ workspaceSlug: "workspace-request"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ });
81
+
82
+ assert.equal(slug, "workspace-request");
83
+ });