@ggui-ai/mcp-server 0.1.0-rc.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.
Files changed (141) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +48 -0
  3. package/dist/admin-blueprints-transport.d.ts +114 -0
  4. package/dist/admin-blueprints-transport.d.ts.map +1 -0
  5. package/dist/admin-blueprints-transport.js +118 -0
  6. package/dist/admin-oauth-providers-transport.d.ts +40 -0
  7. package/dist/admin-oauth-providers-transport.d.ts.map +1 -0
  8. package/dist/admin-oauth-providers-transport.js +263 -0
  9. package/dist/auth.d.ts +39 -0
  10. package/dist/auth.d.ts.map +1 -0
  11. package/dist/auth.js +75 -0
  12. package/dist/build-mcp.d.ts +128 -0
  13. package/dist/build-mcp.d.ts.map +1 -0
  14. package/dist/build-mcp.js +113 -0
  15. package/dist/code-store-fs.d.ts +19 -0
  16. package/dist/code-store-fs.d.ts.map +1 -0
  17. package/dist/code-store-fs.js +98 -0
  18. package/dist/console-auth.d.ts +139 -0
  19. package/dist/console-auth.d.ts.map +1 -0
  20. package/dist/console-auth.js +102 -0
  21. package/dist/console-cache.d.ts +78 -0
  22. package/dist/console-cache.d.ts.map +1 -0
  23. package/dist/console-cache.js +105 -0
  24. package/dist/console-headers.d.ts +124 -0
  25. package/dist/console-headers.d.ts.map +1 -0
  26. package/dist/console-headers.js +49 -0
  27. package/dist/console-llm-trace.d.ts +66 -0
  28. package/dist/console-llm-trace.d.ts.map +1 -0
  29. package/dist/console-llm-trace.js +105 -0
  30. package/dist/console-payloads.d.ts +67 -0
  31. package/dist/console-payloads.d.ts.map +1 -0
  32. package/dist/console-payloads.js +105 -0
  33. package/dist/console-theme-routes.d.ts +111 -0
  34. package/dist/console-theme-routes.d.ts.map +1 -0
  35. package/dist/console-theme-routes.js +202 -0
  36. package/dist/console-timeline.d.ts +45 -0
  37. package/dist/console-timeline.d.ts.map +1 -0
  38. package/dist/console-timeline.js +169 -0
  39. package/dist/console-validator.d.ts +67 -0
  40. package/dist/console-validator.d.ts.map +1 -0
  41. package/dist/console-validator.js +105 -0
  42. package/dist/console-welcome.d.ts +7 -0
  43. package/dist/console-welcome.d.ts.map +1 -0
  44. package/dist/console-welcome.js +221 -0
  45. package/dist/csrf-middleware.d.ts +55 -0
  46. package/dist/csrf-middleware.d.ts.map +1 -0
  47. package/dist/csrf-middleware.js +138 -0
  48. package/dist/email-login.d.ts +174 -0
  49. package/dist/email-login.d.ts.map +1 -0
  50. package/dist/email-login.js +254 -0
  51. package/dist/email-resend.d.ts +29 -0
  52. package/dist/email-resend.d.ts.map +1 -0
  53. package/dist/email-resend.js +71 -0
  54. package/dist/email-sender-from-env.d.ts +34 -0
  55. package/dist/email-sender-from-env.d.ts.map +1 -0
  56. package/dist/email-sender-from-env.js +112 -0
  57. package/dist/email-smtp.d.ts +42 -0
  58. package/dist/email-smtp.d.ts.map +1 -0
  59. package/dist/email-smtp.js +81 -0
  60. package/dist/index.d.ts +102 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +122 -0
  63. package/dist/instructions-presets.d.ts +112 -0
  64. package/dist/instructions-presets.d.ts.map +1 -0
  65. package/dist/instructions-presets.js +195 -0
  66. package/dist/llm-backed-negotiator.d.ts +178 -0
  67. package/dist/llm-backed-negotiator.d.ts.map +1 -0
  68. package/dist/llm-backed-negotiator.js +579 -0
  69. package/dist/logger.d.ts +23 -0
  70. package/dist/logger.d.ts.map +1 -0
  71. package/dist/logger.js +41 -0
  72. package/dist/mcp-apps-inbound.d.ts +86 -0
  73. package/dist/mcp-apps-inbound.d.ts.map +1 -0
  74. package/dist/mcp-apps-inbound.js +278 -0
  75. package/dist/mcp-apps-outbound.d.ts +448 -0
  76. package/dist/mcp-apps-outbound.d.ts.map +1 -0
  77. package/dist/mcp-apps-outbound.js +1163 -0
  78. package/dist/mcp-mounts.d.ts +239 -0
  79. package/dist/mcp-mounts.d.ts.map +1 -0
  80. package/dist/mcp-mounts.js +222 -0
  81. package/dist/oauth-login-types.d.ts +160 -0
  82. package/dist/oauth-login-types.d.ts.map +1 -0
  83. package/dist/oauth-login-types.js +9 -0
  84. package/dist/oauth-login.d.ts +77 -0
  85. package/dist/oauth-login.d.ts.map +1 -0
  86. package/dist/oauth-login.js +455 -0
  87. package/dist/oauth-providers/github.d.ts +17 -0
  88. package/dist/oauth-providers/github.d.ts.map +1 -0
  89. package/dist/oauth-providers/github.js +89 -0
  90. package/dist/oauth-providers/google.d.ts +18 -0
  91. package/dist/oauth-providers/google.d.ts.map +1 -0
  92. package/dist/oauth-providers/google.js +59 -0
  93. package/dist/oauth-providers-store.d.ts +32 -0
  94. package/dist/oauth-providers-store.d.ts.map +1 -0
  95. package/dist/oauth-providers-store.js +291 -0
  96. package/dist/oauth.d.ts +347 -0
  97. package/dist/oauth.d.ts.map +1 -0
  98. package/dist/oauth.js +686 -0
  99. package/dist/pairing-transport.d.ts +99 -0
  100. package/dist/pairing-transport.d.ts.map +1 -0
  101. package/dist/pairing-transport.js +223 -0
  102. package/dist/rate-limit-middleware.d.ts +36 -0
  103. package/dist/rate-limit-middleware.d.ts.map +1 -0
  104. package/dist/rate-limit-middleware.js +57 -0
  105. package/dist/render-gate.d.ts +87 -0
  106. package/dist/render-gate.d.ts.map +1 -0
  107. package/dist/render-gate.js +77 -0
  108. package/dist/render-rate-limit.d.ts +59 -0
  109. package/dist/render-rate-limit.d.ts.map +1 -0
  110. package/dist/render-rate-limit.js +73 -0
  111. package/dist/render-signing.d.ts +98 -0
  112. package/dist/render-signing.d.ts.map +1 -0
  113. package/dist/render-signing.js +113 -0
  114. package/dist/request-context.d.ts +113 -0
  115. package/dist/request-context.d.ts.map +1 -0
  116. package/dist/request-context.js +154 -0
  117. package/dist/reserved-validators.d.ts +22 -0
  118. package/dist/reserved-validators.d.ts.map +1 -0
  119. package/dist/reserved-validators.js +101 -0
  120. package/dist/schema-compat.d.ts +167 -0
  121. package/dist/schema-compat.d.ts.map +1 -0
  122. package/dist/schema-compat.js +187 -0
  123. package/dist/security-headers-middleware.d.ts +38 -0
  124. package/dist/security-headers-middleware.d.ts.map +1 -0
  125. package/dist/security-headers-middleware.js +30 -0
  126. package/dist/server.d.ts +2060 -0
  127. package/dist/server.d.ts.map +1 -0
  128. package/dist/server.js +6338 -0
  129. package/dist/session-channel.d.ts +651 -0
  130. package/dist/session-channel.d.ts.map +1 -0
  131. package/dist/session-channel.js +1756 -0
  132. package/dist/storage.d.ts +89 -0
  133. package/dist/storage.d.ts.map +1 -0
  134. package/dist/storage.js +171 -0
  135. package/dist/thread-transport.d.ts +118 -0
  136. package/dist/thread-transport.d.ts.map +1 -0
  137. package/dist/thread-transport.js +478 -0
  138. package/dist/user-session-auth.d.ts +167 -0
  139. package/dist/user-session-auth.d.ts.map +1 -0
  140. package/dist/user-session-auth.js +148 -0
  141. package/package.json +76 -0
@@ -0,0 +1,178 @@
1
+ /**
2
+ * LLM-backed `HandshakeNegotiator` for the OSS server.
3
+ *
4
+ * Composes BYOK credentials + a `ProviderAdapter` from
5
+ * `@ggui-ai/ui-gen/providers` into an `LLMCaller`, then runs
6
+ * `@ggui-ai/negotiator`'s `negotiate()` pipeline. Mirrors the cloud
7
+ * `createBedrockNegotiator` pattern (cloud/ggui-protocol-pod/src/
8
+ * tools/handshake.ts), stripped of Bedrock-specific embedding +
9
+ * vector-store wiring — those are absent on OSS by default and
10
+ * `negotiate()` handles missing RAG deps gracefully.
11
+ *
12
+ * ## What this binding does
13
+ *
14
+ * On every `ggui_handshake` call:
15
+ *
16
+ * 1. Resolves BYOK creds via the supplied `resolveLlm(ctx)`. No
17
+ * creds → returns a "create" result with a `no-creds` reason.
18
+ * 2. Selects the matching `ProviderAdapter` for the resolved
19
+ * provider (anthropic / openai / google / openrouter / bedrock).
20
+ * 3. Wraps the adapter into an `LLMCaller` (single-shot text
21
+ * completion).
22
+ * 4. Calls `negotiate(deps, input)` with `embedding: undefined,
23
+ * vectors: undefined` — RAG search is skipped, decision LLM
24
+ * runs against an empty candidate list, returns a sensible
25
+ * create/update decision based on session state + agent
26
+ * prompt.
27
+ * 5. Maps the `NegotiateResult` onto the OSS-shape
28
+ * `HandshakeNegotiatorResult`.
29
+ *
30
+ * ## Failure modes
31
+ *
32
+ * Operational errors (network flap, provider 5xx, rate limit) fail
33
+ * open: returns a "create" result with the error reason. Bugs
34
+ * (TypeError / ReferenceError / RangeError / SyntaxError) re-throw
35
+ * — those are programmer errors that should surface, not be
36
+ * silently swallowed.
37
+ *
38
+ * ## Cost posture
39
+ *
40
+ * One LLM call per handshake (when creds resolve). Operators
41
+ * concerned about cost can either (a) skip handshake and call
42
+ * `ggui_push` directly with `{story}`, or (b) bind a different
43
+ * negotiator (e.g., the cache-backed one for read-only cache
44
+ * lookups) via `createGguiServer({handshake: {negotiator: ...}})`.
45
+ *
46
+ * ## Default binding
47
+ *
48
+ * Bound by default in `createGguiServer` when handshake is enabled
49
+ * AND a `resolveLlm` is wired into `generation`. OSS is cloud-aligned:
50
+ * same `negotiate()` pipeline, just with degraded RAG when local
51
+ * infrastructure isn't bound.
52
+ */
53
+ import { type LLMCaller } from '@ggui-ai/negotiator';
54
+ import type { EmbeddingProvider, LlmSelection, ProviderKeyRef, VariantSelectionContext, VariantSelectionDecision, VectorStore } from '@ggui-ai/mcp-server-core';
55
+ import type { HandlerContext } from '@ggui-ai/mcp-server-handlers';
56
+ import { type HandshakeNegotiator, type InstalledBlueprintsProvider } from '@ggui-ai/mcp-server-handlers/session-mutations';
57
+ import type { Blueprint } from '@ggui-ai/protocol';
58
+ /**
59
+ * Wrap a resolved BYOK credential pair into an `LLMCaller` the
60
+ * negotiator can call. The adapter is chosen via `selectAdapter`
61
+ * (anthropic / openai / google / openrouter / bedrock). `call` runs
62
+ * one `complete()` round-trip on the underlying adapter.
63
+ *
64
+ * `callStructured` is wired for Anthropic only. Anthropic's
65
+ * `/v1/messages` natively supports forced tool use via `tools[] +
66
+ * tool_choice: {type:'tool', name}`, so we hit the API directly here
67
+ * instead of expanding the `ProviderAdapter` interface for one
68
+ * provider. Other providers (OpenAI, Google, OpenRouter, Bedrock)
69
+ * omit `callStructured`; consumers detect absence and fall back to
70
+ * regex-JSON extraction on the text path. When this story shifts —
71
+ * e.g., we want OpenAI tool use too — promote `completeWithTool`
72
+ * onto `ProviderAdapter` as an optional method and wire each
73
+ * adapter; this in-place implementation stays the bridge until then.
74
+ *
75
+ * Used by:
76
+ * - `@ggui-ai/negotiator/llm-rerank` (Tier 2 RAG match judge)
77
+ * - `@ggui-ai/negotiator/synthesize-contract` (cold-path contract
78
+ * synthesizer)
79
+ */
80
+ export declare function buildLlmCaller(selection: LlmSelection, providerKey: ProviderKeyRef): LLMCaller;
81
+ /**
82
+ * Dependencies for `createLlmBackedHandshakeNegotiator`. Only
83
+ * `resolveLlm` is required; the rest carry default fallbacks.
84
+ */
85
+ export interface LlmBackedHandshakeNegotiatorDeps {
86
+ /**
87
+ * Per-call BYOK resolver. Returns `null` when no creds are
88
+ * available — the negotiator falls back to a "create" result with
89
+ * a clear reason rather than failing the handshake. Sync-or-async
90
+ * to match `GenerationDeps.resolveLlm`'s wider shape (in-process
91
+ * dispatchers can return synchronously).
92
+ */
93
+ resolveLlm: (ctx: HandlerContext) => {
94
+ selection: LlmSelection;
95
+ providerKey: ProviderKeyRef;
96
+ } | Promise<{
97
+ selection: LlmSelection;
98
+ providerKey: ProviderKeyRef;
99
+ } | null> | null;
100
+ /**
101
+ * Estimated cold-generation latency, embedded on the "create"
102
+ * fallback result's `plan.estimatedLatencyMs`. Default 30s.
103
+ */
104
+ estimatedGenerationLatencyMs?: number;
105
+ /**
106
+ * Blueprint-registry deps for the handshake-time exact-key match
107
+ * fast path. When bound, every `decide()` call first asks
108
+ * `matchBlueprint` whether the agent's draft canonical-key-equals
109
+ * an already-registered blueprint. A hit short-circuits the synth
110
+ * LLM round-trip and returns `origin: 'cache'` with the cached
111
+ * blueprint's contract + codeHash.
112
+ *
113
+ * The exact-key strategy is the only safe match when a contract is
114
+ * supplied (see the fuzzy-match gate in `blueprint-matcher.ts` —
115
+ * fuzzy matches across non-equal canonical contracts let cached
116
+ * call sites drift from the request's actionSpec/contextSpec wire
117
+ * surface).
118
+ * Semantic strategy fires only when contract is omitted, which the
119
+ * handshake input schema today disallows.
120
+ *
121
+ * Optional so deployments without RAG infrastructure (no embedding
122
+ * / vector store) continue to use the synth-only path. Mirrors the
123
+ * shape used by `push.ts:1539-1541` so a single
124
+ * `generationWithCache.cache` value threads into both seams.
125
+ */
126
+ cache?: {
127
+ readonly embedding: EmbeddingProvider;
128
+ readonly vectorStore: VectorStore;
129
+ };
130
+ /**
131
+ * Marketplace-install bridge. When wired alongside
132
+ * `cache`, handshake-time exact-key matches consult the installed-
133
+ * blueprint pool too — the provider lazily compiles + caches each
134
+ * installed blueprint on first ensureCached per scope, so the same
135
+ * canonical key the agent draft hashes to becomes a cache hit
136
+ * without a separate synth round-trip.
137
+ */
138
+ installedBlueprints?: InstalledBlueprintsProvider;
139
+ }
140
+ /**
141
+ * Build an LLM-backed `HandshakeNegotiator` for the OSS server.
142
+ * Wires BYOK creds + an LLM provider adapter into
143
+ * `@ggui-ai/negotiator`'s `negotiate()` pipeline. Operators get the
144
+ * same negotiation shape cloud uses, with RAG gracefully degraded
145
+ * (no embedding / vectors required).
146
+ *
147
+ * @public
148
+ */
149
+ export declare function createLlmBackedHandshakeNegotiator(deps: LlmBackedHandshakeNegotiatorDeps): HandshakeNegotiator;
150
+ /**
151
+ * The system prompt for the variant-selection LLM call. Calibration
152
+ * is load-bearing — the model is explicitly told to surface low
153
+ * confidence when signals are weak so the deterministic-ladder
154
+ * fallback takes over. The prompt is intentionally short: high
155
+ * token budget on the user message (candidate JSON) is more useful
156
+ * than verbose system framing.
157
+ */
158
+ export declare const VARIANT_SELECTION_SYSTEM_PROMPT = "You are the variant selector for the ggui UI matcher. You receive a shortlist of pre-built UI blueprint variants and a request context. Pick the variant that best fits the request.\n\nEach variant carries:\n - blueprintId: stable identity (you MUST echo back exactly one of these).\n - generator: which generator built it (e.g. \"ui-gen-default-haiku-4-5\", \"ui-gen-advanced-opus-4-7\"). Advanced wins on visual polish; default wins on simplicity.\n - validatorScore: optional 0-1 self-assessed quality from the advanced generator's validators. Higher is better, undefined \u21D2 unknown.\n - isOperatorDefault: true \u21D2 the human operator pinned this as the default. Strong signal.\n - variance.persona: free-form tag (\"minimalist\", \"data-dense\", \"mobile-first\"\u2026).\n - variance.aesthetic: optional free-form tag (\"glassy\", \"flat\", \"editorial\"\u2026).\n - variance.context: small structured signal (theme, accent, \u2026).\n - variance.seedPrompt: the operator's original prose that produced this variant.\n\nThe request context carries the same fields. Match on:\n 1. variance.persona equality / closeness (strongest non-pin signal).\n 2. variance.aesthetic equality / closeness.\n 3. variance.context overlap (shared keys + values).\n 4. seedPrompt semantic similarity to context.intent.\n\nHonor operator pins (isOperatorDefault: true) unless variance.persona / variance.aesthetic on the request clearly contradicts the pinned variant \u2014 that's the only case where you should override the pin.\n\nCalibrate confidence honestly. Return high (\u2265 0.7) only when a clear best match exists. Return low (< 0.6) when signals are weak \u2014 the orchestration falls back to a deterministic ladder in that case. The fallback is safe; over-confident picks are NOT.";
159
+ /**
160
+ * Build the user-message payload for the variant-selection prompt.
161
+ * The candidate list is projected to a compact JSON shape that
162
+ * surfaces the decision-relevant fields only — full contract
163
+ * embedding is too much surface area for a sub-second pick.
164
+ *
165
+ * Exposed for testing — the prompt structure is load-bearing, so
166
+ * snapshot tests against this output anchor regressions.
167
+ */
168
+ export declare function buildVariantSelectionUserMessage(candidates: readonly Blueprint[], context: VariantSelectionContext): string;
169
+ /**
170
+ * Parse + validate the LLM-tool-use response shape. Exposed for
171
+ * testing; in production it is only called via `runVariantSelectionLlm`.
172
+ *
173
+ * @throws Error on any shape violation. The caller catches and falls
174
+ * through to the deterministic ladder; the message is surfaced in
175
+ * `VariantSelectionResult.reason` for telemetry.
176
+ */
177
+ export declare function parseVariantSelectionResponse(raw: unknown): VariantSelectionDecision;
178
+ //# sourceMappingURL=llm-back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