@ggui-ai/protocol 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.
- package/LICENSE +201 -0
- package/README.md +46 -0
- package/dist/bridge/invoke-agent.d.ts +65 -0
- package/dist/bridge/invoke-agent.d.ts.map +1 -0
- package/dist/bridge/invoke-agent.js +113 -0
- package/dist/envelope-adapters.d.ts +24 -0
- package/dist/envelope-adapters.d.ts.map +1 -0
- package/dist/envelope-adapters.js +14 -0
- package/dist/envelopes/builders.d.ts +145 -0
- package/dist/envelopes/builders.d.ts.map +1 -0
- package/dist/envelopes/builders.js +113 -0
- package/dist/errors/unknown-permission-name.d.ts +12 -0
- package/dist/errors/unknown-permission-name.d.ts.map +1 -0
- package/dist/errors/unknown-permission-name.js +29 -0
- package/dist/errors/version-mismatch.d.ts +55 -0
- package/dist/errors/version-mismatch.d.ts.map +1 -0
- package/dist/errors/version-mismatch.js +52 -0
- package/dist/gadgets/resolve-contract-gadgets.d.ts +93 -0
- package/dist/gadgets/resolve-contract-gadgets.d.ts.map +1 -0
- package/dist/gadgets/resolve-contract-gadgets.js +119 -0
- package/dist/gadgets/stdlib-gadgets.d.ts +43 -0
- package/dist/gadgets/stdlib-gadgets.d.ts.map +1 -0
- package/dist/gadgets/stdlib-gadgets.js +161 -0
- package/dist/iframe-bridge.d.ts +63 -0
- package/dist/iframe-bridge.d.ts.map +1 -0
- package/dist/iframe-bridge.js +166 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/integrations/mcp-apps.d.ts +1218 -0
- package/dist/integrations/mcp-apps.d.ts.map +1 -0
- package/dist/integrations/mcp-apps.js +427 -0
- package/dist/navigation/index.d.ts +3 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/stack-navigation.d.ts +55 -0
- package/dist/navigation/stack-navigation.d.ts.map +1 -0
- package/dist/navigation/stack-navigation.js +80 -0
- package/dist/recommended-prompts.d.ts +56 -0
- package/dist/recommended-prompts.d.ts.map +1 -0
- package/dist/recommended-prompts.js +55 -0
- package/dist/registry/blueprint-key.d.ts +9 -0
- package/dist/registry/blueprint-key.d.ts.map +1 -0
- package/dist/registry/blueprint-key.js +28 -0
- package/dist/registry/canonicalize-contract.d.ts +35 -0
- package/dist/registry/canonicalize-contract.d.ts.map +1 -0
- package/dist/registry/canonicalize-contract.js +166 -0
- package/dist/registry/summarize-contract.d.ts +46 -0
- package/dist/registry/summarize-contract.d.ts.map +1 -0
- package/dist/registry/summarize-contract.js +63 -0
- package/dist/schema-learning/derive-contract.d.ts +67 -0
- package/dist/schema-learning/derive-contract.d.ts.map +1 -0
- package/dist/schema-learning/derive-contract.js +117 -0
- package/dist/schema-learning/merge.d.ts +32 -0
- package/dist/schema-learning/merge.d.ts.map +1 -0
- package/dist/schema-learning/merge.js +146 -0
- package/dist/schemas/blueprint.d.ts +32 -0
- package/dist/schemas/blueprint.d.ts.map +1 -0
- package/dist/schemas/blueprint.js +92 -0
- package/dist/schemas/data-contract.d.ts +750 -0
- package/dist/schemas/data-contract.d.ts.map +1 -0
- package/dist/schemas/data-contract.js +663 -0
- package/dist/schemas/gadget-name-grammar.d.ts +29 -0
- package/dist/schemas/gadget-name-grammar.d.ts.map +1 -0
- package/dist/schemas/gadget-name-grammar.js +28 -0
- package/dist/schemas/handshake-suggestion.d.ts +46 -0
- package/dist/schemas/handshake-suggestion.d.ts.map +1 -0
- package/dist/schemas/handshake-suggestion.js +107 -0
- package/dist/schemas/invoke.d.ts +337 -0
- package/dist/schemas/invoke.d.ts.map +1 -0
- package/dist/schemas/invoke.js +169 -0
- package/dist/schemas/mcp.d.ts +301 -0
- package/dist/schemas/mcp.d.ts.map +1 -0
- package/dist/schemas/mcp.js +373 -0
- package/dist/schemas/ops-blueprint.d.ts +176 -0
- package/dist/schemas/ops-blueprint.d.ts.map +1 -0
- package/dist/schemas/ops-blueprint.js +259 -0
- package/dist/schemas/sync-check.d.ts +11 -0
- package/dist/schemas/sync-check.d.ts.map +1 -0
- package/dist/schemas/sync-check.js +60 -0
- package/dist/screen-blueprints/define.d.ts +22 -0
- package/dist/screen-blueprints/define.d.ts.map +1 -0
- package/dist/screen-blueprints/define.js +3 -0
- package/dist/screen-blueprints/index.d.ts +4 -0
- package/dist/screen-blueprints/index.d.ts.map +1 -0
- package/dist/screen-blueprints/index.js +3 -0
- package/dist/screen-blueprints/match.d.ts +35 -0
- package/dist/screen-blueprints/match.d.ts.map +1 -0
- package/dist/screen-blueprints/match.js +51 -0
- package/dist/screen-blueprints/types.d.ts +164 -0
- package/dist/screen-blueprints/types.d.ts.map +1 -0
- package/dist/screen-blueprints/types.js +1 -0
- package/dist/stream/stream-parser.d.ts +62 -0
- package/dist/stream/stream-parser.d.ts.map +1 -0
- package/dist/stream/stream-parser.js +199 -0
- package/dist/transport/websocket.d.ts +178 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +1 -0
- package/dist/types/app-config.d.ts +61 -0
- package/dist/types/app-config.d.ts.map +1 -0
- package/dist/types/app-config.js +1 -0
- package/dist/types/auth.d.ts +61 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +1 -0
- package/dist/types/blueprint.d.ts +206 -0
- package/dist/types/blueprint.d.ts.map +1 -0
- package/dist/types/blueprint.js +1 -0
- package/dist/types/canvas-lifecycle.d.ts +105 -0
- package/dist/types/canvas-lifecycle.d.ts.map +1 -0
- package/dist/types/canvas-lifecycle.js +38 -0
- package/dist/types/capabilities.d.ts +40 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +19 -0
- package/dist/types/contract-inference.d.ts +401 -0
- package/dist/types/contract-inference.d.ts.map +1 -0
- package/dist/types/contract-inference.js +44 -0
- package/dist/types/credential.d.ts +41 -0
- package/dist/types/credential.d.ts.map +1 -0
- package/dist/types/credential.js +32 -0
- package/dist/types/data-bindings.d.ts +322 -0
- package/dist/types/data-bindings.d.ts.map +1 -0
- package/dist/types/data-bindings.js +29 -0
- package/dist/types/data-contract.d.ts +1296 -0
- package/dist/types/data-contract.d.ts.map +1 -0
- package/dist/types/data-contract.js +111 -0
- package/dist/types/events.d.ts +182 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +8 -0
- package/dist/types/feedback.d.ts +24 -0
- package/dist/types/feedback.d.ts.map +1 -0
- package/dist/types/feedback.js +7 -0
- package/dist/types/gadget.d.ts +121 -0
- package/dist/types/gadget.d.ts.map +1 -0
- package/dist/types/gadget.js +24 -0
- package/dist/types/handshake-suggestion.d.ts +264 -0
- package/dist/types/handshake-suggestion.d.ts.map +1 -0
- package/dist/types/handshake-suggestion.js +70 -0
- package/dist/types/host-context.d.ts +163 -0
- package/dist/types/host-context.d.ts.map +1 -0
- package/dist/types/host-context.js +142 -0
- package/dist/types/interface-context.d.ts +105 -0
- package/dist/types/interface-context.d.ts.map +1 -0
- package/dist/types/interface-context.js +115 -0
- package/dist/types/invoke.d.ts +28 -0
- package/dist/types/invoke.d.ts.map +1 -0
- package/dist/types/invoke.js +7 -0
- package/dist/types/live-channel.d.ts +613 -0
- package/dist/types/live-channel.d.ts.map +1 -0
- package/dist/types/live-channel.js +1 -0
- package/dist/types/llm.d.ts +61 -0
- package/dist/types/llm.d.ts.map +1 -0
- package/dist/types/llm.js +186 -0
- package/dist/types/mcp-proxy.d.ts +67 -0
- package/dist/types/mcp-proxy.d.ts.map +1 -0
- package/dist/types/mcp-proxy.js +46 -0
- package/dist/types/mcp.d.ts +637 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +30 -0
- package/dist/types/openrouter-models.d.ts +22 -0
- package/dist/types/openrouter-models.d.ts.map +1 -0
- package/dist/types/openrouter-models.js +4843 -0
- package/dist/types/region.d.ts +26 -0
- package/dist/types/region.d.ts.map +1 -0
- package/dist/types/region.js +36 -0
- package/dist/types/session.d.ts +419 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +1 -0
- package/dist/types/thread.d.ts +207 -0
- package/dist/types/thread.d.ts.map +1 -0
- package/dist/types/thread.js +57 -0
- package/dist/types/ui-generator.d.ts +100 -0
- package/dist/types/ui-generator.d.ts.map +1 -0
- package/dist/types/ui-generator.js +53 -0
- package/dist/validation/ajv-runtime.d.ts +140 -0
- package/dist/validation/ajv-runtime.d.ts.map +1 -0
- package/dist/validation/ajv-runtime.js +452 -0
- package/dist/validation/content-hash.d.ts +3 -0
- package/dist/validation/content-hash.d.ts.map +1 -0
- package/dist/validation/content-hash.js +21 -0
- package/dist/validation/contract-validator.d.ts +244 -0
- package/dist/validation/contract-validator.d.ts.map +1 -0
- package/dist/validation/contract-validator.js +711 -0
- package/dist/validation/cross-references.d.ts +105 -0
- package/dist/validation/cross-references.d.ts.map +1 -0
- package/dist/validation/cross-references.js +164 -0
- package/dist/validation/hygiene-rules.d.ts +250 -0
- package/dist/validation/hygiene-rules.d.ts.map +1 -0
- package/dist/validation/hygiene-rules.js +564 -0
- package/dist/validation/lint-contract.d.ts +130 -0
- package/dist/validation/lint-contract.d.ts.map +1 -0
- package/dist/validation/lint-contract.js +225 -0
- package/dist/validation/name-invariants.d.ts +117 -0
- package/dist/validation/name-invariants.d.ts.map +1 -0
- package/dist/validation/name-invariants.js +172 -0
- package/dist/validation/reserved-channels.d.ts +156 -0
- package/dist/validation/reserved-channels.d.ts.map +1 -0
- package/dist/validation/reserved-channels.js +356 -0
- package/dist/validation/resolve-stream-channel.d.ts +78 -0
- package/dist/validation/resolve-stream-channel.d.ts.map +1 -0
- package/dist/validation/resolve-stream-channel.js +64 -0
- package/dist/validation/sanitize-error.d.ts +46 -0
- package/dist/validation/sanitize-error.d.ts.map +1 -0
- package/dist/validation/sanitize-error.js +88 -0
- package/dist/validation/schema-compat-invariants.d.ts +140 -0
- package/dist/validation/schema-compat-invariants.d.ts.map +1 -0
- package/dist/validation/schema-compat-invariants.js +220 -0
- package/dist/validation/schema-meta-validation.d.ts +60 -0
- package/dist/validation/schema-meta-validation.d.ts.map +1 -0
- package/dist/validation/schema-meta-validation.js +131 -0
- package/dist/validation/schema-subset.d.ts +165 -0
- package/dist/validation/schema-subset.d.ts.map +1 -0
- package/dist/validation/schema-subset.js +295 -0
- package/dist/validation/ui-security.d.ts +54 -0
- package/dist/validation/ui-security.d.ts.map +1 -0
- package/dist/validation/ui-security.js +138 -0
- package/dist/validation/zod-to-json-schema.d.ts +63 -0
- package/dist/validation/zod-to-json-schema.d.ts.map +1 -0
- package/dist/validation/zod-to-json-schema.js +126 -0
- package/dist/version.d.ts +1458 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1459 -0
- package/package.json +113 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import type { DataContract, JsonObject, JsonValue } from './data-contract';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the JSON Schema `required` array from a schema literal as a
|
|
4
|
+
* string union. Resolves to `never` when `required` is absent, empty,
|
|
5
|
+
* or non-string-typed.
|
|
6
|
+
*
|
|
7
|
+
* Used by {@link SchemaToType} to split an object's `properties` into
|
|
8
|
+
* required + optional sub-maps. Honors the spec's `required: string[]`
|
|
9
|
+
* array; properties NOT listed are optional.
|
|
10
|
+
*/
|
|
11
|
+
export type RequiredKeysOf<S> = S extends {
|
|
12
|
+
readonly required: readonly (infer R)[];
|
|
13
|
+
} ? R extends string ? R : never : never;
|
|
14
|
+
/**
|
|
15
|
+
* Flatten an intersection of object types into a single object type.
|
|
16
|
+
*
|
|
17
|
+
* Why this exists: the required/optional split in {@link SchemaToType}
|
|
18
|
+
* (and the parallel split in {@link InferProps}) emits an intersection
|
|
19
|
+
* `{ required keys } & { optional keys }`. TypeScript's `Equal` helper
|
|
20
|
+
* (used in our type tests) treats `A & B` and the equivalent flat
|
|
21
|
+
* shape as DIFFERENT types under its `[<T>() => …]` conditional
|
|
22
|
+
* distribution trick, even though they're assignable in both
|
|
23
|
+
* directions. `Prettify` walks every key one level deep and rebuilds
|
|
24
|
+
* a flat shape, so `Equal` resolves correctly.
|
|
25
|
+
*
|
|
26
|
+
* Note: only one level deep — nested object properties keep their
|
|
27
|
+
* own structure (which is fine because nested objects flow back
|
|
28
|
+
* through `SchemaToType` themselves and emerge already-prettified).
|
|
29
|
+
*/
|
|
30
|
+
type Prettify<T> = {
|
|
31
|
+
[K in keyof T]: T[K];
|
|
32
|
+
} & {};
|
|
33
|
+
/**
|
|
34
|
+
* Map a JSON Schema literal type to its corresponding TypeScript type.
|
|
35
|
+
*
|
|
36
|
+
* Works with `as const` literals to preserve exact types:
|
|
37
|
+
* - `{ type: 'string' }` -> `string`
|
|
38
|
+
* - `{ type: 'number' }` -> `number`
|
|
39
|
+
* - `{ type: 'boolean' }` -> `boolean`
|
|
40
|
+
* - `{ type: 'null' }` -> `null`
|
|
41
|
+
* - `{ type: 'array', items: S }` -> `SchemaToType<S>[]`
|
|
42
|
+
* - `{ type: 'object', properties: { k: S }, required: ['k'] }` -> `{ k: SchemaToType<S> }`
|
|
43
|
+
* - `{ type: 'object', properties: { k: S } }` -> `{ k?: SchemaToType<S> }` (no `required` ⇒ all optional, per JSON Schema draft-07)
|
|
44
|
+
* - `{ type: 'object' }` (no properties) -> {@link JsonObject}
|
|
45
|
+
* - `{ enum: ['a', 'b'] }` -> `'a' | 'b'`
|
|
46
|
+
* - `{ const: 42 }` -> `42`
|
|
47
|
+
* - `{ oneOf: [S1, S2] }` -> `SchemaToType<S1> | SchemaToType<S2>`
|
|
48
|
+
*
|
|
49
|
+
* Falls back to `unknown` for non-literal or unrecognized schemas.
|
|
50
|
+
* Objects without explicit `properties` resolve to {@link JsonObject} (not `unknown`).
|
|
51
|
+
*
|
|
52
|
+
* Required-array honor: per JSON Schema draft-07, an object schema's
|
|
53
|
+
* `required` array names the keys that MUST be present; properties NOT
|
|
54
|
+
* listed are optional. The mapping splits `properties` into a required
|
|
55
|
+
* sub-map (keys in `required`) and an
|
|
56
|
+
* optional sub-map (the rest), then intersects them. When `required` is
|
|
57
|
+
* absent or empty, all properties are optional.
|
|
58
|
+
*/
|
|
59
|
+
export type SchemaToType<S> = S extends {
|
|
60
|
+
readonly const: infer V;
|
|
61
|
+
} ? V : S extends {
|
|
62
|
+
readonly enum: readonly (infer E)[];
|
|
63
|
+
} ? E : S extends {
|
|
64
|
+
readonly type: 'string';
|
|
65
|
+
} ? string : S extends {
|
|
66
|
+
readonly type: 'number';
|
|
67
|
+
} ? number : S extends {
|
|
68
|
+
readonly type: 'integer';
|
|
69
|
+
} ? number : S extends {
|
|
70
|
+
readonly type: 'boolean';
|
|
71
|
+
} ? boolean : S extends {
|
|
72
|
+
readonly type: 'null';
|
|
73
|
+
} ? null : S extends {
|
|
74
|
+
readonly type: 'array';
|
|
75
|
+
readonly items: infer I;
|
|
76
|
+
} ? SchemaToType<I>[] : S extends {
|
|
77
|
+
readonly type: 'object';
|
|
78
|
+
readonly properties: infer P;
|
|
79
|
+
} ? Prettify<{
|
|
80
|
+
-readonly [K in keyof P as K extends RequiredKeysOf<S> ? K : never]: SchemaToType<P[K]>;
|
|
81
|
+
} & {
|
|
82
|
+
-readonly [K in keyof P as K extends RequiredKeysOf<S> ? never : K]?: SchemaToType<P[K]>;
|
|
83
|
+
}> : S extends {
|
|
84
|
+
readonly type: 'object';
|
|
85
|
+
} ? JsonObject : S extends {
|
|
86
|
+
readonly oneOf: readonly (infer U)[];
|
|
87
|
+
} ? SchemaToType<U> : S extends {
|
|
88
|
+
readonly anyOf: readonly (infer U)[];
|
|
89
|
+
} ? SchemaToType<U> : unknown;
|
|
90
|
+
/**
|
|
91
|
+
* Infer the TypeScript props type from a `PropsSpec` literal.
|
|
92
|
+
*
|
|
93
|
+
* Given `{ properties: { city: { schema: { type: 'string' }, required: true }, temp: { schema: { type: 'number' } } } }`,
|
|
94
|
+
* infers `{ city: string; temp?: number }`.
|
|
95
|
+
*
|
|
96
|
+
* Falls back to {@link JsonObject} when no props spec is present (untyped usage).
|
|
97
|
+
*
|
|
98
|
+
* Required honor: each {@link PropEntry} carries a per-property
|
|
99
|
+
* `required?: boolean` flag (NOT a `required: string[]` at the props
|
|
100
|
+
* level — that's the JSON Schema convention used elsewhere by
|
|
101
|
+
* {@link SchemaToType}). Entries with `required: true` map to
|
|
102
|
+
* required keys; everything else (`required: false`, `required` omitted,
|
|
103
|
+
* or any non-`true` value) maps to optional `?:` keys. The split uses
|
|
104
|
+
* a key-remap, mirroring the JSON-Schema `required: string[]` handling
|
|
105
|
+
* in {@link SchemaToType}.
|
|
106
|
+
*/
|
|
107
|
+
export type InferProps<T> = T extends {
|
|
108
|
+
readonly propsSpec: {
|
|
109
|
+
readonly properties: infer P;
|
|
110
|
+
};
|
|
111
|
+
} ? Prettify<{
|
|
112
|
+
-readonly [K in keyof P as P[K] extends {
|
|
113
|
+
readonly required: true;
|
|
114
|
+
} ? K : never]: P[K] extends {
|
|
115
|
+
readonly schema: infer S;
|
|
116
|
+
} ? SchemaToType<S> : unknown;
|
|
117
|
+
} & {
|
|
118
|
+
-readonly [K in keyof P as P[K] extends {
|
|
119
|
+
readonly required: true;
|
|
120
|
+
} ? never : K]?: P[K] extends {
|
|
121
|
+
readonly schema: infer S;
|
|
122
|
+
} ? SchemaToType<S> : unknown;
|
|
123
|
+
}> : JsonObject;
|
|
124
|
+
/**
|
|
125
|
+
* Extract action names as a string literal union from a contract.
|
|
126
|
+
*
|
|
127
|
+
* `DataContract.actionSpec` is a flat `Record<actionName, ActionEntry>`;
|
|
128
|
+
* this type matches that shape directly.
|
|
129
|
+
*
|
|
130
|
+
* The fallback (no `actionSpec` key on `T`) resolves to `never`, not
|
|
131
|
+
* `string`. A `string` fallback would silently let generated code
|
|
132
|
+
* pattern-match against arbitrary names when no contract was declared;
|
|
133
|
+
* `never` makes `useAction('nonExistent')` a compile error instead.
|
|
134
|
+
* Consumers that still need a broad name/payload shape (e.g. the
|
|
135
|
+
* server-side untyped-handler default) keep it by going through
|
|
136
|
+
* `TypedAction<T>`, which falls back to `{ name: string; data: JsonValue }`
|
|
137
|
+
* when Names narrows to `never`.
|
|
138
|
+
*/
|
|
139
|
+
export type InferActionNames<T> = T extends {
|
|
140
|
+
readonly actionSpec: infer A;
|
|
141
|
+
} ? Extract<keyof A, string> : never;
|
|
142
|
+
/**
|
|
143
|
+
* Infer the payload type for a specific action.
|
|
144
|
+
* Actions without a `schema` field have `void` payload (fire-and-forget).
|
|
145
|
+
*/
|
|
146
|
+
export type InferActionPayload<T, N extends string> = T extends {
|
|
147
|
+
readonly actionSpec: infer A;
|
|
148
|
+
} ? N extends keyof A ? A[N] extends {
|
|
149
|
+
readonly schema: infer S;
|
|
150
|
+
} ? SchemaToType<S> : void : never : unknown;
|
|
151
|
+
/**
|
|
152
|
+
* Extract stream channel names as a string literal union from a contract.
|
|
153
|
+
*
|
|
154
|
+
* `DataContract.streamSpec` is a flat
|
|
155
|
+
* `Record<channelName, StreamChannelEntry>`; this type matches that
|
|
156
|
+
* shape directly.
|
|
157
|
+
*
|
|
158
|
+
* The fallback (no `streamSpec` key on `T`) resolves to `never`, not
|
|
159
|
+
* `string`. Parallel to `InferActionNames` — `useStream('nonExistent')`
|
|
160
|
+
* becomes a compile error when no contract is declared.
|
|
161
|
+
* `TypedStreamEvent<T>` preserves the broad
|
|
162
|
+
* `{ channel: string; payload: JsonValue; … }` fallback when names
|
|
163
|
+
* narrow to `never`, so untyped-handler defaults still work.
|
|
164
|
+
*/
|
|
165
|
+
export type InferStreamNames<T> = T extends {
|
|
166
|
+
readonly streamSpec: infer C;
|
|
167
|
+
} ? Extract<keyof C, string> : never;
|
|
168
|
+
/** Infer the payload type for a specific stream channel. */
|
|
169
|
+
export type InferStreamPayload<T, N extends string> = T extends {
|
|
170
|
+
readonly streamSpec: infer C;
|
|
171
|
+
} ? N extends keyof C ? C[N] extends {
|
|
172
|
+
readonly schema: infer S;
|
|
173
|
+
} ? SchemaToType<S> : unknown : never : unknown;
|
|
174
|
+
/**
|
|
175
|
+
* Extract contextSpec slot names as a string literal union from a contract.
|
|
176
|
+
*
|
|
177
|
+
* Mirrors {@link InferActionNames} / {@link InferStreamNames}: when the
|
|
178
|
+
* contract declares a `contextSpec` map, returns the keys as a literal
|
|
179
|
+
* union; absent → `never` (so a context-slot lookup for a `'nonExistent'`
|
|
180
|
+
* key against an empty contract is a compile error rather than a silent
|
|
181
|
+
* broad-string fallback).
|
|
182
|
+
*/
|
|
183
|
+
export type InferContextNames<T> = T extends {
|
|
184
|
+
readonly contextSpec: infer S;
|
|
185
|
+
} ? Extract<keyof S, string> : never;
|
|
186
|
+
/**
|
|
187
|
+
* Infer the value type for a specific contextSpec slot, narrowed by
|
|
188
|
+
* its declared `schema`. Mirrors {@link InferActionPayload} /
|
|
189
|
+
* {@link InferStreamPayload}.
|
|
190
|
+
*
|
|
191
|
+
* - Present `contextSpec` + known slot name → `SchemaToType<schema>`.
|
|
192
|
+
* - Present `contextSpec` + unknown slot name → `never`.
|
|
193
|
+
* - Absent `contextSpec` entirely → `unknown` (parallel to the
|
|
194
|
+
* payload-fallback posture on actionSpec / streamSpec).
|
|
195
|
+
*/
|
|
196
|
+
export type InferContextValue<T, N extends string> = T extends {
|
|
197
|
+
readonly contextSpec: infer S;
|
|
198
|
+
} ? N extends keyof S ? S[N] extends {
|
|
199
|
+
readonly schema: infer Sch;
|
|
200
|
+
} ? SchemaToType<Sch> : unknown : never : unknown;
|
|
201
|
+
/**
|
|
202
|
+
* Extract agent-tool names as a string literal union. Used by the
|
|
203
|
+
* generator's `AllWires<T>` completeness manifest to enumerate the
|
|
204
|
+
* catalog at type-time.
|
|
205
|
+
*
|
|
206
|
+
* The catalog is invoked by the AGENT, not the component — there is no
|
|
207
|
+
* payload-type inference for component callers because the component
|
|
208
|
+
* never calls these tools. The catalog is referenced from
|
|
209
|
+
* `actionSpec[*].nextStep` and `streamSpec[*].source.tool`.
|
|
210
|
+
*/
|
|
211
|
+
export type InferAgentToolNames<T> = T extends {
|
|
212
|
+
readonly agentCapabilities: {
|
|
213
|
+
readonly tools: infer Tools;
|
|
214
|
+
};
|
|
215
|
+
} ? Extract<keyof Tools, string> : string;
|
|
216
|
+
/**
|
|
217
|
+
* Extract gadget EXPORT names as a string literal union — the union
|
|
218
|
+
* of every export name across every package the contract declares on
|
|
219
|
+
* `clientCapabilities.gadgets` (which is package-keyed:
|
|
220
|
+
* `Record<package, Record<exportName, GadgetExportUse>>` — there is no
|
|
221
|
+
* `exports` wrapper; a package entry IS its export map).
|
|
222
|
+
*
|
|
223
|
+
* Gadgets are declarations, not RPC, so they have no input/output
|
|
224
|
+
* schemas to narrow against. The value type for a declared gadget is
|
|
225
|
+
* consumed via the runtime hook / rendered component (e.g.,
|
|
226
|
+
* `useMicrophone()` returns `GadgetHook<TOutput>`), not via a
|
|
227
|
+
* contract-level type query — so the export NAME is the unit the
|
|
228
|
+
* completeness manifest enumerates.
|
|
229
|
+
*/
|
|
230
|
+
export type InferGadgetNames<T> = T extends {
|
|
231
|
+
readonly clientCapabilities: {
|
|
232
|
+
readonly gadgets: infer Pkgs;
|
|
233
|
+
};
|
|
234
|
+
} ? {
|
|
235
|
+
[K in keyof Pkgs]: Extract<keyof Pkgs[K], string>;
|
|
236
|
+
}[keyof Pkgs] : string;
|
|
237
|
+
/**
|
|
238
|
+
* Discriminated union of all stream emissions in a contract.
|
|
239
|
+
*
|
|
240
|
+
* Each member has `{ channel: ChannelName; payload: PayloadType; complete?: boolean; stackItemId?: string }`
|
|
241
|
+
* — the agent-supplied fields of {@link GguiEmitInput} minus `sessionId`
|
|
242
|
+
* (which is caller context, not per-delivery).
|
|
243
|
+
*
|
|
244
|
+
* `mode` / `seq` / transport details are intentionally NOT on this union:
|
|
245
|
+
* `mode` is derived from `streamSpec[channel].mode` server-side,
|
|
246
|
+
* and `seq` is server-assigned via `SessionStreamBuffer`. Producers that
|
|
247
|
+
* try to set either are drifting against the streamSpec design lock.
|
|
248
|
+
*
|
|
249
|
+
* Falls back to `{ channel: string; payload: JsonValue; complete?: boolean; stackItemId?: string }`
|
|
250
|
+
* when the contract has no `streamSpec` declared.
|
|
251
|
+
*/
|
|
252
|
+
export type TypedStreamEvent<T> = [
|
|
253
|
+
InferStreamNames<T>
|
|
254
|
+
] extends [never] ? {
|
|
255
|
+
channel: string;
|
|
256
|
+
payload: JsonValue;
|
|
257
|
+
complete?: boolean;
|
|
258
|
+
stackItemId?: string;
|
|
259
|
+
} : InferStreamNames<T> extends infer Names extends string ? {
|
|
260
|
+
[N in Names]: {
|
|
261
|
+
channel: N;
|
|
262
|
+
payload: InferStreamPayload<T, N>;
|
|
263
|
+
complete?: boolean;
|
|
264
|
+
stackItemId?: string;
|
|
265
|
+
};
|
|
266
|
+
}[Names] : {
|
|
267
|
+
channel: string;
|
|
268
|
+
payload: JsonValue;
|
|
269
|
+
complete?: boolean;
|
|
270
|
+
stackItemId?: string;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Discriminated union of all action events in a contract.
|
|
274
|
+
* Each member has `{ name: ActionName; data: PayloadType }`.
|
|
275
|
+
*
|
|
276
|
+
* Falls back to `{ name: string; data: JsonValue }` when no action spec is present.
|
|
277
|
+
*/
|
|
278
|
+
export type TypedAction<T> = [
|
|
279
|
+
InferActionNames<T>
|
|
280
|
+
] extends [never] ? {
|
|
281
|
+
name: string;
|
|
282
|
+
data: JsonValue;
|
|
283
|
+
} : InferActionNames<T> extends infer Names extends string ? {
|
|
284
|
+
[N in Names]: {
|
|
285
|
+
name: N;
|
|
286
|
+
data: InferActionPayload<T, N>;
|
|
287
|
+
};
|
|
288
|
+
}[Names] : {
|
|
289
|
+
name: string;
|
|
290
|
+
data: JsonValue;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Define a data contract with full type inference.
|
|
294
|
+
*
|
|
295
|
+
* The `const` type parameter preserves literal types from `as const`,
|
|
296
|
+
* enabling automatic TypeScript type inference from JSON Schema definitions.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const contract = defineContract({
|
|
301
|
+
* intent: 'Show weather for a city with refresh control',
|
|
302
|
+
* props: { properties: {
|
|
303
|
+
* city: { schema: { type: 'string' } },
|
|
304
|
+
* temp: { schema: { type: 'number' } },
|
|
305
|
+
* }},
|
|
306
|
+
* actionSpec: {
|
|
307
|
+
* refresh: { label: 'Refresh' },
|
|
308
|
+
* changeUnit: { label: 'Unit', schema: { type: 'object', properties: { unit: { type: 'string' } } } },
|
|
309
|
+
* },
|
|
310
|
+
* streamSpec: {
|
|
311
|
+
* weatherUpdate: { schema: { type: 'object', properties: { temp: { type: 'number' }, conditions: { type: 'string' } } } },
|
|
312
|
+
* },
|
|
313
|
+
* } as const);
|
|
314
|
+
*
|
|
315
|
+
* // TypeScript infers:
|
|
316
|
+
* // InferProps<typeof contract> = { city: string; temp: number }
|
|
317
|
+
* // InferActionNames<typeof contract> = 'refresh' | 'changeUnit'
|
|
318
|
+
* // InferActionPayload<typeof contract, 'changeUnit'> = { unit: string }
|
|
319
|
+
* // InferStreamPayload<typeof contract, 'weatherUpdate'> = { temp: number; conditions: string }
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export declare function defineContract<const T extends DataContract>(contract: T): T;
|
|
323
|
+
/**
|
|
324
|
+
* Manual type map for cases where `SchemaToType` can't infer
|
|
325
|
+
* (complex unions, conditional schemas, branded types, etc.).
|
|
326
|
+
*
|
|
327
|
+
* Both paths (auto-inferred via `defineContract` and manual via `ContractTypeMap`)
|
|
328
|
+
* work with `useContract`, typed handlers, and typed MCP client methods.
|
|
329
|
+
*
|
|
330
|
+
* All map slots default to {@link JsonObject} (props, actions, streams) or
|
|
331
|
+
* `Record<string, { request/args: JsonValue; response: JsonValue }>` (tools)
|
|
332
|
+
* when not overridden.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* interface MyContract extends ContractTypeMap {
|
|
337
|
+
* props: { city: string; temperature: number };
|
|
338
|
+
* actions: { refresh: void; changeUnit: { unit: 'C' | 'F' } };
|
|
339
|
+
* streams: { weatherUpdate: { temp: number; conditions: string } };
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
export interface ContractTypeMap {
|
|
344
|
+
props?: JsonObject;
|
|
345
|
+
actions?: JsonObject;
|
|
346
|
+
streams?: JsonObject;
|
|
347
|
+
agentCapabilities?: Record<string, {
|
|
348
|
+
input: JsonValue;
|
|
349
|
+
output: JsonValue;
|
|
350
|
+
}>;
|
|
351
|
+
/**
|
|
352
|
+
* Per-gadget binding-name set. Values are intentionally typed
|
|
353
|
+
* `unknown` — gadget hooks own their own typed `value` / `start()`
|
|
354
|
+
* shape (see `GadgetHook` in `./gadget.ts`), which
|
|
355
|
+
* is not derivable from a contract-level type query.
|
|
356
|
+
*/
|
|
357
|
+
clientCapabilities?: Record<string, unknown>;
|
|
358
|
+
}
|
|
359
|
+
/** Extract props from a manual ContractTypeMap. */
|
|
360
|
+
export type PropsOf<C extends ContractTypeMap> = C extends {
|
|
361
|
+
props: infer P;
|
|
362
|
+
} ? P : JsonObject;
|
|
363
|
+
/** Extract action names from a manual ContractTypeMap. */
|
|
364
|
+
export type ActionNames<C extends ContractTypeMap> = C extends {
|
|
365
|
+
actions: infer A;
|
|
366
|
+
} ? Extract<keyof A, string> : string;
|
|
367
|
+
/** Extract action payload from a manual ContractTypeMap. */
|
|
368
|
+
export type ActionPayload<C extends ContractTypeMap, N extends ActionNames<C>> = C extends {
|
|
369
|
+
actions: infer A;
|
|
370
|
+
} ? N extends keyof A ? A[N] : unknown : unknown;
|
|
371
|
+
/** Extract stream event names from a manual ContractTypeMap. */
|
|
372
|
+
export type StreamNames<C extends ContractTypeMap> = C extends {
|
|
373
|
+
streams: infer S;
|
|
374
|
+
} ? Extract<keyof S, string> : string;
|
|
375
|
+
/** Extract stream payload from a manual ContractTypeMap. */
|
|
376
|
+
export type StreamPayloadOf<C extends ContractTypeMap, N extends StreamNames<C>> = C extends {
|
|
377
|
+
streams: infer S;
|
|
378
|
+
} ? N extends keyof S ? S[N] : unknown : unknown;
|
|
379
|
+
/**
|
|
380
|
+
* Extract agent-tool names from a manual ContractTypeMap. Used by the
|
|
381
|
+
* generator's `AllWires<T>` completeness manifest to enumerate the
|
|
382
|
+
* catalog at type-time.
|
|
383
|
+
*
|
|
384
|
+
* The catalog is invoked by the AGENT, never a component-side hook
|
|
385
|
+
* surface, so there is no payload-type inference for component callers.
|
|
386
|
+
*/
|
|
387
|
+
export type AgentToolNames<C extends ContractTypeMap> = C extends {
|
|
388
|
+
agentCapabilities: infer T;
|
|
389
|
+
} ? Extract<keyof T, string> : string;
|
|
390
|
+
/**
|
|
391
|
+
* Extract gadget binding names from a manual ContractTypeMap.
|
|
392
|
+
*
|
|
393
|
+
* Libraries are declarations, not RPC, so there is no payload-type
|
|
394
|
+
* inference. Value types are consumed via the runtime hook
|
|
395
|
+
* (`GadgetHook<TOutput>`), not via a contract-level query.
|
|
396
|
+
*/
|
|
397
|
+
export type GadgetNames<C extends ContractTypeMap> = C extends {
|
|
398
|
+
clientCapabilities: infer T;
|
|
399
|
+
} ? Extract<keyof T, string> : string;
|
|
400
|
+
export {};
|
|
401
|
+
//# sourceMappingURL=contract-inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-inference.d.ts","sourceRoot":"","sources":["../../src/types/contract-inference.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM3E;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B,CAAC,SAAS;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAA;CAAE,GACjD,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,GAC5B,KAAK,CAAC;AAEZ;;;;;;;;;;;;;;;GAeG;AACH,KAAK,QAAQ,CAAC,CAAC,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M,eAAe,CAAC,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,IAC7E,CAAC,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC,CAAA;CAAE,GAC1B,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAClC,OAAO,CAAC;AAEd;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,eAAe,IAClD,CAAC,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,eAAe,IAC/C,CAAC,SAAS;IAAE,kBAAkB,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// packages/protocol/src/types/contract-inference.ts
|
|
2
|
+
//
|
|
3
|
+
// Compile-time type inference from JSON Schema contract literals.
|
|
4
|
+
//
|
|
5
|
+
// Agents write a single `defineContract({ ... } as const)` call.
|
|
6
|
+
// TypeScript infers all prop types, action names/payloads, stream events,
|
|
7
|
+
// and tool signatures automatically from the JSON Schema literal — no
|
|
8
|
+
// parallel type definitions needed.
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// defineContract — zero-cost identity that locks literal types
|
|
11
|
+
// =============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Define a data contract with full type inference.
|
|
14
|
+
*
|
|
15
|
+
* The `const` type parameter preserves literal types from `as const`,
|
|
16
|
+
* enabling automatic TypeScript type inference from JSON Schema definitions.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const contract = defineContract({
|
|
21
|
+
* intent: 'Show weather for a city with refresh control',
|
|
22
|
+
* props: { properties: {
|
|
23
|
+
* city: { schema: { type: 'string' } },
|
|
24
|
+
* temp: { schema: { type: 'number' } },
|
|
25
|
+
* }},
|
|
26
|
+
* actionSpec: {
|
|
27
|
+
* refresh: { label: 'Refresh' },
|
|
28
|
+
* changeUnit: { label: 'Unit', schema: { type: 'object', properties: { unit: { type: 'string' } } } },
|
|
29
|
+
* },
|
|
30
|
+
* streamSpec: {
|
|
31
|
+
* weatherUpdate: { schema: { type: 'object', properties: { temp: { type: 'number' }, conditions: { type: 'string' } } } },
|
|
32
|
+
* },
|
|
33
|
+
* } as const);
|
|
34
|
+
*
|
|
35
|
+
* // TypeScript infers:
|
|
36
|
+
* // InferProps<typeof contract> = { city: string; temp: number }
|
|
37
|
+
* // InferActionNames<typeof contract> = 'refresh' | 'changeUnit'
|
|
38
|
+
* // InferActionPayload<typeof contract, 'changeUnit'> = { unit: string }
|
|
39
|
+
* // InferStreamPayload<typeof contract, 'weatherUpdate'> = { temp: number; conditions: string }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function defineContract(contract) {
|
|
43
|
+
return contract;
|
|
44
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential injection — cross-process wire protocol between the
|
|
3
|
+
* open @ggui-ai/server auth relay (which writes placeholders) and
|
|
4
|
+
* the closed cloud mcp-proxy service (which resolves them).
|
|
5
|
+
*
|
|
6
|
+
* Shared between:
|
|
7
|
+
* - packages/server/src/mcp-auth-middleware.ts (writes placeholders)
|
|
8
|
+
* - cloud/amplify/functions/rest-api/mcp-proxy/handler.ts (resolves placeholders)
|
|
9
|
+
* - cloud/services/mcp-proxy/src/* (resolves placeholders)
|
|
10
|
+
*
|
|
11
|
+
* Hosted-overlay shapes for the `auth` block inside per-app
|
|
12
|
+
* config files are a hosting concept and not a portable wire
|
|
13
|
+
* protocol. What remains here is the runtime placeholder /
|
|
14
|
+
* injection-mode protocol, which is legitimately cross-process.
|
|
15
|
+
*/
|
|
16
|
+
/** How the proxy injects a credential into the outbound request. */
|
|
17
|
+
export type CredentialInjection = 'bearer_header' | 'api_key_header' | 'query_param' | 'custom_header';
|
|
18
|
+
/** Full injection config — resolved from app config or McpServiceConfig. */
|
|
19
|
+
export interface CredentialInjectionConfig {
|
|
20
|
+
mode: CredentialInjection;
|
|
21
|
+
/** Header name for api_key_header / custom_header. Default: 'X-API-Key'. */
|
|
22
|
+
headerName?: string;
|
|
23
|
+
/** Query param name for query_param. Default: 'api_key'. */
|
|
24
|
+
paramName?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Placeholder regex — matches `<ggui:credential:{serviceId}>`.
|
|
28
|
+
* The placeholder is always the raw credential slot value.
|
|
29
|
+
* The proxy applies injection formatting (Bearer prefix, header name, etc.).
|
|
30
|
+
*/
|
|
31
|
+
export declare const CREDENTIAL_PLACEHOLDER_RE: RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* Internal control header for placeholder pre-injection.
|
|
34
|
+
* - Writer: auth relay middleware only
|
|
35
|
+
* - Consumer: proxy only (reads, resolves, strips before forwarding)
|
|
36
|
+
* - Never forwarded upstream
|
|
37
|
+
*/
|
|
38
|
+
export declare const CREDENTIAL_HEADER = "x-ggui-credential";
|
|
39
|
+
/** Build a placeholder string for a given serviceId. */
|
|
40
|
+
export declare function credentialPlaceholder(serviceId: string): string;
|
|
41
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../../src/types/credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAC3B,eAAe,GACf,gBAAgB,GAChB,aAAa,GACb,eAAe,CAAC;AAEpB,4EAA4E;AAC5E,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAyC,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,wDAAwD;AACxD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential injection — cross-process wire protocol between the
|
|
3
|
+
* open @ggui-ai/server auth relay (which writes placeholders) and
|
|
4
|
+
* the closed cloud mcp-proxy service (which resolves them).
|
|
5
|
+
*
|
|
6
|
+
* Shared between:
|
|
7
|
+
* - packages/server/src/mcp-auth-middleware.ts (writes placeholders)
|
|
8
|
+
* - cloud/amplify/functions/rest-api/mcp-proxy/handler.ts (resolves placeholders)
|
|
9
|
+
* - cloud/services/mcp-proxy/src/* (resolves placeholders)
|
|
10
|
+
*
|
|
11
|
+
* Hosted-overlay shapes for the `auth` block inside per-app
|
|
12
|
+
* config files are a hosting concept and not a portable wire
|
|
13
|
+
* protocol. What remains here is the runtime placeholder /
|
|
14
|
+
* injection-mode protocol, which is legitimately cross-process.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Placeholder regex — matches `<ggui:credential:{serviceId}>`.
|
|
18
|
+
* The placeholder is always the raw credential slot value.
|
|
19
|
+
* The proxy applies injection formatting (Bearer prefix, header name, etc.).
|
|
20
|
+
*/
|
|
21
|
+
export const CREDENTIAL_PLACEHOLDER_RE = /^<ggui:credential:([a-zA-Z0-9_-]+)>$/;
|
|
22
|
+
/**
|
|
23
|
+
* Internal control header for placeholder pre-injection.
|
|
24
|
+
* - Writer: auth relay middleware only
|
|
25
|
+
* - Consumer: proxy only (reads, resolves, strips before forwarding)
|
|
26
|
+
* - Never forwarded upstream
|
|
27
|
+
*/
|
|
28
|
+
export const CREDENTIAL_HEADER = 'x-ggui-credential';
|
|
29
|
+
/** Build a placeholder string for a given serviceId. */
|
|
30
|
+
export function credentialPlaceholder(serviceId) {
|
|
31
|
+
return `<ggui:credential:${serviceId}>`;
|
|
32
|
+
}
|