@silverbulletmd/silverbullet 2.9.0 → 2.11.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 (123) hide show
  1. package/README.md +38 -25
  2. package/client/asset_bundle/bundle.ts +0 -1
  3. package/client/config.ts +343 -0
  4. package/client/markdown_parser/constants.ts +3 -1
  5. package/client/plugos/hooks/command.ts +0 -5
  6. package/client/plugos/hooks/event.ts +0 -6
  7. package/client/plugos/hooks/mq.ts +0 -3
  8. package/client/plugos/hooks/slash_command.ts +1 -7
  9. package/client/plugos/hooks/syscall.ts +24 -14
  10. package/client/plugos/manifest_cache.ts +0 -32
  11. package/client/plugos/plug.ts +0 -3
  12. package/client/plugos/plug_compile.ts +3 -13
  13. package/client/plugos/sandboxes/worker_sandbox.ts +19 -9
  14. package/client/plugos/syscalls/asset.ts +61 -23
  15. package/client/plugos/syscalls/clientStore.ts +32 -6
  16. package/client/plugos/syscalls/client_code_widget.ts +9 -4
  17. package/client/plugos/syscalls/code_widget.ts +26 -11
  18. package/client/plugos/syscalls/config.ts +146 -30
  19. package/client/plugos/syscalls/datastore.ts +146 -40
  20. package/client/plugos/syscalls/editor.ts +1518 -722
  21. package/client/plugos/syscalls/event.ts +44 -13
  22. package/client/plugos/syscalls/fetch.ts +120 -83
  23. package/client/plugos/syscalls/icon.ts +46 -0
  24. package/client/plugos/syscalls/index.ts +267 -121
  25. package/client/plugos/syscalls/jsonschema.ts +107 -9
  26. package/client/plugos/syscalls/language.ts +38 -12
  27. package/client/plugos/syscalls/markdown.ts +166 -50
  28. package/client/plugos/syscalls/mq.ts +92 -20
  29. package/client/plugos/syscalls/navigator.ts +143 -0
  30. package/client/plugos/syscalls/schema_introspection.ts +33 -0
  31. package/client/plugos/syscalls/search.ts +44 -0
  32. package/client/plugos/syscalls/service_registry.ts +74 -20
  33. package/client/plugos/syscalls/shell.ts +51 -21
  34. package/client/plugos/syscalls/space.ts +412 -113
  35. package/client/plugos/syscalls/sync.ts +103 -20
  36. package/client/plugos/syscalls/system.ts +274 -139
  37. package/client/plugos/system.ts +28 -10
  38. package/client/plugos/worker_runtime.ts +0 -2
  39. package/client/space_lua/aggregates.ts +0 -16
  40. package/client/space_lua/api_documentation.ts +107 -0
  41. package/client/space_lua/ast.ts +13 -5
  42. package/client/space_lua/ast_narrow.ts +0 -5
  43. package/client/space_lua/budget.ts +113 -0
  44. package/client/space_lua/budget_ui.ts +49 -0
  45. package/client/space_lua/eval.ts +125 -92
  46. package/client/space_lua/labels.ts +0 -4
  47. package/client/space_lua/numeric.ts +0 -5
  48. package/client/space_lua/parse.ts +243 -125
  49. package/client/space_lua/pretty_print.ts +128 -54
  50. package/client/space_lua/quarantine.ts +127 -0
  51. package/client/space_lua/query_collection.ts +7 -51
  52. package/client/space_lua/query_env.ts +0 -2
  53. package/client/space_lua/render_lua_markdown.ts +2 -7
  54. package/client/space_lua/render_widget.ts +173 -0
  55. package/client/space_lua/runtime.ts +133 -92
  56. package/client/space_lua/stdlib/crypto.ts +8 -3
  57. package/client/space_lua/stdlib/encoding.ts +27 -9
  58. package/client/space_lua/stdlib/format.ts +0 -12
  59. package/client/space_lua/stdlib/js.ts +136 -23
  60. package/client/space_lua/stdlib/load.ts +24 -16
  61. package/client/space_lua/stdlib/math.ts +331 -133
  62. package/client/space_lua/stdlib/net.ts +57 -13
  63. package/client/space_lua/stdlib/os.ts +111 -54
  64. package/client/space_lua/stdlib/pattern.ts +10 -15
  65. package/client/space_lua/stdlib/space_lua.ts +344 -21
  66. package/client/space_lua/stdlib/string.ts +282 -104
  67. package/client/space_lua/stdlib/string_pack.ts +58 -22
  68. package/client/space_lua/stdlib/table.ts +195 -45
  69. package/client/space_lua/stdlib.ts +354 -125
  70. package/client/space_lua/syscalls.ts +270 -0
  71. package/client/space_lua/tonumber.ts +0 -9
  72. package/dist/plug-compile.js +2 -3
  73. package/package.json +15 -5
  74. package/plug-api/lib/async.ts +1 -6
  75. package/plug-api/lib/collation.ts +22 -0
  76. package/plug-api/lib/crypto.ts +16 -15
  77. package/plug-api/lib/dates.ts +33 -0
  78. package/plug-api/lib/fuzzy.ts +282 -0
  79. package/plug-api/lib/json.ts +0 -6
  80. package/plug-api/lib/limited_map.ts +0 -2
  81. package/plug-api/lib/link_write.ts +27 -0
  82. package/plug-api/{ui → lib}/panel_styles.ts +4 -3
  83. package/plug-api/lib/ref.ts +124 -5
  84. package/plug-api/lib/resolve.ts +0 -1
  85. package/plug-api/lib/resolve_path.ts +290 -0
  86. package/plug-api/lib/shortcut.ts +17 -1
  87. package/plug-api/lib/tags.ts +0 -3
  88. package/plug-api/lib/transclusion.ts +28 -1
  89. package/plug-api/lib/tree.ts +0 -5
  90. package/plug-api/lib/yaml.ts +3 -42
  91. package/plug-api/syscall.ts +1 -5
  92. package/plug-api/syscalls/config.ts +7 -5
  93. package/plug-api/syscalls/editor.ts +70 -208
  94. package/plug-api/syscalls/icon.ts +18 -0
  95. package/plug-api/syscalls/index.ts +39 -5
  96. package/plug-api/syscalls/jsonschema.ts +9 -0
  97. package/plug-api/syscalls/lua.ts +7 -0
  98. package/plug-api/syscalls/search.ts +11 -0
  99. package/plug-api/syscalls/shell.ts +0 -1
  100. package/plug-api/syscalls/space.ts +122 -5
  101. package/plug-api/syscalls/sync.ts +23 -2
  102. package/plug-api/syscalls/system.ts +53 -0
  103. package/plug-api/syscalls.ts +2 -0
  104. package/plug-api/system_mock.ts +15 -2
  105. package/plug-api/types/client.ts +4 -3
  106. package/plug-api/types/datastore.ts +11 -2
  107. package/plug-api/types/index.ts +62 -1
  108. package/plug-api/types/manifest.ts +22 -4
  109. package/plug-api/types/profile.ts +13 -0
  110. package/plug-api/types/revisions.ts +67 -0
  111. package/plug-api/ui/cx.ts +1 -3
  112. package/plug-api/ui/description.ts +64 -0
  113. package/plug-api/ui/hover.ts +69 -0
  114. package/plug-api/ui/index.ts +61 -2
  115. package/plug-api/ui/scroll.ts +30 -0
  116. package/plug-api/ui/slugify.ts +44 -0
  117. package/plug-api/ui/tree_model.ts +263 -0
  118. package/plug-api/ui/tree_types.ts +66 -0
  119. package/plug-api/ui/use_fit_collapse.ts +67 -0
  120. package/plugs/builtin_plugs.ts +0 -1
  121. package/plugs/index/types.ts +9 -0
  122. package/client/plugos/syscalls/lua.ts +0 -81
  123. package/plug-api/lib/memory_cache.ts +0 -21
@@ -12,29 +12,83 @@ export function serviceRegistrySyscalls(
12
12
  /**
13
13
  * Define a Lua event listener
14
14
  */
15
- "service.define": (_ctx, def: ServiceSpec) => {
16
- return serviceRegistry.define(def);
15
+ "service.define": {
16
+ callback: (_ctx, def: ServiceSpec) => {
17
+ return serviceRegistry.define(def);
18
+ },
19
+ description: "Defines a service that can be discovered by selector.",
20
+ parameters: [
21
+ {
22
+ name: "spec",
23
+ type: "table",
24
+ description: "Selector, match rule, and run callback.",
25
+ },
26
+ ],
27
+ examples: [
28
+ {
29
+ code: 'service.define { selector = "greeter", match = {}, run = function(name) return "Hello " .. name end }',
30
+ },
31
+ ],
17
32
  },
18
- "service.discover": (
19
- _ctx,
20
- selector: string,
21
- data: any,
22
- ): Promise<ServiceMatch[]> => {
23
- return serviceRegistry.discover(selector, data);
33
+ "service.discover": {
34
+ callback: (
35
+ _ctx,
36
+ selector: string,
37
+ data: any,
38
+ ): Promise<ServiceMatch[]> => {
39
+ return serviceRegistry.discover(selector, data);
40
+ },
41
+ description: "Discovers matching services sorted by descending priority.",
42
+ parameters: [
43
+ {
44
+ name: "selector",
45
+ type: "string",
46
+ description: "Service selector.",
47
+ },
48
+ { name: "data", description: "Value passed to match callbacks." },
49
+ ],
50
+ returns: [
51
+ { type: "table", description: "Matching service descriptors." },
52
+ ],
24
53
  },
25
- "service.invoke": (
26
- _ctx,
27
- service: ServiceMatch,
28
- data: any,
29
- ): Promise<any> => {
30
- return serviceRegistry.invoke(service, data);
54
+ "service.invoke": {
55
+ callback: (_ctx, service: ServiceMatch, data: any): Promise<any> => {
56
+ return serviceRegistry.invoke(service, data);
57
+ },
58
+ description: "Invokes a previously discovered service match.",
59
+ parameters: [
60
+ {
61
+ name: "match",
62
+ type: "table",
63
+ description: "Service match returned by service.discover.",
64
+ },
65
+ { name: "data", description: "Value passed to the service." },
66
+ ],
67
+ returns: [{ description: "Service result." }],
31
68
  },
32
- "service.invokeBestMatch": (
33
- _ctx,
34
- selector: string,
35
- data: any,
36
- ): Promise<any> => {
37
- return serviceRegistry.invokeBestMatch(selector, data);
69
+ "service.invokeBestMatch": {
70
+ callback: (_ctx, selector: string, data: any): Promise<any> => {
71
+ return serviceRegistry.invokeBestMatch(selector, data);
72
+ },
73
+ description:
74
+ "Discovers and invokes the highest-priority matching service.",
75
+ parameters: [
76
+ {
77
+ name: "selector",
78
+ type: "string",
79
+ description: "Service selector.",
80
+ },
81
+ {
82
+ name: "data",
83
+ description: "Value used for matching and invocation.",
84
+ },
85
+ ],
86
+ returns: [{ description: "Best matching service result." }],
87
+ examples: [
88
+ {
89
+ code: 'local greeting = service.invokeBestMatch("greeter", "Pete")',
90
+ },
91
+ ],
38
92
  },
39
93
  };
40
94
  }
@@ -4,33 +4,63 @@ import { fsEndpoint } from "../../spaces/constants.ts";
4
4
 
5
5
  export function shellSyscalls(client: Client): SysCallMapping {
6
6
  return {
7
- "shell.run": async (
8
- _ctx,
9
- cmd: string,
10
- args: string[],
11
- stdin?: string,
12
- ): Promise<{ stdout: string; stderr: string; code: number }> => {
13
- if (!client.httpSpacePrimitives) {
14
- throw new Error("Not supported in fully local mode");
15
- }
16
- const resp = client.httpSpacePrimitives.authenticatedFetch(
17
- buildShellUrl(client),
7
+ "shell.run": {
8
+ callback: async (
9
+ _ctx,
10
+ cmd: string,
11
+ args: string[],
12
+ stdin?: string,
13
+ ): Promise<{ stdout: string; stderr: string; code: number }> => {
14
+ if (!client.httpSpacePrimitives) {
15
+ throw new Error("Not supported in fully local mode");
16
+ }
17
+ const resp = client.httpSpacePrimitives.authenticatedFetch(
18
+ buildShellUrl(client),
19
+ {
20
+ method: "POST",
21
+ body: JSON.stringify({
22
+ cmd,
23
+ args,
24
+ stdin,
25
+ }),
26
+ },
27
+ );
28
+ const { code, stderr, stdout } = await (await resp).json();
29
+ return { code, stderr, stdout };
30
+ },
31
+ description: "Runs a shell command on the server and returns its output.",
32
+ parameters: [
33
+ { name: "command", type: "string", description: "Executable name." },
18
34
  {
19
- method: "POST",
20
- body: JSON.stringify({
21
- cmd,
22
- args,
23
- stdin,
24
- }),
35
+ name: "arguments",
36
+ type: "table",
37
+ description: "Command arguments.",
25
38
  },
26
- );
27
- const { code, stderr, stdout } = await (await resp).json();
28
- return { code, stderr, stdout };
39
+ {
40
+ name: "stdin",
41
+ type: "string",
42
+ description: "Text supplied on standard input.",
43
+ optional: true,
44
+ },
45
+ ],
46
+ returns: [
47
+ {
48
+ type: "table",
49
+ description: "stdout, stderr, and numeric exit code.",
50
+ },
51
+ ],
52
+ examples: [
53
+ {
54
+ code: 'local result = shell.run("ls", {"-l"})\nprint(result.stdout)',
55
+ },
56
+ {
57
+ code: 'local result = shell.run("cat", {}, "hello")\nprint(result.stdout)',
58
+ },
59
+ ],
29
60
  },
30
61
  };
31
62
  }
32
63
 
33
64
  function buildShellUrl(client: Client) {
34
- // Strip off the /.fs and replace with /.shell
35
65
  return `${client.httpSpacePrimitives.url.slice(0, -fsEndpoint.length)}/.shell`;
36
66
  }