Skip to content

Commit e94e6f7

Browse files
committed
feat: import launch context module in global API file
- Added import statement for the launch-context module in the global.ts file to enhance modularity and functionality.
1 parent a08df96 commit e94e6f7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/api/global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "../core/utils.js"
1313

1414
import "../globals/index.js"
15+
import "./launch-context.js"
1516

1617
import { getScripts } from "../core/db.js"
1718
import type { PromptConfig } from "../types/core"

src/api/launch-context.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Provides information about how the current script was launched
3+
*/
4+
5+
export type LaunchContext = 'mcp' | 'http' | 'socket' | 'direct' | 'cli'
6+
7+
declare global {
8+
/**
9+
* The context in which the script was launched
10+
* - 'mcp': Launched via Model Context Protocol server
11+
* - 'http': Launched via HTTP server
12+
* - 'socket': Launched via Unix socket (sk)
13+
* - 'direct': Direct internal call
14+
* - 'cli': Command line (future)
15+
*/
16+
var KIT_LAUNCH_CONTEXT: LaunchContext
17+
var _KIT_LAUNCH_CONTEXT_CACHE: LaunchContext | undefined
18+
}
19+
20+
// Lazy getter that determines launch context on first access
21+
Object.defineProperty(global, 'KIT_LAUNCH_CONTEXT', {
22+
get() {
23+
// Return cached value if already determined
24+
if (global._KIT_LAUNCH_CONTEXT_CACHE !== undefined) {
25+
return global._KIT_LAUNCH_CONTEXT_CACHE
26+
}
27+
28+
// Determine launch context from headers
29+
const headers = global.headers || {}
30+
31+
// Check the X-Kit-Launch-Context header set by handleScript
32+
if (headers['X-Kit-Launch-Context']) {
33+
global._KIT_LAUNCH_CONTEXT_CACHE = headers['X-Kit-Launch-Context'] as LaunchContext
34+
} else {
35+
// Fallback to 'direct' if no context header is present
36+
global._KIT_LAUNCH_CONTEXT_CACHE = 'direct'
37+
}
38+
39+
return global._KIT_LAUNCH_CONTEXT_CACHE
40+
},
41+
enumerable: true,
42+
configurable: true
43+
})

0 commit comments

Comments
 (0)