@knolo/cli 3.2.2 → 5.0.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 (28) hide show
  1. package/README.md +68 -7
  2. package/bin/knolo.mjs +514 -7
  3. package/package.json +21 -3
  4. package/templates/icp-knowledge-canister/README.md +76 -0
  5. package/templates/icp-knowledge-canister/canisters/knolo-core-rust/Cargo.toml +13 -0
  6. package/templates/icp-knowledge-canister/canisters/knolo-core-rust/src/lib.rs +1603 -0
  7. package/templates/icp-knowledge-canister/canisters/knolo-icp-canister/Cargo.lock +541 -0
  8. package/templates/icp-knowledge-canister/canisters/knolo-icp-canister/Cargo.toml +20 -0
  9. package/templates/icp-knowledge-canister/canisters/knolo-icp-canister/knolo_icp.did +29 -0
  10. package/templates/icp-knowledge-canister/canisters/knolo-icp-canister/src/lib.rs +605 -0
  11. package/templates/icp-knowledge-canister/dfx.json +25 -0
  12. package/templates/icp-knowledge-canister/frontend/index.html +12 -0
  13. package/templates/icp-knowledge-canister/frontend/package.json +27 -0
  14. package/templates/icp-knowledge-canister/frontend/src/App.tsx +225 -0
  15. package/templates/icp-knowledge-canister/frontend/src/app.css +271 -0
  16. package/templates/icp-knowledge-canister/frontend/src/canister.ts +119 -0
  17. package/templates/icp-knowledge-canister/frontend/src/canisterConfig.test.ts +34 -0
  18. package/templates/icp-knowledge-canister/frontend/src/canisterConfig.ts +26 -0
  19. package/templates/icp-knowledge-canister/frontend/src/main.tsx +5 -0
  20. package/templates/icp-knowledge-canister/frontend/src/vite-env.d.ts +14 -0
  21. package/templates/icp-knowledge-canister/frontend/tsconfig.json +18 -0
  22. package/templates/icp-knowledge-canister/frontend/vite.config.ts +66 -0
  23. package/templates/icp-knowledge-canister/knolo.config.json +15 -0
  24. package/templates/icp-knowledge-canister/knowledge/alpha.md +5 -0
  25. package/templates/icp-knowledge-canister/knowledge/guides/beta.md +5 -0
  26. package/templates/icp-knowledge-canister/scripts/build-sample-pack.mjs +24 -0
  27. package/templates/icp-knowledge-canister/scripts/query.sh +11 -0
  28. package/templates/icp-knowledge-canister/scripts/upload-pack.sh +16 -0
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "Bundler",
9
+ "resolveJsonModule": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "esModuleInterop": true,
12
+ "strict": true,
13
+ "noEmit": true,
14
+ "jsx": "react-jsx",
15
+ "types": ["vite/client", "node"]
16
+ },
17
+ "include": ["src", "vite.config.ts"]
18
+ }
@@ -0,0 +1,66 @@
1
+ /// <reference types="vitest/config" />
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ import react from '@vitejs/plugin-react';
7
+ import { defineConfig, loadEnv } from 'vite';
8
+
9
+ type CanisterIdsFile = {
10
+ knolo_knowledge?: Record<string, string | undefined>;
11
+ };
12
+
13
+ function readCanisterIds(exampleRoot: string): CanisterIdsFile | undefined {
14
+ const canisterIdsPath = path.join(exampleRoot, '.dfx', 'local', 'canister_ids.json');
15
+ if (!fs.existsSync(canisterIdsPath)) {
16
+ return undefined;
17
+ }
18
+
19
+ const raw = fs.readFileSync(canisterIdsPath, 'utf8');
20
+ return JSON.parse(raw) as CanisterIdsFile;
21
+ }
22
+
23
+ function trimValue(value: string | undefined): string | undefined {
24
+ const trimmed = value?.trim();
25
+ return trimmed ? trimmed : undefined;
26
+ }
27
+
28
+ function pickNetwork(env: Record<string, string>): string {
29
+ return trimValue(env.VITE_DFX_NETWORK) ?? trimValue(env.DFX_NETWORK) ?? 'local';
30
+ }
31
+
32
+ function pickCanisterId(
33
+ env: Record<string, string>,
34
+ canisterIds: CanisterIdsFile | undefined,
35
+ network: string
36
+ ): string | undefined {
37
+ return (
38
+ trimValue(env.VITE_KNOLO_CANISTER_ID) ??
39
+ trimValue(canisterIds?.knolo_knowledge?.[network]) ??
40
+ trimValue(canisterIds?.knolo_knowledge?.local)
41
+ );
42
+ }
43
+
44
+ export default defineConfig(({ mode }) => {
45
+ const env = loadEnv(mode, process.cwd(), '');
46
+ const exampleRoot = path.resolve(__dirname, '..');
47
+ const network = pickNetwork(env);
48
+ const canisterId = pickCanisterId(env, readCanisterIds(exampleRoot), network);
49
+
50
+ return {
51
+ plugins: [react()],
52
+ define: {
53
+ __KNOLO_CANISTER_ID__: canisterId ? JSON.stringify(canisterId) : 'undefined',
54
+ __KNOLO_DFX_NETWORK__: JSON.stringify(network),
55
+ },
56
+ server: {
57
+ fs: {
58
+ allow: [exampleRoot],
59
+ },
60
+ },
61
+ test: {
62
+ environment: 'node',
63
+ include: ['src/**/*.test.ts'],
64
+ },
65
+ };
66
+ });
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": 1,
3
+ "sources": [
4
+ {
5
+ "name": "docs",
6
+ "path": "./knowledge"
7
+ }
8
+ ],
9
+ "output": {
10
+ "path": "./dist/knowledge.knolo"
11
+ },
12
+ "query": {
13
+ "topK": 5
14
+ }
15
+ }
@@ -0,0 +1,5 @@
1
+ # Alpha Guide
2
+
3
+ Alpha beta deployment notes for Knolo on the Internet Computer.
4
+
5
+ This sample document explains that a developer can build a local knowledge pack, upload it to the canister with `set_pack`, and run deterministic lexical search without a middleware server.
@@ -0,0 +1,5 @@
1
+ # Beta Notes
2
+
3
+ Beta guidance for local testing.
4
+
5
+ Use the sample query `alpha beta` after uploading the pack. The canister should return this note and the alpha guide as direct lexical hits.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFileSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
9
+ const projectDir = path.resolve(scriptDir, '..');
10
+ const knoloBin = process.env.KNOLO_BIN || 'knolo';
11
+ const outPath = path.join(projectDir, 'dist/knowledge.knolo');
12
+
13
+ console.log('[build-sample-pack] Building dist/knowledge.knolo');
14
+ execFileSync(knoloBin, ['icp', 'build-pack', './knowledge', '--out', './dist/knowledge.knolo'], {
15
+ cwd: projectDir,
16
+ stdio: 'inherit',
17
+ });
18
+
19
+ if (!existsSync(outPath)) {
20
+ console.error(`Expected pack output at ${outPath}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ console.log('[build-sample-pack] OK');
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ KNOLO_BIN="${KNOLO_BIN:-knolo}"
6
+ CANISTER_NAME="${CANISTER_NAME:-knolo_knowledge}"
7
+ QUERY_TEXT="${1:-alpha beta}"
8
+ TOP_K="${TOP_K:-5}"
9
+
10
+ cd "$ROOT"
11
+ "$KNOLO_BIN" icp query "$QUERY_TEXT" --canister "$CANISTER_NAME" --k "$TOP_K"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ KNOLO_BIN="${KNOLO_BIN:-knolo}"
6
+ CANISTER_NAME="${CANISTER_NAME:-knolo_knowledge}"
7
+ PACK_LABEL="${PACK_LABEL:-sample-knowledge-pack}"
8
+ PACK_PATH="${PACK_PATH:-$ROOT/dist/knowledge.knolo}"
9
+
10
+ if [ ! -f "$PACK_PATH" ]; then
11
+ echo "Pack file not found at $PACK_PATH. Run node scripts/build-sample-pack.mjs first." >&2
12
+ exit 1
13
+ fi
14
+
15
+ cd "$ROOT"
16
+ "$KNOLO_BIN" icp upload "$PACK_PATH" --canister "$CANISTER_NAME" --label "$PACK_LABEL"