@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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Loqu, Inc. (Guuey)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @ggui-ai/protocol
|
|
2
|
+
|
|
3
|
+
TypeScript source of truth for the ggui protocol — the open wire format between agents and generated user interfaces. Ships the envelope types (`ActionEnvelope`, `StreamEnvelope`, `ContractErrorPayload`), the canonical error-code union, the WebSocket + MCP transport bindings, and the DTCG design-token contract.
|
|
4
|
+
|
|
5
|
+
The full normative spec lives at [docs.ggui.ai](https://docs.ggui.ai). This package is what an implementer actually imports.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ggui-ai/protocol
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How the protocol works
|
|
12
|
+
|
|
13
|
+
An agent declares a contract. A user clicks a button. The right MCP tool runs. No SDK glue.
|
|
14
|
+
|
|
15
|
+
Here is what happens when a user clicks "Add" on a generated todo UI:
|
|
16
|
+
|
|
17
|
+
1. **LLM wrote the hook** — `const addTodo = useAction('addTodo');` bound to the button's `onClick`.
|
|
18
|
+
2. **User clicks** — React fires `onClick`, which calls `addTodo(data)`.
|
|
19
|
+
3. **Hook dispatches** — `useAction` (from `@ggui-ai/wire`) sends an `ActionEnvelope` on the live channel.
|
|
20
|
+
4. **WS transport** — the server receives the envelope on the session's live-channel WebSocket.
|
|
21
|
+
5. **Router looks up the tool** — `wiredActionRouter` reads `actionSpec.addTodo.nextStep === 'todo.add'`.
|
|
22
|
+
6. **MCP tool invoked** — the router calls `todo.add` with the validated payload.
|
|
23
|
+
7. **Tool responds** — `todo.add` returns; the response travels back as a `StreamEnvelope` on the live channel.
|
|
24
|
+
8. **UI absorbs the update** — the component's `useStream` callback fires, state updates, no regeneration.
|
|
25
|
+
|
|
26
|
+
**No SDK glue.** Every step has a named, typed enforcement layer — schema-subset check at push time, `ContractErrorPayload` on `_ggui:contract-error` at runtime, `@ggui-ai/protocol-conformance` at CI time, TypeScript narrowing at author time. Nothing about this pipeline assumes a specific SDK: a third-party implementer honoring the envelope + channel contracts inherits all four enforcement tiers for free.
|
|
27
|
+
|
|
28
|
+
## Implementer guide
|
|
29
|
+
|
|
30
|
+
Building a third-party MCP host that renders ggui sessions, a non-React viewer, or any runtime that speaks the ggui wire contract? The implementer guide at [docs.ggui.ai](https://docs.ggui.ai) covers the three-way quickstart (React via `<McpAppIframe>` / vanilla iframe + postMessage / MCP-host install), the full `ProtocolError` recipe with suggested UX per variant, `ObservabilityEvent` kinds, and version negotiation.
|
|
31
|
+
|
|
32
|
+
## What this package exports
|
|
33
|
+
|
|
34
|
+
| Surface | What it is |
|
|
35
|
+
| ------------------------------------------- | ---------------------------------------------------------------- |
|
|
36
|
+
| `@ggui-ai/protocol` | Root barrel — envelope types, `StackItem`, `StreamSpec`, actions |
|
|
37
|
+
| `@ggui-ai/protocol/content-hash` | Deterministic hashing for cache keys |
|
|
38
|
+
| `@ggui-ai/protocol/blueprint-key` | Server-only blueprint cache-key derivation (uses `node:crypto`) |
|
|
39
|
+
| `@ggui-ai/protocol/transport/websocket` | Live-channel WS binding — subscribe / ack / resume types |
|
|
40
|
+
| `@ggui-ai/protocol/integrations/mcp-apps` | MCP Apps host integration types — bootstrap + lifecycle protocol |
|
|
41
|
+
| `@ggui-ai/protocol/version` | Protocol version constant + negotiation helpers |
|
|
42
|
+
| `@ggui-ai/protocol/errors/version-mismatch` | Typed error for version-negotiation failures |
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
Apache-2.0.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent invocation helper for the bridge agent pattern.
|
|
3
|
+
*
|
|
4
|
+
* Cloud-provider agnostic — uses standard fetch API. Can be used by any
|
|
5
|
+
* platform implementation (serverless function, self-hosted server, etc.) that needs
|
|
6
|
+
* to forward messages to an agent's HTTP endpoint.
|
|
7
|
+
*
|
|
8
|
+
* Handles both JSON and SSE streaming responses using stream-parser.
|
|
9
|
+
*/
|
|
10
|
+
import type { InterfaceContext } from '../types/interface-context';
|
|
11
|
+
import type { ConversationTurn } from '../types/session';
|
|
12
|
+
export interface InvokeAgentOptions {
|
|
13
|
+
/** The agent's HTTP endpoint URL */
|
|
14
|
+
connectorEndpointUrl: string;
|
|
15
|
+
/** Session ID (omit for 'start' flow — agent creates session) */
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
/** Invocation type: 'start' creates a new session, 'message' continues one */
|
|
18
|
+
type: 'start' | 'message';
|
|
19
|
+
/** User message text */
|
|
20
|
+
message?: string;
|
|
21
|
+
/** App ID to include in the request */
|
|
22
|
+
appId: string;
|
|
23
|
+
/** Client interface context (device, viewport, shell type) */
|
|
24
|
+
interfaceContext?: InterfaceContext;
|
|
25
|
+
/** Conversation history for multi-turn context */
|
|
26
|
+
conversationHistory?: ConversationTurn[];
|
|
27
|
+
/** Callback to forward streaming text chunks to the user */
|
|
28
|
+
onStreamChunk?: (text: string) => Promise<void>;
|
|
29
|
+
/** Callback when the stream is done */
|
|
30
|
+
onStreamDone?: () => Promise<void>;
|
|
31
|
+
/** Callback when the agent returns a sessionId (start flow, SSE) */
|
|
32
|
+
onSessionId?: (sessionId: string) => Promise<void>;
|
|
33
|
+
/** Callback for structured agent events (stream, push, etc.) from the events array */
|
|
34
|
+
onAgentEvent?: (event: {
|
|
35
|
+
type: string;
|
|
36
|
+
payload: unknown;
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
/** Request timeout in milliseconds (default: 90000) */
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface InvokeAgentResult {
|
|
42
|
+
/** Session ID returned by the agent (start flow) */
|
|
43
|
+
sessionId?: string;
|
|
44
|
+
/** Full text response (JSON responses only — streaming uses callbacks) */
|
|
45
|
+
text?: string;
|
|
46
|
+
/** Whether the response was streamed via SSE */
|
|
47
|
+
streamed: boolean;
|
|
48
|
+
/** Outcome status */
|
|
49
|
+
status: 'ok' | 'error';
|
|
50
|
+
/** Error message if status is 'error' */
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Invoke an agent's HTTP endpoint and handle the response.
|
|
55
|
+
*
|
|
56
|
+
* Supports two response formats:
|
|
57
|
+
* 1. JSON — returns the parsed body as InvokeAgentResult
|
|
58
|
+
* 2. SSE stream — forwards chunks via callbacks, returns when stream ends
|
|
59
|
+
*
|
|
60
|
+
* The request body shape follows the ggui bridge protocol:
|
|
61
|
+
* - start: { type: 'start', message, appId, interfaceContext }
|
|
62
|
+
* - message: { type: 'message', sessionId, appId, message, conversationHistory, interfaceContext }
|
|
63
|
+
*/
|
|
64
|
+
export declare function invokeAgentEndpoint(options: InvokeAgentOptions): Promise<InvokeAgentResult>;
|
|
65
|
+
//# sourceMappingURL=invoke-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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CAAC;IACd,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB;IACrB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CA4G5B"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isStreamingContentType } from '../stream/stream-parser.js';
|
|
3
|
+
/** Schema for agent HTTP response data — validates untrusted external input. */
|
|
4
|
+
const agentResponseSchema = z.object({
|
|
5
|
+
sessionId: z.string().optional(),
|
|
6
|
+
text: z.string().optional(),
|
|
7
|
+
events: z.array(z.object({
|
|
8
|
+
type: z.string(),
|
|
9
|
+
payload: z.unknown(),
|
|
10
|
+
}).passthrough()).optional(),
|
|
11
|
+
}).passthrough();
|
|
12
|
+
// ── Implementation ──
|
|
13
|
+
/**
|
|
14
|
+
* Invoke an agent's HTTP endpoint and handle the response.
|
|
15
|
+
*
|
|
16
|
+
* Supports two response formats:
|
|
17
|
+
* 1. JSON — returns the parsed body as InvokeAgentResult
|
|
18
|
+
* 2. SSE stream — forwards chunks via callbacks, returns when stream ends
|
|
19
|
+
*
|
|
20
|
+
* The request body shape follows the ggui bridge protocol:
|
|
21
|
+
* - start: { type: 'start', message, appId, interfaceContext }
|
|
22
|
+
* - message: { type: 'message', sessionId, appId, message, conversationHistory, interfaceContext }
|
|
23
|
+
*/
|
|
24
|
+
export async function invokeAgentEndpoint(options) {
|
|
25
|
+
const { connectorEndpointUrl, type, appId, sessionId, message, interfaceContext, conversationHistory, onStreamChunk, onStreamDone, onSessionId, timeoutMs = 90_000, } = options;
|
|
26
|
+
// Build request body based on invocation type
|
|
27
|
+
const body = { type, appId };
|
|
28
|
+
if (type === 'start') {
|
|
29
|
+
if (sessionId)
|
|
30
|
+
body.sessionId = sessionId;
|
|
31
|
+
body.message = message || 'Start a new session';
|
|
32
|
+
if (interfaceContext)
|
|
33
|
+
body.interfaceContext = interfaceContext;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
body.sessionId = sessionId;
|
|
37
|
+
body.message = message;
|
|
38
|
+
if (interfaceContext)
|
|
39
|
+
body.interfaceContext = interfaceContext;
|
|
40
|
+
if (conversationHistory && conversationHistory.length > 0) {
|
|
41
|
+
body.conversationHistory = conversationHistory;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Build headers
|
|
45
|
+
const headers = {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
'X-Ggui-App-Id': appId,
|
|
48
|
+
};
|
|
49
|
+
if (sessionId) {
|
|
50
|
+
headers['X-Ggui-Session-Id'] = sessionId;
|
|
51
|
+
}
|
|
52
|
+
// POST to agent endpoint
|
|
53
|
+
let response;
|
|
54
|
+
try {
|
|
55
|
+
response = await fetch(connectorEndpointUrl, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers,
|
|
58
|
+
body: JSON.stringify(body),
|
|
59
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const errMsg = err instanceof Error ? err.message : 'Agent invocation failed';
|
|
64
|
+
return { status: 'error', error: errMsg, streamed: false };
|
|
65
|
+
}
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
return {
|
|
68
|
+
status: 'error',
|
|
69
|
+
error: `Agent returned ${response.status}`,
|
|
70
|
+
streamed: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Determine response format
|
|
74
|
+
const contentType = response.headers.get('content-type') || '';
|
|
75
|
+
const transferEncoding = response.headers.get('transfer-encoding') || '';
|
|
76
|
+
// Read the full response body (SSE or JSON)
|
|
77
|
+
const responseText = await response.text();
|
|
78
|
+
// Parse the response — handle SSE format (strip `data: ` prefix)
|
|
79
|
+
let agentData;
|
|
80
|
+
try {
|
|
81
|
+
// SSE responses have `data: {...}` lines
|
|
82
|
+
const lines = responseText.split('\n').filter(l => l.startsWith('data: '));
|
|
83
|
+
const raw = lines.length > 0
|
|
84
|
+
? JSON.parse(lines[lines.length - 1].slice(6).trim())
|
|
85
|
+
: JSON.parse(responseText);
|
|
86
|
+
agentData = agentResponseSchema.parse(raw);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Couldn't parse or validate — forward raw text
|
|
90
|
+
await onStreamChunk?.(responseText);
|
|
91
|
+
await onStreamDone?.();
|
|
92
|
+
return { status: 'ok', streamed: true };
|
|
93
|
+
}
|
|
94
|
+
// Extract sessionId
|
|
95
|
+
if (agentData.sessionId) {
|
|
96
|
+
await onSessionId?.(agentData.sessionId);
|
|
97
|
+
}
|
|
98
|
+
// Forward structured agent events
|
|
99
|
+
if (agentData.events && options.onAgentEvent) {
|
|
100
|
+
for (const event of agentData.events) {
|
|
101
|
+
await options.onAgentEvent(event);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Extract text for conversation history
|
|
105
|
+
const resultText = agentData.text;
|
|
106
|
+
await onStreamDone?.();
|
|
107
|
+
return {
|
|
108
|
+
sessionId: agentData.sessionId,
|
|
109
|
+
text: resultText,
|
|
110
|
+
status: 'ok',
|
|
111
|
+
streamed: isStreamingContentType(contentType, transferEncoding),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope adapters — storage-side helpers for the consume pipe.
|
|
3
|
+
*
|
|
4
|
+
* `PendingEvent.envelope` carries the per-gesture {@link ConsumeEventEntry}
|
|
5
|
+
* row written by `submit_action`'s `kind:"dispatch"` branch. Storage is
|
|
6
|
+
* single-shaped (the same shape `ggui_consume` returns verbatim on drain).
|
|
7
|
+
*
|
|
8
|
+
* The only bounded adapter that lives here now is
|
|
9
|
+
* {@link parsePendingEnvelope} — a shape-neutral reader for stored
|
|
10
|
+
* `PendingEvent.envelope` values that may arrive as raw objects (direct
|
|
11
|
+
* DDB writes) or as JSON strings (AppSync `a.json()` semantics).
|
|
12
|
+
*/
|
|
13
|
+
import type { ConsumeEventEntry } from './types/mcp';
|
|
14
|
+
/**
|
|
15
|
+
* Parse a {@link PendingEvent.envelope} that may arrive as either a raw
|
|
16
|
+
* object (direct DDB writes) or a JSON-stringified object (AppSync
|
|
17
|
+
* `a.json()` semantics). Returns the parsed entry unchanged when
|
|
18
|
+
* already an object.
|
|
19
|
+
*
|
|
20
|
+
* Throws `SyntaxError` when a string input is malformed JSON. Does NOT
|
|
21
|
+
* validate the entry shape — that's the caller's job.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parsePendingEnvelope(stored: ConsumeEventEntry | string): ConsumeEventEntry;
|
|
24
|
+
//# sourceMappingURL=envelope-adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope-adapters.d.ts","sourceRoot":"","sources":["../src/envelope-adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,MAAM,GACjC,iBAAiB,CAGnB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a {@link PendingEvent.envelope} that may arrive as either a raw
|
|
3
|
+
* object (direct DDB writes) or a JSON-stringified object (AppSync
|
|
4
|
+
* `a.json()` semantics). Returns the parsed entry unchanged when
|
|
5
|
+
* already an object.
|
|
6
|
+
*
|
|
7
|
+
* Throws `SyntaxError` when a string input is malformed JSON. Does NOT
|
|
8
|
+
* validate the entry shape — that's the caller's job.
|
|
9
|
+
*/
|
|
10
|
+
export function parsePendingEnvelope(stored) {
|
|
11
|
+
if (typeof stored !== 'string')
|
|
12
|
+
return stored;
|
|
13
|
+
return JSON.parse(stored);
|
|
14
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central envelope builders — single stamp point for `schemaVersion`
|
|
3
|
+
* across every producer path.
|
|
4
|
+
*
|
|
5
|
+
* **Why centralize.** The `schemaVersion` forward-compat stamp is
|
|
6
|
+
* emitted from many producer sites (wire helper, React-SDK emit
|
|
7
|
+
* paths, OSS in-memory stream buffer, session-channel contract-error
|
|
8
|
+
* router, hosted server paths). Spreading stamp logic across N sites
|
|
9
|
+
* causes drift — producers silently skip the stamp. These builders
|
|
10
|
+
* remove the drift surface by giving every producer a single function
|
|
11
|
+
* to call; the default stamp happens inside the builder.
|
|
12
|
+
*
|
|
13
|
+
* **Override semantics.** Each builder accepts `schemaVersion` in the
|
|
14
|
+
* input object:
|
|
15
|
+
*
|
|
16
|
+
* - **Key omitted** → the builder stamps {@link PROTOCOL_SCHEMA_VERSION}.
|
|
17
|
+
* - **Explicit string** → used as-is (cross-version test scenarios,
|
|
18
|
+
* replay fidelity when forwarding an already-stamped envelope).
|
|
19
|
+
* - **Explicit `undefined`** (`makeXxx({ schemaVersion: undefined,
|
|
20
|
+
* ... })`) → the builder OMITS the field entirely (no
|
|
21
|
+
* `schemaVersion` key on the returned envelope). This is a
|
|
22
|
+
* test-only pattern used by consumer-side tests that assert
|
|
23
|
+
* behavior when the field is absent on the wire. Production
|
|
24
|
+
* producers MUST NOT pass `undefined` explicitly.
|
|
25
|
+
*
|
|
26
|
+
* Key-present-vs-absent is distinguished via the `in` operator —
|
|
27
|
+
* `'schemaVersion' in parts` is `true` iff the caller wrote the key,
|
|
28
|
+
* even as `undefined`. The builders rely on that distinction so the
|
|
29
|
+
* test-only omit path does not require a separate escape-hatch flag.
|
|
30
|
+
*
|
|
31
|
+
* **Exactly which key is set** matters. The builder omits `undefined`
|
|
32
|
+
* optional fields entirely (it does not emit `{key: undefined}`) so
|
|
33
|
+
* that `JSON.stringify` produces the same bytes as the old manual
|
|
34
|
+
* `if (x !== undefined) envelope.x = x` pattern — byte-equivalence
|
|
35
|
+
* with every pre-refactor stamp site is a load-bearing claim of the
|
|
36
|
+
* centralization.
|
|
37
|
+
*
|
|
38
|
+
* **Scope.** These builders stamp and shape; they do NOT validate.
|
|
39
|
+
* Validators live in `@ggui-ai/protocol/validation/*`. The division
|
|
40
|
+
* is deliberate: stamping is part of the wire-shape contract (a
|
|
41
|
+
* producer obligation), validation is part of the behavior contract
|
|
42
|
+
* (an observable-violation obligation). Keeping them separate keeps
|
|
43
|
+
* each module's surface narrow.
|
|
44
|
+
*
|
|
45
|
+
* @see PROTOCOL_SCHEMA_VERSION on `@ggui-ai/protocol`
|
|
46
|
+
*/
|
|
47
|
+
import type { ActionEnvelope, EventType } from '../types/events.js';
|
|
48
|
+
import type { ErrorPayload, StreamEnvelope } from '../types/live-channel.js';
|
|
49
|
+
import type { ContractErrorCode, ContractErrorPayload, JsonValue, StreamChannelMode } from '../types/data-contract.js';
|
|
50
|
+
/** Input type for {@link makeActionEnvelope}. */
|
|
51
|
+
export interface MakeActionEnvelopeInput<TPayload = JsonValue> {
|
|
52
|
+
readonly sessionId: string;
|
|
53
|
+
readonly type: EventType;
|
|
54
|
+
readonly payload?: TPayload;
|
|
55
|
+
readonly stackIndex?: number;
|
|
56
|
+
readonly stackItemId?: string;
|
|
57
|
+
readonly clientSeq?: number;
|
|
58
|
+
/**
|
|
59
|
+
* `schemaVersion` override. See the module docstring for the three
|
|
60
|
+
* semantic paths (omit key → default stamp; pass string → stamp
|
|
61
|
+
* that value; pass explicit `undefined` → omit stamp entirely —
|
|
62
|
+
* test-only).
|
|
63
|
+
*/
|
|
64
|
+
readonly schemaVersion?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Input type for {@link makeStreamEnvelope}. */
|
|
67
|
+
export interface MakeStreamEnvelopeInput {
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
readonly channel: string;
|
|
70
|
+
readonly mode: StreamChannelMode;
|
|
71
|
+
readonly payload: JsonValue;
|
|
72
|
+
readonly complete?: boolean;
|
|
73
|
+
readonly seq?: number;
|
|
74
|
+
/** See {@link MakeActionEnvelopeInput.schemaVersion}. */
|
|
75
|
+
readonly schemaVersion?: string;
|
|
76
|
+
}
|
|
77
|
+
/** Input type for {@link makeErrorPayload}. */
|
|
78
|
+
export interface MakeErrorPayloadInput {
|
|
79
|
+
readonly code: string;
|
|
80
|
+
readonly message: string;
|
|
81
|
+
readonly details?: JsonValue;
|
|
82
|
+
}
|
|
83
|
+
/** Input type for {@link makeContractErrorPayload}. */
|
|
84
|
+
export interface MakeContractErrorPayloadInput {
|
|
85
|
+
readonly toolName: string;
|
|
86
|
+
readonly actionName?: string;
|
|
87
|
+
readonly sourceAction?: {
|
|
88
|
+
readonly type: 'wired-action' | 'refresh-stream' | (string & {});
|
|
89
|
+
readonly dispatchedAt: string;
|
|
90
|
+
};
|
|
91
|
+
readonly error: {
|
|
92
|
+
readonly code: ContractErrorCode;
|
|
93
|
+
readonly message: string;
|
|
94
|
+
readonly causedBy?: string;
|
|
95
|
+
};
|
|
96
|
+
readonly timestamp: string;
|
|
97
|
+
/** See {@link MakeActionEnvelopeInput.schemaVersion}. */
|
|
98
|
+
readonly schemaVersion?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Build an {@link ActionEnvelope} with `schemaVersion` stamped to
|
|
102
|
+
* {@link PROTOCOL_SCHEMA_VERSION} unless the caller overrides.
|
|
103
|
+
*
|
|
104
|
+
* Filters `undefined` optional fields so the serialized wire message
|
|
105
|
+
* omits them (matches the producer convention that "absent field =
|
|
106
|
+
* default").
|
|
107
|
+
*/
|
|
108
|
+
export declare function makeActionEnvelope<TPayload = JsonValue>(parts: MakeActionEnvelopeInput<TPayload>): ActionEnvelope<TPayload>;
|
|
109
|
+
/**
|
|
110
|
+
* Build a {@link StreamEnvelope} with `schemaVersion` stamped to
|
|
111
|
+
* {@link PROTOCOL_SCHEMA_VERSION} unless the caller overrides.
|
|
112
|
+
*
|
|
113
|
+
* Filters `undefined` optional fields (`complete`, `seq`) so the
|
|
114
|
+
* serialized wire message omits them. `seq` is server-assigned in
|
|
115
|
+
* practice — callers pass the value the buffer hands them.
|
|
116
|
+
*/
|
|
117
|
+
export declare function makeStreamEnvelope(parts: MakeStreamEnvelopeInput): StreamEnvelope;
|
|
118
|
+
/**
|
|
119
|
+
* Build an {@link ErrorPayload} for the `{type: 'error'}` wire frame.
|
|
120
|
+
*
|
|
121
|
+
* Does NOT stamp `schemaVersion` — `ErrorPayload` is the wire-level
|
|
122
|
+
* error envelope (free-form `code: string`), not an envelope that
|
|
123
|
+
* opts into the forward-compat stamp (see {@link ActionEnvelope} /
|
|
124
|
+
* {@link StreamEnvelope} / {@link ContractErrorPayload}). Keeping
|
|
125
|
+
* `ErrorPayload` stamp-free preserves byte-equivalence with every
|
|
126
|
+
* existing server-side error emission that pre-dates the central
|
|
127
|
+
* builders.
|
|
128
|
+
*
|
|
129
|
+
* The builder exists so first-party subscribe / handshake paths emit
|
|
130
|
+
* canonical codes (e.g. `UPGRADE_REQUIRED`) via a single helper
|
|
131
|
+
* instead of spreading `{code, message}` object literals. `details`
|
|
132
|
+
* is filtered when `undefined` so the serialized frame matches the
|
|
133
|
+
* pre-builder `{code, message}` shape byte-for-byte.
|
|
134
|
+
*/
|
|
135
|
+
export declare function makeErrorPayload(parts: MakeErrorPayloadInput): ErrorPayload;
|
|
136
|
+
/**
|
|
137
|
+
* Build a {@link ContractErrorPayload} with `schemaVersion` stamped
|
|
138
|
+
* to {@link PROTOCOL_SCHEMA_VERSION} unless the caller overrides.
|
|
139
|
+
*
|
|
140
|
+
* Filters `undefined` optional fields so the emitted payload keeps
|
|
141
|
+
* byte-equivalence with the pre-refactor session-channel router
|
|
142
|
+
* code.
|
|
143
|
+
*/
|
|
144
|
+
export declare function makeContractErrorPayload(parts: MakeContractErrorPayloadInput): ContractErrorPayload;
|
|
145
|
+
//# sourceMappingURL=builders.d.ts.map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