@briancray/belte 0.1.0 → 0.2.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.
- package/bin/belte.ts +25 -12
- package/package.json +2 -1
- package/src/appEntry.ts +124 -0
- package/src/belteResolverPlugin.ts +236 -202
- package/src/build.ts +6 -67
- package/src/buildCli.ts +36 -63
- package/src/buildDisconnected.ts +127 -0
- package/src/bundleApp.ts +123 -0
- package/src/bundleDisconnectedEntry.ts +17 -0
- package/src/cliEntry.ts +3 -9
- package/src/compile.ts +4 -15
- package/src/controlServerWorker.ts +261 -0
- package/src/dedupeSveltePlugin.ts +66 -0
- package/src/discoveryEntry.ts +12 -11
- package/src/lib/browser/cache.ts +3 -6
- package/src/lib/browser/page.svelte.ts +19 -21
- package/src/lib/browser/socketChannel.ts +11 -1
- package/src/lib/browser/types/Pages.ts +1 -1
- package/src/lib/bundle/BundleMenu.ts +11 -0
- package/src/lib/bundle/BundleMenuItem.ts +24 -0
- package/src/lib/bundle/BundleWindow.ts +20 -0
- package/src/lib/bundle/bindConnectedFlag.ts +29 -0
- package/src/lib/bundle/bindRequestNavigate.ts +31 -0
- package/src/lib/bundle/buildWebviewLib.ts +111 -0
- package/src/lib/bundle/disconnected.css +9 -0
- package/src/lib/bundle/disconnected.svelte +192 -0
- package/src/lib/bundle/ensureWebviewLib.ts +20 -0
- package/src/lib/bundle/exitWithParent.ts +28 -0
- package/src/lib/bundle/findFreePort.ts +14 -0
- package/src/lib/bundle/infoPlist.ts +46 -0
- package/src/lib/bundle/installMacMenu.ts +39 -0
- package/src/lib/bundle/listenLocalControlServer.ts +19 -0
- package/src/lib/bundle/native/belteMenu.mm +298 -0
- package/src/lib/bundle/native/webview.h +4557 -0
- package/src/lib/bundle/onMenu.ts +26 -0
- package/src/lib/bundle/openWebview.ts +81 -0
- package/src/lib/bundle/pngToIcns.ts +47 -0
- package/src/lib/bundle/probeBelteServer.ts +34 -0
- package/src/lib/bundle/resolveServerBinary.ts +12 -0
- package/src/lib/bundle/resolveWebviewLib.ts +51 -0
- package/src/lib/bundle/serverBinaryFilename.ts +8 -0
- package/src/lib/bundle/stableLocalPort.ts +19 -0
- package/src/lib/bundle/waitForServer.ts +23 -0
- package/src/lib/bundle/webviewBuildRevision.ts +9 -0
- package/src/lib/bundle/webviewCachePath.ts +23 -0
- package/src/lib/bundle/webviewLibName.ts +11 -0
- package/src/lib/bundle/webviewVersion.ts +7 -0
- package/src/lib/cli/createClient.ts +34 -36
- package/src/lib/cli/printHelp.ts +45 -2
- package/src/lib/cli/runCli.ts +12 -3
- package/src/lib/mcp/createMcpResourceServer.ts +1 -1
- package/src/lib/mcp/dispatchMcpRequest.ts +53 -73
- package/src/lib/server/AppModule.ts +2 -2
- package/src/lib/server/cli/handleCliDownload.ts +4 -5
- package/src/lib/server/cli/handleCliInstall.ts +17 -0
- package/src/lib/server/error.ts +23 -9
- package/src/lib/server/json.ts +5 -5
- package/src/lib/server/jsonl.ts +10 -5
- package/src/lib/server/prompts/definePrompt.ts +6 -6
- package/src/lib/server/prompts/renderPromptTemplate.ts +16 -0
- package/src/lib/server/prompts/types/Prompt.ts +8 -9
- package/src/lib/server/prompts/types/PromptOptions.ts +7 -12
- package/src/lib/server/prompts/types/PromptRegistryEntry.ts +3 -5
- package/src/lib/server/prompts/types/PromptRoutes.ts +4 -4
- package/src/lib/server/redirect.ts +13 -8
- package/src/lib/server/rpc/defineVerb.ts +4 -3
- package/src/lib/server/rpc/findVerbByCommandName.ts +18 -0
- package/src/lib/server/rpc/types/RemoteFunction.ts +1 -1
- package/src/lib/server/rpc/types/RemoteHandler.ts +4 -0
- package/src/lib/server/runtime/acceptsZstd.ts +8 -0
- package/src/lib/server/runtime/buildOpenApiSpec.ts +2 -0
- package/src/lib/server/runtime/cacheControlForAsset.ts +7 -2
- package/src/lib/server/runtime/createAssetHeaderCache.ts +35 -0
- package/src/lib/server/runtime/createPublicAssetServer.ts +6 -20
- package/src/lib/server/runtime/createServer.ts +50 -58
- package/src/lib/server/runtime/registryManifests.ts +33 -15
- package/src/lib/server/runtime/types/RequestStore.ts +2 -3
- package/src/lib/server/runtime/withResponseDefaults.ts +24 -0
- package/src/lib/server/sockets/createSocketDispatcher.ts +10 -7
- package/src/lib/server/sse.ts +10 -5
- package/src/lib/shared/belteImportName.test.ts +58 -0
- package/src/lib/shared/belteImportName.ts +45 -0
- package/src/lib/shared/beltePackageName.ts +7 -0
- package/src/lib/shared/cacheControlValues.ts +10 -2
- package/src/lib/shared/canonicalJson.ts +1 -5
- package/src/lib/shared/createCacheStore.ts +29 -20
- package/src/lib/shared/exitOnBuildFailure.ts +17 -0
- package/src/lib/shared/fileStem.ts +9 -0
- package/src/lib/shared/jsonSchemaForPromptArguments.ts +29 -0
- package/src/lib/shared/keyForRemoteCall.ts +7 -5
- package/src/lib/shared/parsePromptMarkdown.ts +34 -0
- package/src/lib/shared/prepareRpcModule.ts +14 -4
- package/src/lib/shared/prepareSocketModule.ts +16 -2
- package/src/lib/shared/promptNameForFile.ts +5 -5
- package/src/lib/shared/subscribableFromResponse.ts +104 -215
- package/src/lib/shared/types/PromptArgument.ts +12 -0
- package/src/lib/shared/writeRoutesDts.ts +5 -7
- package/src/serverBuildPlugins.ts +25 -0
- package/src/serverEntry.ts +4 -0
- package/template/package.json +3 -2
- package/src/lib/server/prompt.ts +0 -30
- package/src/lib/server/prompts/types/PromptMessage.ts +0 -10
- package/src/lib/shared/preparePromptModule.ts +0 -36
|
@@ -9,13 +9,11 @@ when dispatching, so the page component sees `params.rest`, not
|
|
|
9
9
|
`params['*']`.
|
|
10
10
|
*/
|
|
11
11
|
function paramsForRoute(routeUrl: string): Record<string, 'string'> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return params
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
parseRouteSegments(routeUrl)
|
|
14
|
+
.filter((segment) => segment.kind === 'param')
|
|
15
|
+
.map((segment) => [segment.name, 'string'] as const),
|
|
16
|
+
)
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
function renderParamsShape(shape: Record<string, 'string'>): string {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BunPlugin } from 'bun'
|
|
2
|
+
import { belteResolverPlugin } from './belteResolverPlugin.ts'
|
|
3
|
+
import type { SvelteConfig } from './lib/server/runtime/types/SvelteConfig.ts'
|
|
4
|
+
import { sveltePlugin } from './sveltePlugin.ts'
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
The server-target Bun.build plugin pair shared by compile / buildCli /
|
|
8
|
+
bundleApp: the svelte loader (server generate) plus belte's virtual-module
|
|
9
|
+
resolver. `embedAssets` flips on the zstd asset embed used by the standalone
|
|
10
|
+
server binary; the CLI + launcher builds leave it off.
|
|
11
|
+
*/
|
|
12
|
+
export function serverBuildPlugins({
|
|
13
|
+
cwd,
|
|
14
|
+
svelteConfig,
|
|
15
|
+
embedAssets = false,
|
|
16
|
+
}: {
|
|
17
|
+
cwd: string
|
|
18
|
+
svelteConfig?: SvelteConfig
|
|
19
|
+
embedAssets?: boolean
|
|
20
|
+
}): BunPlugin[] {
|
|
21
|
+
return [
|
|
22
|
+
sveltePlugin({ generate: 'server', svelteConfig }),
|
|
23
|
+
belteResolverPlugin({ cwd, embedAssets, target: 'server' }),
|
|
24
|
+
]
|
|
25
|
+
}
|
package/src/serverEntry.ts
CHANGED
|
@@ -24,10 +24,14 @@ import { rpc } from './_virtual/rpc.ts'
|
|
|
24
24
|
import { shell } from './_virtual/shell.ts'
|
|
25
25
|
// @ts-expect-error virtual module resolved by belteResolverPlugin
|
|
26
26
|
import { sockets } from './_virtual/sockets.ts'
|
|
27
|
+
import { exitWithParent } from './lib/bundle/exitWithParent.ts'
|
|
27
28
|
import { createServer } from './lib/server/runtime/createServer.ts'
|
|
28
29
|
import { requestContext } from './lib/server/runtime/requestContext.ts'
|
|
29
30
|
import { setCacheStoreResolver } from './lib/shared/setCacheStoreResolver.ts'
|
|
30
31
|
|
|
32
|
+
// In a bundle, tie this server's life to the launcher's (no-op standalone).
|
|
33
|
+
exitWithParent()
|
|
34
|
+
|
|
31
35
|
setCacheStoreResolver(() => requestContext.getStore()?.cache)
|
|
32
36
|
|
|
33
37
|
await createServer({
|
package/template/package.json
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
"dev": "belte dev",
|
|
8
8
|
"build": "belte build",
|
|
9
9
|
"start": "belte start",
|
|
10
|
-
"compile": "belte compile"
|
|
10
|
+
"compile": "belte compile",
|
|
11
|
+
"bundle": "belte bundle"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
+
"belte": "npm:@briancray/belte@^0.2.0",
|
|
14
15
|
"svelte": "^5.0.0"
|
|
15
16
|
}
|
|
16
17
|
}
|
package/src/lib/server/prompt.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Prompt } from './prompts/types/Prompt.ts'
|
|
2
|
-
import type { PromptOptions } from './prompts/types/PromptOptions.ts'
|
|
3
|
-
import type { StandardSchemaV1 } from './rpc/types/StandardSchemaV1.ts'
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Declares an MCP prompt inside a file under `src/server/prompts/`. Each
|
|
7
|
-
file contains exactly one export, named after the file (e.g.
|
|
8
|
-
`summarize.ts` → `export const summarize = prompt(...)`). The bundler
|
|
9
|
-
reads the export name from the filename and the prompt name from the file
|
|
10
|
-
path under `src/server/prompts/`, then rewrites this call to bind the name
|
|
11
|
-
into definePrompt.
|
|
12
|
-
|
|
13
|
-
`render(args)` returns the messages MCP hands back for `prompts/get`:
|
|
14
|
-
either a bare string (one user message) or an explicit message array.
|
|
15
|
-
When `schema` is set, `Args` infers from `InferOutput<Schema>`, incoming
|
|
16
|
-
arguments validate against it, and MCP advertises the argument list in
|
|
17
|
-
`prompts/list`.
|
|
18
|
-
|
|
19
|
-
This function exists only for the type signature; calling it directly
|
|
20
|
-
means the bundler plugin didn't process the file, which throws.
|
|
21
|
-
*/
|
|
22
|
-
export function prompt<Schema extends StandardSchemaV1>(
|
|
23
|
-
opts: PromptOptions<StandardSchemaV1.InferOutput<Schema>> & { schema: Schema },
|
|
24
|
-
): Prompt<StandardSchemaV1.InferOutput<Schema>>
|
|
25
|
-
export function prompt<Args = Record<string, string>>(opts: PromptOptions<Args>): Prompt<Args>
|
|
26
|
-
export function prompt(_opts: PromptOptions): Prompt {
|
|
27
|
-
throw new Error(
|
|
28
|
-
'[belte] `prompt(...)` was called outside a prompts module — the prompt helper is only valid as the value of `export const <filename> = ...` inside a file under src/server/prompts/',
|
|
29
|
-
)
|
|
30
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
A single message in an MCP prompt's rendered output. `prompt({ render })`
|
|
3
|
-
returns either a bare string (sugar for one `user` message) or an array
|
|
4
|
-
of these. The dispatcher maps each into the MCP `prompts/get` wire shape
|
|
5
|
-
({ role, content: { type: 'text', text } }).
|
|
6
|
-
*/
|
|
7
|
-
export type PromptMessage = {
|
|
8
|
-
role: 'user' | 'assistant'
|
|
9
|
-
text: string
|
|
10
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { findExportCallSite } from './findExportCallSite.ts'
|
|
2
|
-
import { stripImport } from './stripImport.ts'
|
|
3
|
-
|
|
4
|
-
const SINGLE_EXPORT_ERROR =
|
|
5
|
-
'[belte] prompts module contains more than one `prompt(...)` export — each file must declare exactly one prompt'
|
|
6
|
-
|
|
7
|
-
export type PreparedPromptModule = {
|
|
8
|
-
exportName: string
|
|
9
|
-
rewriteForServer: (name: string) => string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
Scans a `src/server/prompts/**` module once and returns its declared
|
|
14
|
-
export name plus a closure that, given the prompt name, emits the
|
|
15
|
-
server-side rewrite (`__belteDefinePrompt__("<name>", opts)` spliced into
|
|
16
|
-
the original source). Mirrors prepareSocketModule — a single tokenizer
|
|
17
|
-
pass so a `prompt` mention inside a string or comment is left alone.
|
|
18
|
-
*/
|
|
19
|
-
export function preparePromptModule(source: string): PreparedPromptModule | undefined {
|
|
20
|
-
const stripped = stripImport(source, 'belte/server/prompt')
|
|
21
|
-
const site = findExportCallSite(stripped, (ident) => ident === 'prompt', SINGLE_EXPORT_ERROR)
|
|
22
|
-
if (!site) {
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
exportName: site.exportName,
|
|
27
|
-
rewriteForServer(name: string): string {
|
|
28
|
-
const inner = stripped.slice(site.parenStart + 1, site.parenEnd).trim()
|
|
29
|
-
const binding =
|
|
30
|
-
inner.length === 0
|
|
31
|
-
? `__belteDefinePrompt__(${JSON.stringify(name)})`
|
|
32
|
-
: `__belteDefinePrompt__(${JSON.stringify(name)}, ${stripped.slice(site.parenStart + 1, site.parenEnd)})`
|
|
33
|
-
return stripped.slice(0, site.callStart) + binding + stripped.slice(site.parenEnd + 1)
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
}
|