feat: add websocket upstream adapter
This commit is contained in:
@@ -238,6 +238,7 @@ fn runtime_test_failure_code(error: &RuntimeError) -> &'static str {
|
||||
RuntimeError::GraphqlAdapter(_) => "runtime_graphql_error",
|
||||
RuntimeError::GrpcAdapter(_) => "runtime_grpc_error",
|
||||
RuntimeError::RestAdapter(_) => "runtime_rest_error",
|
||||
RuntimeError::WebsocketAdapter(_) => "runtime_websocket_error",
|
||||
RuntimeError::UnsupportedProtocol { .. } => "runtime_protocol_error",
|
||||
RuntimeError::InvalidPreparedRequest { .. } => "runtime_request_error",
|
||||
RuntimeError::MissingStreamingConfig { .. } => "runtime_streaming_config_error",
|
||||
|
||||
@@ -1347,10 +1347,15 @@ impl AdminService {
|
||||
}
|
||||
|
||||
pub async fn list_protocol_capabilities(&self) -> Vec<ProtocolCapabilityView> {
|
||||
[Protocol::Rest, Protocol::Graphql, Protocol::Grpc]
|
||||
.into_iter()
|
||||
.map(protocol_capability_view)
|
||||
.collect()
|
||||
[
|
||||
Protocol::Rest,
|
||||
Protocol::Graphql,
|
||||
Protocol::Grpc,
|
||||
Protocol::Websocket,
|
||||
]
|
||||
.into_iter()
|
||||
.map(protocol_capability_view)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
@@ -3601,6 +3606,7 @@ fn validate_protocol_target(protocol: Protocol, target: &Target) -> Result<(), A
|
||||
(Protocol::Rest, Target::Rest(_))
|
||||
| (Protocol::Graphql, Target::Graphql(_))
|
||||
| (Protocol::Grpc, Target::Grpc(_))
|
||||
| (Protocol::Websocket, Target::Websocket(_))
|
||||
);
|
||||
|
||||
if is_match {
|
||||
@@ -3827,6 +3833,7 @@ fn demo_grpc_operation_payload() -> OperationPayload {
|
||||
headers: BTreeMap::new(),
|
||||
protocol_options: Some(crank_core::ProtocolOptions {
|
||||
grpc: Some(crank_core::GrpcProtocolOptions { use_tls: false }),
|
||||
websocket: None,
|
||||
}),
|
||||
streaming: None,
|
||||
},
|
||||
@@ -4007,6 +4014,7 @@ fn runtime_error_code(error: &RuntimeError) -> &'static str {
|
||||
RuntimeError::GraphqlAdapter(_) => "graphql_error",
|
||||
RuntimeError::GrpcAdapter(_) => "grpc_error",
|
||||
RuntimeError::RestAdapter(_) => "rest_error",
|
||||
RuntimeError::WebsocketAdapter(_) => "websocket_error",
|
||||
RuntimeError::UnsupportedProtocol { .. } => "unsupported_protocol",
|
||||
RuntimeError::MissingStreamingConfig { .. } => "streaming_config_error",
|
||||
RuntimeError::UnsupportedExecutionMode { .. } => "streaming_mode_error",
|
||||
@@ -4034,7 +4042,7 @@ fn protocol_capability_view(protocol: Protocol) -> ProtocolCapabilityView {
|
||||
.filter(|behavior| protocol.supports_transport_behavior(*behavior))
|
||||
.collect();
|
||||
let supports_upload_artifacts = match protocol {
|
||||
Protocol::Rest | Protocol::Graphql => Vec::new(),
|
||||
Protocol::Rest | Protocol::Graphql | Protocol::Websocket => Vec::new(),
|
||||
Protocol::Grpc => vec!["proto".to_owned(), "descriptor_set".to_owned()],
|
||||
};
|
||||
|
||||
|
||||
@@ -1725,6 +1725,7 @@ fn runtime_error_code(error: &RuntimeError) -> &'static str {
|
||||
RuntimeError::GraphqlAdapter(_) => "adapter_execution_error",
|
||||
RuntimeError::GrpcAdapter(_) => "adapter_execution_error",
|
||||
RuntimeError::RestAdapter(_) => "adapter_execution_error",
|
||||
RuntimeError::WebsocketAdapter(_) => "adapter_execution_error",
|
||||
RuntimeError::UnsupportedProtocol { .. } => "unsupported_protocol",
|
||||
RuntimeError::MissingStreamingConfig { .. } => "streaming_config_error",
|
||||
RuntimeError::UnsupportedExecutionMode { .. } => "streaming_mode_error",
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
<option value="rest" selected>REST</option>
|
||||
<option value="graphql">GraphQL</option>
|
||||
<option value="grpc">gRPC</option>
|
||||
<option value="websocket">WebSocket</option>
|
||||
</select>
|
||||
<div class="form-hint" data-i18n="workspace_setup.protocol_hint">Pre-selected in the operation wizard.</div>
|
||||
</div>
|
||||
|
||||
+2
-2
@@ -181,13 +181,13 @@
|
||||
<svg class="chevron" width="10" height="10"><use href="icons/general/chevron-down.svg#icon"/></svg>
|
||||
</button>
|
||||
<div class="dropdown-menu" x-show="openDropdown === 'protocol'" x-transition>
|
||||
<template x-for="p in ['rest','graphql','grpc']" :key="p">
|
||||
<template x-for="p in ['rest','graphql','grpc','websocket']" :key="p">
|
||||
<button
|
||||
class="dropdown-item"
|
||||
:class="{ selected: filterProtocol === p }"
|
||||
@click="setProtocol(p)"
|
||||
>
|
||||
<span x-text="p === 'rest' ? 'REST' : p === 'graphql' ? 'GraphQL' : 'gRPC'"></span>
|
||||
<span x-text="p === 'rest' ? 'REST' : p === 'graphql' ? 'GraphQL' : p === 'grpc' ? 'gRPC' : 'WebSocket'"></span>
|
||||
<svg class="check" width="12" height="12"><use href="icons/general/check.svg#icon"/></svg>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -416,12 +416,14 @@ document.addEventListener('alpine:init', function() {
|
||||
protocolBadge(operation) {
|
||||
if (operation.protocol === 'rest') return 'badge badge-rest';
|
||||
if (operation.protocol === 'graphql') return 'badge badge-graphql';
|
||||
if (operation.protocol === 'websocket') return 'badge badge-rest';
|
||||
return 'badge badge-grpc';
|
||||
},
|
||||
|
||||
protocolLabel(operation) {
|
||||
if (operation.protocol === 'rest') return 'REST';
|
||||
if (operation.protocol === 'graphql') return 'GQL';
|
||||
if (operation.protocol === 'websocket') return 'WS';
|
||||
return 'gRPC';
|
||||
},
|
||||
|
||||
|
||||
@@ -399,6 +399,7 @@ document.addEventListener('alpine:init', function() {
|
||||
return operation.method ? ('REST · ' + operation.method) : 'REST';
|
||||
}
|
||||
if (operation.protocol === 'graphql') return 'GraphQL';
|
||||
if (operation.protocol === 'websocket') return 'WebSocket';
|
||||
return 'gRPC';
|
||||
},
|
||||
|
||||
|
||||
@@ -410,6 +410,7 @@ var TRANSLATIONS = {
|
||||
'workspace_setup.custom_protocol.rest': 'REST',
|
||||
'workspace_setup.custom_protocol.graphql': 'GraphQL',
|
||||
'workspace_setup.custom_protocol.grpc': 'gRPC',
|
||||
'workspace_setup.custom_protocol.websocket': 'WebSocket',
|
||||
|
||||
// Wizard
|
||||
'wizard.back_catalog': 'Operations',
|
||||
@@ -444,6 +445,8 @@ var TRANSLATIONS = {
|
||||
'wizard.step1.graphql_tagline': 'Query and mutate a GraphQL schema. Supports queries and mutations over one fixed operation.',
|
||||
'wizard.step1.grpc_name': 'gRPC',
|
||||
'wizard.step1.grpc_tagline': 'High-performance binary RPC over HTTP/2. Ideal for low-latency internal services.',
|
||||
'wizard.step1.websocket_name': 'WebSocket',
|
||||
'wizard.step1.websocket_tagline': 'Stateful event streams and push-oriented integrations normalized into bounded MCP streaming tools.',
|
||||
'wizard.step1.query': 'Query',
|
||||
'wizard.step1.mutation': 'Mutation',
|
||||
'wizard.step1.unary': 'Unary',
|
||||
@@ -1192,6 +1195,7 @@ var TRANSLATIONS = {
|
||||
'workspace_setup.custom_protocol.rest': 'REST',
|
||||
'workspace_setup.custom_protocol.graphql': 'GraphQL',
|
||||
'workspace_setup.custom_protocol.grpc': 'gRPC',
|
||||
'workspace_setup.custom_protocol.websocket': 'WebSocket',
|
||||
|
||||
// Wizard
|
||||
'wizard.back_catalog': 'Операции',
|
||||
@@ -1226,6 +1230,8 @@ var TRANSLATIONS = {
|
||||
'wizard.step1.graphql_tagline': 'Запросы и мутации к GraphQL-схеме. Поддерживаются query и mutation для одной фиксированной операции.',
|
||||
'wizard.step1.grpc_name': 'gRPC',
|
||||
'wizard.step1.grpc_tagline': 'Высокопроизводительный бинарный RPC поверх HTTP/2. Подходит для низколатентных внутренних сервисов.',
|
||||
'wizard.step1.websocket_name': 'WebSocket',
|
||||
'wizard.step1.websocket_tagline': 'Состояние соединения, event streams и push-oriented интеграции, нормализованные в bounded MCP streaming tools.',
|
||||
'wizard.step1.query': 'Запрос',
|
||||
'wizard.step1.mutation': 'Мутация',
|
||||
'wizard.step1.unary': 'Unary',
|
||||
|
||||
@@ -58,6 +58,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if (protocol === 'grpc' || protocol === 'Grpc') {
|
||||
return 'var(--accent)';
|
||||
}
|
||||
if (protocol === 'websocket' || protocol === 'Websocket') {
|
||||
return 'var(--teal)';
|
||||
}
|
||||
return 'var(--blue)';
|
||||
}
|
||||
|
||||
@@ -68,6 +71,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if (protocol === 'grpc' || protocol === 'Grpc') {
|
||||
return 'gRPC';
|
||||
}
|
||||
if (protocol === 'websocket' || protocol === 'Websocket') {
|
||||
return 'WebSocket';
|
||||
}
|
||||
return 'REST';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var currentStep = 1;
|
||||
var TOTAL_STEPS = 5;
|
||||
var wizardProtocol = 'rest'; // 'rest' | 'graphql' | 'grpc'
|
||||
var wizardProtocol = 'rest'; // 'rest' | 'graphql' | 'grpc' | 'websocket'
|
||||
var wizardMode = 'create'; // 'create' | 'edit'
|
||||
var wizardEditId = null;
|
||||
var wizardWorkspaceId = null;
|
||||
@@ -32,6 +32,10 @@ function defaultProtocolCapabilities() {
|
||||
supports_execution_modes: ['unary', 'window', 'session', 'async_job'],
|
||||
supports_transport_behaviors: ['request_response', 'server_stream'],
|
||||
},
|
||||
websocket: {
|
||||
supports_execution_modes: ['window', 'session', 'async_job'],
|
||||
supports_transport_behaviors: ['server_stream', 'stateful_session', 'deferred_result'],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user