File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212} from "../core/utils.js"
1313
1414import "../globals/index.js"
15+ import "./launch-context.js"
1516
1617import { getScripts } from "../core/db.js"
1718import type { PromptConfig } from "../types/core"
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments