@nice-code/action 0.4.4 → 0.4.6
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/README.md +20 -28
- package/build/devtools/browser/index.js +159 -60
- package/build/devtools/server/index.js +2 -0
- package/build/index.js +329 -166
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.types.d.ts +2 -1
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +4 -3
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +3 -3
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/ConnectionTransportManager.d.ts +2 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/{TransportCustom.d.ts → CustomConnection.d.ts} +2 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomTransport.d.ts +33 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/{TransportHttp.d.ts → HttpConnection.d.ts} +2 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpTransport.d.ts +28 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.types.d.ts +1 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.d.ts +25 -12
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +15 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/TransportConnection.d.ts +27 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/{TransportWebSocket.d.ts → WebSocketConnection.d.ts} +6 -3
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketTransport.d.ts +41 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/ws_util.d.ts +2 -0
- package/build/types/ActionRuntime/test/helpers/new_action_test_data.d.ts +2 -2
- package/build/types/devtools/browser/components/HandlerChips.d.ts +11 -0
- package/build/types/devtools/browser/components/Tooltip.d.ts +11 -1
- package/build/types/devtools/core/ActionDevtools.types.d.ts +5 -0
- package/build/types/index.d.ts +4 -4
- package/package.json +4 -4
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.combined.types.d.ts +0 -4
package/build/index.js
CHANGED
|
@@ -1870,6 +1870,143 @@ class ConnectionTransportManager {
|
|
|
1870
1870
|
}
|
|
1871
1871
|
}
|
|
1872
1872
|
|
|
1873
|
+
// src/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.ts
|
|
1874
|
+
class ActionExternalClientHandler extends ActionHandler {
|
|
1875
|
+
externalClient;
|
|
1876
|
+
handlerType = "external" /* external */;
|
|
1877
|
+
cuid;
|
|
1878
|
+
_defaultTimeout;
|
|
1879
|
+
_transportCache = new Map;
|
|
1880
|
+
transportManager = new ConnectionTransportManager(this._transportCache);
|
|
1881
|
+
_incomingActionDataListeners = [];
|
|
1882
|
+
actionRouter = new ActionRouter({
|
|
1883
|
+
contextType: "handler_route" /* handler_route */,
|
|
1884
|
+
handler: this
|
|
1885
|
+
});
|
|
1886
|
+
constructor({
|
|
1887
|
+
runtimeCoordinate: externalClientSpecifier,
|
|
1888
|
+
transports,
|
|
1889
|
+
defaultTimeout
|
|
1890
|
+
}) {
|
|
1891
|
+
super();
|
|
1892
|
+
this.externalClient = externalClientSpecifier;
|
|
1893
|
+
this.cuid = nanoid4();
|
|
1894
|
+
this._defaultTimeout = defaultTimeout ?? DEFAULT_TRANSPORT_TIMEOUT;
|
|
1895
|
+
for (const transport of transports) {
|
|
1896
|
+
const connection = transport._createConnection({
|
|
1897
|
+
resolvers: {
|
|
1898
|
+
onIncomingActionDataJson: (json) => {
|
|
1899
|
+
for (const l of this._incomingActionDataListeners)
|
|
1900
|
+
l(json);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
});
|
|
1904
|
+
connection.definition = transport;
|
|
1905
|
+
this.transportManager.addTransport(connection);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
forDomain(domain) {
|
|
1909
|
+
this.actionRouter.forDomain(domain, true);
|
|
1910
|
+
return this;
|
|
1911
|
+
}
|
|
1912
|
+
forAction(action) {
|
|
1913
|
+
this.actionRouter.forAction(action, true);
|
|
1914
|
+
return this;
|
|
1915
|
+
}
|
|
1916
|
+
forActionIds(domain, ids) {
|
|
1917
|
+
this.actionRouter.forActionIds(domain, ids, true);
|
|
1918
|
+
return this;
|
|
1919
|
+
}
|
|
1920
|
+
_setIncomingActionDataListener(listener) {
|
|
1921
|
+
this._incomingActionDataListeners.push(listener);
|
|
1922
|
+
}
|
|
1923
|
+
async handleActionRequest(action, config) {
|
|
1924
|
+
const localRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
1925
|
+
const localClient = localRuntime.coordinate;
|
|
1926
|
+
const incomingTimeout = config?.timeout ?? this._defaultTimeout;
|
|
1927
|
+
const parentCuid = peekHandlerCuid();
|
|
1928
|
+
const callSite = action._callSite ?? new Error().stack;
|
|
1929
|
+
const { methods, transport } = await this.transportManager.getReadyTransport({
|
|
1930
|
+
action,
|
|
1931
|
+
localClient,
|
|
1932
|
+
externalClient: this.externalClient
|
|
1933
|
+
});
|
|
1934
|
+
action.context.addRouteItem({
|
|
1935
|
+
runtime: localClient,
|
|
1936
|
+
handler: this.toHandlerRouteItem(transport, {
|
|
1937
|
+
action,
|
|
1938
|
+
localClient,
|
|
1939
|
+
externalClient: this.externalClient
|
|
1940
|
+
}),
|
|
1941
|
+
time: Date.now()
|
|
1942
|
+
});
|
|
1943
|
+
const runningAction = new RunningAction({
|
|
1944
|
+
context: action.context,
|
|
1945
|
+
request: action,
|
|
1946
|
+
parentCuid,
|
|
1947
|
+
callSite
|
|
1948
|
+
});
|
|
1949
|
+
localRuntime.registerRunningAction(runningAction);
|
|
1950
|
+
const routeActionParams = {
|
|
1951
|
+
action,
|
|
1952
|
+
runningAction,
|
|
1953
|
+
localClient,
|
|
1954
|
+
externalClient: this.externalClient,
|
|
1955
|
+
timeout: incomingTimeout
|
|
1956
|
+
};
|
|
1957
|
+
if (action.type === "request" /* request */ && methods.updateRunConfig != null) {
|
|
1958
|
+
const runConfig = methods.updateRunConfig(routeActionParams);
|
|
1959
|
+
routeActionParams.timeout = runConfig?.timeout ?? incomingTimeout;
|
|
1960
|
+
}
|
|
1961
|
+
try {
|
|
1962
|
+
methods.sendActionData(routeActionParams);
|
|
1963
|
+
} catch (err3) {
|
|
1964
|
+
runningAction._abort(err3);
|
|
1965
|
+
}
|
|
1966
|
+
return runningAction;
|
|
1967
|
+
}
|
|
1968
|
+
async sendReturnPayload(payload, config) {
|
|
1969
|
+
const localClient = config.targetLocalRuntime.coordinate;
|
|
1970
|
+
try {
|
|
1971
|
+
const { methods } = await this.transportManager.getReadyTransport({
|
|
1972
|
+
action: payload,
|
|
1973
|
+
localClient,
|
|
1974
|
+
externalClient: this.externalClient
|
|
1975
|
+
});
|
|
1976
|
+
if (methods.sendReturnData == null)
|
|
1977
|
+
return false;
|
|
1978
|
+
methods.sendReturnData(payload);
|
|
1979
|
+
return true;
|
|
1980
|
+
} catch {
|
|
1981
|
+
return false;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
toJsonObject() {
|
|
1985
|
+
return {
|
|
1986
|
+
type: this.handlerType,
|
|
1987
|
+
client: this.externalClient
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
toHandlerRouteItem(transport, input) {
|
|
1991
|
+
return {
|
|
1992
|
+
type: this.handlerType,
|
|
1993
|
+
client: this.externalClient,
|
|
1994
|
+
transOrd: transport.transOrd,
|
|
1995
|
+
transType: transport.type,
|
|
1996
|
+
transInfo: transport.getRouteInfo(input)
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
clearTransportCache() {
|
|
2000
|
+
this._transportCache.clear();
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
var createExternalClientHandler = (config) => {
|
|
2004
|
+
return new ActionExternalClientHandler(config);
|
|
2005
|
+
};
|
|
2006
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/Transport.ts
|
|
2007
|
+
class Transport {
|
|
2008
|
+
}
|
|
2009
|
+
|
|
1873
2010
|
// src/ActionRuntime/Handler/ExternalClient/Transport/helpers/addTransportStatusMetadata.ts
|
|
1874
2011
|
function addTransportStatusMetadata(transportStatus) {
|
|
1875
2012
|
if (transportStatus.status === "ready" /* ready */) {
|
|
@@ -1902,19 +2039,23 @@ function addTransportStatusMetadata(transportStatus) {
|
|
|
1902
2039
|
};
|
|
1903
2040
|
}
|
|
1904
2041
|
|
|
1905
|
-
// src/ActionRuntime/Handler/ExternalClient/Transport/
|
|
2042
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/TransportConnection.ts
|
|
1906
2043
|
var transportOrd = 0;
|
|
1907
2044
|
|
|
1908
|
-
class
|
|
2045
|
+
class TransportConnection {
|
|
1909
2046
|
def;
|
|
1910
2047
|
transOrd = transportOrd++;
|
|
1911
2048
|
type;
|
|
1912
2049
|
initialized;
|
|
2050
|
+
definition;
|
|
1913
2051
|
constructor(def) {
|
|
1914
2052
|
this.def = def;
|
|
1915
2053
|
this.type = def.type;
|
|
1916
2054
|
this.initialized = def.initialize();
|
|
1917
2055
|
}
|
|
2056
|
+
getRouteInfo(input) {
|
|
2057
|
+
return this.definition?.getRouteInfo(input);
|
|
2058
|
+
}
|
|
1918
2059
|
_getCacheKey(input) {
|
|
1919
2060
|
const parts = this.initialized.getTransportCacheKey?.(input);
|
|
1920
2061
|
if (parts == null)
|
|
@@ -1958,8 +2099,8 @@ class Transport {
|
|
|
1958
2099
|
}
|
|
1959
2100
|
}
|
|
1960
2101
|
|
|
1961
|
-
// src/ActionRuntime/Handler/ExternalClient/Transport/Custom/
|
|
1962
|
-
class
|
|
2102
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomConnection.ts
|
|
2103
|
+
class CustomConnection extends TransportConnection {
|
|
1963
2104
|
constructor(def) {
|
|
1964
2105
|
super({
|
|
1965
2106
|
...def,
|
|
@@ -1975,9 +2116,65 @@ class TransportCustom extends Transport {
|
|
|
1975
2116
|
}
|
|
1976
2117
|
}
|
|
1977
2118
|
|
|
1978
|
-
// src/ActionRuntime/Handler/ExternalClient/Transport/
|
|
2119
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomTransport.ts
|
|
2120
|
+
class CustomTransport extends Transport {
|
|
2121
|
+
options;
|
|
2122
|
+
type = "custom" /* custom */;
|
|
2123
|
+
constructor(options) {
|
|
2124
|
+
super();
|
|
2125
|
+
this.options = options;
|
|
2126
|
+
}
|
|
2127
|
+
_createConnection(_ctx) {
|
|
2128
|
+
const options = this.options;
|
|
2129
|
+
return new CustomConnection({
|
|
2130
|
+
initialize: () => ({
|
|
2131
|
+
getTransportCacheKey: options.getTransportCacheKey,
|
|
2132
|
+
getTransport: options.getTransport ?? (() => ({
|
|
2133
|
+
status: "ready" /* ready */,
|
|
2134
|
+
readyData: {
|
|
2135
|
+
sendActionData: options.sendActionData,
|
|
2136
|
+
sendReturnData: options.sendReturnData,
|
|
2137
|
+
updateRunConfig: options.updateRunConfig,
|
|
2138
|
+
closeTransport: options.closeTransport ?? (() => {})
|
|
2139
|
+
}
|
|
2140
|
+
}))
|
|
2141
|
+
})
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
getRouteInfo(input) {
|
|
2145
|
+
if (this.options.getRouteInfo != null)
|
|
2146
|
+
return this.options.getRouteInfo(input);
|
|
2147
|
+
return {
|
|
2148
|
+
type: "custom" /* custom */,
|
|
2149
|
+
summary: this.options.label ?? "custom"
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport_ws.ts
|
|
2154
|
+
import { err as err3 } from "@nice-code/error";
|
|
2155
|
+
var EErrId_NiceTransport_WebSocket;
|
|
2156
|
+
((EErrId_NiceTransport_WebSocket2) => {
|
|
2157
|
+
EErrId_NiceTransport_WebSocket2["ws_disconnected"] = "ws_disconnected";
|
|
2158
|
+
EErrId_NiceTransport_WebSocket2["ws_create_failed"] = "ws_create_failed";
|
|
2159
|
+
EErrId_NiceTransport_WebSocket2["ws_error"] = "ws_error";
|
|
2160
|
+
})(EErrId_NiceTransport_WebSocket ||= {});
|
|
2161
|
+
var err_nice_transport_ws = err_nice_transport.createChildDomain({
|
|
2162
|
+
domain: "ws_transport",
|
|
2163
|
+
schema: {
|
|
2164
|
+
["ws_disconnected" /* ws_disconnected */]: err3({
|
|
2165
|
+
message: () => `WebSocket transport disconnected.`
|
|
2166
|
+
}),
|
|
2167
|
+
["ws_create_failed" /* ws_create_failed */]: err3({
|
|
2168
|
+
message: ({ originalError }) => `Failed to create WebSocket transport.${originalError ? ` Original error: ${originalError.message}` : ""}`
|
|
2169
|
+
}),
|
|
2170
|
+
["ws_error" /* ws_error */]: err3({
|
|
2171
|
+
message: ({ originalError }) => `WebSocket transport error.${originalError ? ` Original error: ${originalError.message}` : ""}`
|
|
2172
|
+
})
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpConnection.ts
|
|
1979
2176
|
import { castNiceError as castNiceError3, isNiceErrorObject as isNiceErrorObject2, NiceError as NiceError2 } from "@nice-code/error";
|
|
1980
|
-
class
|
|
2177
|
+
class HttpConnection extends TransportConnection {
|
|
1981
2178
|
constructor(def) {
|
|
1982
2179
|
super({
|
|
1983
2180
|
...def,
|
|
@@ -1988,7 +2185,7 @@ class TransportHttp extends Transport {
|
|
|
1988
2185
|
return {
|
|
1989
2186
|
sendActionData: (input) => {
|
|
1990
2187
|
const request = methods.createRequest(input);
|
|
1991
|
-
this.send({ ...input, params: { request }, runningAction: input.runningAction }).catch((
|
|
2188
|
+
this.send({ ...input, params: { request }, runningAction: input.runningAction }).catch((err4) => input.runningAction._abort(err4));
|
|
1992
2189
|
},
|
|
1993
2190
|
updateRunConfig: methods.updateRunConfig
|
|
1994
2191
|
};
|
|
@@ -2048,7 +2245,7 @@ class TransportHttp extends Transport {
|
|
|
2048
2245
|
try {
|
|
2049
2246
|
text = await res.text();
|
|
2050
2247
|
} catch (e) {
|
|
2051
|
-
console.warn(`Failed to read error response body for failed HTTP request in
|
|
2248
|
+
console.warn(`Failed to read error response body for failed HTTP request in HttpConnection:`, e);
|
|
2052
2249
|
}
|
|
2053
2250
|
throw err_nice_transport.fromId("send_failed" /* send_failed */, {
|
|
2054
2251
|
actionState: action.type,
|
|
@@ -2068,18 +2265,18 @@ class TransportHttp extends Transport {
|
|
|
2068
2265
|
}
|
|
2069
2266
|
runningAction._completeWithResult(action._domain.hydrateResultPayload(json));
|
|
2070
2267
|
}
|
|
2071
|
-
} catch (
|
|
2268
|
+
} catch (err4) {
|
|
2072
2269
|
if (timedOut) {
|
|
2073
2270
|
throw err_nice_transport.fromId("timeout" /* timeout */, { timeout });
|
|
2074
2271
|
}
|
|
2075
|
-
if (
|
|
2076
|
-
throw
|
|
2272
|
+
if (err4 instanceof NiceError2) {
|
|
2273
|
+
throw err4;
|
|
2077
2274
|
}
|
|
2078
2275
|
throw err_nice_transport.fromId("send_failed" /* send_failed */, {
|
|
2079
2276
|
actionState: action.type,
|
|
2080
2277
|
actionId: action.id,
|
|
2081
|
-
message:
|
|
2082
|
-
}).withOriginError(
|
|
2278
|
+
message: err4 instanceof Error ? err4.message : String(err4)
|
|
2279
|
+
}).withOriginError(err4 instanceof Error ? err4 : undefined);
|
|
2083
2280
|
} finally {
|
|
2084
2281
|
clearTimeout(timeoutId);
|
|
2085
2282
|
unsubscribe();
|
|
@@ -2087,29 +2284,57 @@ class TransportHttp extends Transport {
|
|
|
2087
2284
|
}
|
|
2088
2285
|
}
|
|
2089
2286
|
|
|
2090
|
-
// src/ActionRuntime/Handler/ExternalClient/Transport/
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
domain: "ws_transport",
|
|
2100
|
-
schema: {
|
|
2101
|
-
["ws_disconnected" /* ws_disconnected */]: err3({
|
|
2102
|
-
message: () => `WebSocket transport disconnected.`
|
|
2103
|
-
}),
|
|
2104
|
-
["ws_create_failed" /* ws_create_failed */]: err3({
|
|
2105
|
-
message: ({ originalError }) => `Failed to create WebSocket transport.${originalError ? ` Original error: ${originalError.message}` : ""}`
|
|
2106
|
-
}),
|
|
2107
|
-
["ws_error" /* ws_error */]: err3({
|
|
2108
|
-
message: ({ originalError }) => `WebSocket transport error.${originalError ? ` Original error: ${originalError.message}` : ""}`
|
|
2109
|
-
})
|
|
2287
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpTransport.ts
|
|
2288
|
+
function resolveMaybe(value, input) {
|
|
2289
|
+
return typeof value === "function" ? value(input) : value;
|
|
2290
|
+
}
|
|
2291
|
+
function shortPath(url) {
|
|
2292
|
+
try {
|
|
2293
|
+
return new URL(url).pathname || url;
|
|
2294
|
+
} catch {
|
|
2295
|
+
return url;
|
|
2110
2296
|
}
|
|
2111
|
-
}
|
|
2297
|
+
}
|
|
2112
2298
|
|
|
2299
|
+
class HttpTransport extends Transport {
|
|
2300
|
+
options;
|
|
2301
|
+
type = "http" /* http */;
|
|
2302
|
+
constructor(options) {
|
|
2303
|
+
super();
|
|
2304
|
+
this.options = options;
|
|
2305
|
+
}
|
|
2306
|
+
_resolveRequest(input) {
|
|
2307
|
+
if (this.options.createRequest != null)
|
|
2308
|
+
return this.options.createRequest(input);
|
|
2309
|
+
return {
|
|
2310
|
+
url: resolveMaybe(this.options.url, input),
|
|
2311
|
+
headers: this.options.headers != null ? resolveMaybe(this.options.headers, input) : undefined
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
_createConnection(_ctx) {
|
|
2315
|
+
return new HttpConnection({
|
|
2316
|
+
initialize: () => ({
|
|
2317
|
+
getTransportCacheKey: this.options.getTransportCacheKey,
|
|
2318
|
+
getTransport: () => ({
|
|
2319
|
+
status: "ready" /* ready */,
|
|
2320
|
+
readyData: {
|
|
2321
|
+
createRequest: (input) => this._resolveRequest(input),
|
|
2322
|
+
updateRunConfig: this.options.updateRunConfig
|
|
2323
|
+
}
|
|
2324
|
+
})
|
|
2325
|
+
})
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
getRouteInfo(input) {
|
|
2329
|
+
const { url } = this._resolveRequest(input);
|
|
2330
|
+
return {
|
|
2331
|
+
type: "http" /* http */,
|
|
2332
|
+
method: "POST",
|
|
2333
|
+
url,
|
|
2334
|
+
summary: `POST ${shortPath(url)}`
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2113
2338
|
// src/ActionRuntime/Handler/ExternalClient/Transport/helpers/createUnsetTransportResolvers.ts
|
|
2114
2339
|
var createUnsetTransportResolvers = (type) => ({
|
|
2115
2340
|
onIncomingActionDataJson: (json) => {
|
|
@@ -2117,10 +2342,21 @@ var createUnsetTransportResolvers = (type) => ({
|
|
|
2117
2342
|
}
|
|
2118
2343
|
});
|
|
2119
2344
|
|
|
2120
|
-
// src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/
|
|
2121
|
-
|
|
2345
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/ws_util.ts
|
|
2346
|
+
function shortWs(url) {
|
|
2347
|
+
try {
|
|
2348
|
+
const u = new URL(url);
|
|
2349
|
+
return `${u.host}${u.pathname}`;
|
|
2350
|
+
} catch {
|
|
2351
|
+
return url;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketConnection.ts
|
|
2356
|
+
class WebSocketConnection extends TransportConnection {
|
|
2122
2357
|
resolvers;
|
|
2123
2358
|
_abortSet = new Set;
|
|
2359
|
+
_liveSocketUrl;
|
|
2124
2360
|
constructor(def, resolvers) {
|
|
2125
2361
|
super({ ...def, type: "ws" /* ws */ });
|
|
2126
2362
|
this.resolvers = resolvers ?? createUnsetTransportResolvers("ws" /* ws */);
|
|
@@ -2181,9 +2417,22 @@ class TransportWebSocket extends Transport {
|
|
|
2181
2417
|
readyData: this._finalizeTransportMethods(transportStatusInfo.readyData)
|
|
2182
2418
|
};
|
|
2183
2419
|
}
|
|
2420
|
+
getRouteInfo(input) {
|
|
2421
|
+
const base = this.definition?.getRouteInfo(input);
|
|
2422
|
+
if (base?.url != null || this._liveSocketUrl == null)
|
|
2423
|
+
return base;
|
|
2424
|
+
return {
|
|
2425
|
+
type: "ws" /* ws */,
|
|
2426
|
+
...base,
|
|
2427
|
+
url: this._liveSocketUrl,
|
|
2428
|
+
summary: `ws ${shortWs(this._liveSocketUrl)}`
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2184
2431
|
_finalizeTransportMethods(wsData) {
|
|
2185
2432
|
const ws = wsData.ws;
|
|
2186
2433
|
const disconnectListeners = [];
|
|
2434
|
+
if (ws.url != null && ws.url !== "")
|
|
2435
|
+
this._liveSocketUrl = ws.url;
|
|
2187
2436
|
const sendActionData = (inputs) => {
|
|
2188
2437
|
const { action, runningAction, timeout } = inputs;
|
|
2189
2438
|
if (action.type === "request" /* request */) {
|
|
@@ -2252,140 +2501,53 @@ class TransportWebSocket extends Transport {
|
|
|
2252
2501
|
}
|
|
2253
2502
|
}
|
|
2254
2503
|
|
|
2255
|
-
// src/ActionRuntime/Handler/ExternalClient/
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
actionRouter = new ActionRouter({
|
|
2265
|
-
contextType: "handler_route" /* handler_route */,
|
|
2266
|
-
handler: this
|
|
2267
|
-
});
|
|
2268
|
-
constructor({
|
|
2269
|
-
externalClientSpecifier,
|
|
2270
|
-
transports,
|
|
2271
|
-
defaultTimeout
|
|
2272
|
-
}) {
|
|
2504
|
+
// src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketTransport.ts
|
|
2505
|
+
function resolveMaybe2(value, input) {
|
|
2506
|
+
return typeof value === "function" ? value(input) : value;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
class WebSocketTransport extends Transport {
|
|
2510
|
+
options;
|
|
2511
|
+
type = "ws" /* ws */;
|
|
2512
|
+
constructor(options) {
|
|
2273
2513
|
super();
|
|
2274
|
-
this.
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2514
|
+
this.options = options;
|
|
2515
|
+
}
|
|
2516
|
+
_createSocket(input) {
|
|
2517
|
+
if (this.options.createWebSocket != null)
|
|
2518
|
+
return this.options.createWebSocket(input);
|
|
2519
|
+
if (this.options.url == null) {
|
|
2520
|
+
throw new Error("WebSocketTransport requires `url` or `createWebSocket` when not using `getTransport`.");
|
|
2521
|
+
}
|
|
2522
|
+
return new WebSocket(resolveMaybe2(this.options.url, input));
|
|
2523
|
+
}
|
|
2524
|
+
_createConnection(ctx) {
|
|
2525
|
+
const { url, getTransportCacheKey, getTransport } = this.options;
|
|
2526
|
+
return new WebSocketConnection({
|
|
2527
|
+
initialize: () => ({
|
|
2528
|
+
getTransportCacheKey: getTransportCacheKey ?? (url != null ? (input) => [resolveMaybe2(url, input)] : undefined),
|
|
2529
|
+
getTransport: getTransport ?? ((input) => ({
|
|
2530
|
+
status: "ready" /* ready */,
|
|
2531
|
+
readyData: {
|
|
2532
|
+
ws: this._createSocket(input),
|
|
2533
|
+
formatMessage: this.options.formatMessage,
|
|
2534
|
+
updateRunConfig: this.options.updateRunConfig
|
|
2283
2535
|
}
|
|
2284
|
-
}))
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
});
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
forDomain(domain) {
|
|
2297
|
-
this.actionRouter.forDomain(domain, true);
|
|
2298
|
-
return this;
|
|
2299
|
-
}
|
|
2300
|
-
forAction(action) {
|
|
2301
|
-
this.actionRouter.forAction(action, true);
|
|
2302
|
-
return this;
|
|
2303
|
-
}
|
|
2304
|
-
forActionIds(domain, ids) {
|
|
2305
|
-
this.actionRouter.forActionIds(domain, ids, true);
|
|
2306
|
-
return this;
|
|
2307
|
-
}
|
|
2308
|
-
_setIncomingActionDataListener(listener) {
|
|
2309
|
-
this._incomingActionDataListeners.push(listener);
|
|
2310
|
-
}
|
|
2311
|
-
async handleActionRequest(action, config) {
|
|
2312
|
-
const localRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
2313
|
-
const localClient = localRuntime.coordinate;
|
|
2314
|
-
const incomingTimeout = config?.timeout ?? this._defaultTimeout;
|
|
2315
|
-
const parentCuid = peekHandlerCuid();
|
|
2316
|
-
const callSite = action._callSite ?? new Error().stack;
|
|
2317
|
-
const { methods, transport } = await this.transportManager.getReadyTransport({
|
|
2318
|
-
action,
|
|
2319
|
-
localClient,
|
|
2320
|
-
externalClient: this.externalClient
|
|
2321
|
-
});
|
|
2322
|
-
action.context.addRouteItem({
|
|
2323
|
-
runtime: localClient,
|
|
2324
|
-
handler: this.toHandlerRouteItem(transport),
|
|
2325
|
-
time: Date.now()
|
|
2326
|
-
});
|
|
2327
|
-
const runningAction = new RunningAction({
|
|
2328
|
-
context: action.context,
|
|
2329
|
-
request: action,
|
|
2330
|
-
parentCuid,
|
|
2331
|
-
callSite
|
|
2332
|
-
});
|
|
2333
|
-
localRuntime.registerRunningAction(runningAction);
|
|
2334
|
-
const routeActionParams = {
|
|
2335
|
-
action,
|
|
2336
|
-
runningAction,
|
|
2337
|
-
localClient,
|
|
2338
|
-
externalClient: this.externalClient,
|
|
2339
|
-
timeout: incomingTimeout
|
|
2340
|
-
};
|
|
2341
|
-
if (action.type === "request" /* request */ && methods.updateRunConfig != null) {
|
|
2342
|
-
const runConfig = methods.updateRunConfig(routeActionParams);
|
|
2343
|
-
routeActionParams.timeout = runConfig?.timeout ?? incomingTimeout;
|
|
2344
|
-
}
|
|
2345
|
-
try {
|
|
2346
|
-
methods.sendActionData(routeActionParams);
|
|
2347
|
-
} catch (err4) {
|
|
2348
|
-
runningAction._abort(err4);
|
|
2349
|
-
}
|
|
2350
|
-
return runningAction;
|
|
2351
|
-
}
|
|
2352
|
-
async sendReturnPayload(payload, config) {
|
|
2353
|
-
const localClient = config.targetLocalRuntime.coordinate;
|
|
2354
|
-
try {
|
|
2355
|
-
const { methods } = await this.transportManager.getReadyTransport({
|
|
2356
|
-
action: payload,
|
|
2357
|
-
localClient,
|
|
2358
|
-
externalClient: this.externalClient
|
|
2359
|
-
});
|
|
2360
|
-
if (methods.sendReturnData == null)
|
|
2361
|
-
return false;
|
|
2362
|
-
methods.sendReturnData(payload);
|
|
2363
|
-
return true;
|
|
2364
|
-
} catch {
|
|
2365
|
-
return false;
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
toJsonObject() {
|
|
2536
|
+
}))
|
|
2537
|
+
})
|
|
2538
|
+
}, ctx.resolvers);
|
|
2539
|
+
}
|
|
2540
|
+
getRouteInfo(input) {
|
|
2541
|
+
if (this.options.getRouteInfo != null)
|
|
2542
|
+
return this.options.getRouteInfo(input);
|
|
2543
|
+
const url = this.options.url != null ? resolveMaybe2(this.options.url, input) : undefined;
|
|
2369
2544
|
return {
|
|
2370
|
-
type:
|
|
2371
|
-
|
|
2545
|
+
type: "ws" /* ws */,
|
|
2546
|
+
url,
|
|
2547
|
+
summary: url != null ? `ws ${shortWs(url)}` : "ws"
|
|
2372
2548
|
};
|
|
2373
2549
|
}
|
|
2374
|
-
toHandlerRouteItem(transport) {
|
|
2375
|
-
return {
|
|
2376
|
-
type: this.handlerType,
|
|
2377
|
-
client: this.externalClient,
|
|
2378
|
-
transOrd: transport.transOrd,
|
|
2379
|
-
transType: transport.type
|
|
2380
|
-
};
|
|
2381
|
-
}
|
|
2382
|
-
clearTransportCache() {
|
|
2383
|
-
this._transportCache.clear();
|
|
2384
|
-
}
|
|
2385
2550
|
}
|
|
2386
|
-
var createExternalClientHandler = (config) => {
|
|
2387
|
-
return new ActionExternalClientHandler(config);
|
|
2388
|
-
};
|
|
2389
2551
|
export {
|
|
2390
2552
|
isActionPayload_Result_JsonObject,
|
|
2391
2553
|
isActionPayload_Request_JsonObject,
|
|
@@ -2398,11 +2560,11 @@ export {
|
|
|
2398
2560
|
createExternalClientHandler,
|
|
2399
2561
|
createActionRootDomain,
|
|
2400
2562
|
actionSchema,
|
|
2401
|
-
|
|
2402
|
-
TransportHttp,
|
|
2563
|
+
WebSocketTransport,
|
|
2403
2564
|
Transport,
|
|
2404
2565
|
RuntimeCoordinate,
|
|
2405
2566
|
RunningAction,
|
|
2567
|
+
HttpTransport,
|
|
2406
2568
|
ETransportType,
|
|
2407
2569
|
ETransportStatus,
|
|
2408
2570
|
ERunningActionUpdateType,
|
|
@@ -2413,6 +2575,7 @@ export {
|
|
|
2413
2575
|
EErrId_NiceAction,
|
|
2414
2576
|
EActionProgressType,
|
|
2415
2577
|
EActionPayloadType,
|
|
2578
|
+
CustomTransport,
|
|
2416
2579
|
ActionSchema,
|
|
2417
2580
|
ActionRuntime,
|
|
2418
2581
|
ActionRootDomain,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TInferActionError } from "../../..";
|
|
2
2
|
import type { IActionHandler_ExternalClient_Json, IActionHandler_Local_Json } from "../../../ActionRuntime/Handler/ActionHandler.types";
|
|
3
|
-
import type { ETransportType } from "../../../ActionRuntime/Handler/ExternalClient/Transport/Transport.types";
|
|
3
|
+
import type { ETransportType, ITransportRouteInfo } from "../../../ActionRuntime/Handler/ExternalClient/Transport/Transport.types";
|
|
4
4
|
import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../Domain/ActionDomain.types";
|
|
5
5
|
import type { EActionForm, IActionBase, IActionBase_JsonObject } from "../ActionBase.types";
|
|
6
6
|
import type { ActionContext } from "../Context/ActionContext";
|
|
@@ -25,6 +25,7 @@ export interface IActionPayload_Base<DT extends EActionPayloadType, DOM extends
|
|
|
25
25
|
export type IActionRouteItemHandler = IActionHandler_Local_Json | (IActionHandler_ExternalClient_Json & {
|
|
26
26
|
transType: ETransportType;
|
|
27
27
|
transOrd: number;
|
|
28
|
+
transInfo?: ITransportRouteInfo;
|
|
28
29
|
});
|
|
29
30
|
/**
|
|
30
31
|
* [ ]
|
|
@@ -10,7 +10,8 @@ import { RuntimeCoordinate } from "../../RuntimeCoordinate";
|
|
|
10
10
|
import { ActionHandler } from "../ActionHandler";
|
|
11
11
|
import { EActionHandlerType, type IActionHandler_ExternalClient, type IActionHandler_ExternalClient_Json, type IHandleActionOptions } from "../ActionHandler.types";
|
|
12
12
|
import type { IActionExternalClientRequestHandlerConfig } from "./ActionExternalClientHandler.types";
|
|
13
|
-
import type
|
|
13
|
+
import { type ITransportRouteActionParams } from "./Transport/Transport.types";
|
|
14
|
+
import type { TransportConnection } from "./Transport/TransportConnection";
|
|
14
15
|
export declare class ActionExternalClientHandler extends ActionHandler<EActionHandlerType.external> implements IActionHandler_ExternalClient {
|
|
15
16
|
readonly externalClient: RuntimeCoordinate;
|
|
16
17
|
readonly handlerType = EActionHandlerType.external;
|
|
@@ -20,7 +21,7 @@ export declare class ActionExternalClientHandler extends ActionHandler<EActionHa
|
|
|
20
21
|
private transportManager;
|
|
21
22
|
private _incomingActionDataListeners;
|
|
22
23
|
readonly actionRouter: ActionRouter<true>;
|
|
23
|
-
constructor({ externalClientSpecifier, transports, defaultTimeout, }: IActionExternalClientRequestHandlerConfig);
|
|
24
|
+
constructor({ runtimeCoordinate: externalClientSpecifier, transports, defaultTimeout, }: IActionExternalClientRequestHandlerConfig);
|
|
24
25
|
forDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>): this;
|
|
25
26
|
forAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(action: ActionCore<ACT_DOM, ID>): this;
|
|
26
27
|
forActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actionSchema"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS): this;
|
|
@@ -37,7 +38,7 @@ export declare class ActionExternalClientHandler extends ActionHandler<EActionHa
|
|
|
37
38
|
targetLocalRuntime: ActionRuntime;
|
|
38
39
|
}): Promise<boolean>;
|
|
39
40
|
toJsonObject(): IActionHandler_ExternalClient_Json;
|
|
40
|
-
toHandlerRouteItem(transport:
|
|
41
|
+
toHandlerRouteItem(transport: TransportConnection, input: ITransportRouteActionParams): IActionRouteItemHandler;
|
|
41
42
|
clearTransportCache(): void;
|
|
42
43
|
}
|
|
43
44
|
export declare const createExternalClientHandler: (config: IActionExternalClientRequestHandlerConfig) => ActionExternalClientHandler;
|
package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RuntimeCoordinate } from "../../RuntimeCoordinate";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Transport } from "./Transport/Transport";
|
|
3
3
|
export interface IActionExternalClientRequestHandlerConfig {
|
|
4
4
|
defaultTimeout?: number;
|
|
5
|
-
|
|
6
|
-
transports:
|
|
5
|
+
runtimeCoordinate: RuntimeCoordinate;
|
|
6
|
+
transports: Transport[];
|
|
7
7
|
}
|
package/build/types/ActionRuntime/Handler/ExternalClient/Transport/ConnectionTransportManager.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Transport } from "./Transport";
|
|
2
1
|
import { type IActionTransportReady, type ITransportRouteActionParams, type TTransportCache } from "./Transport.types";
|
|
2
|
+
import type { TransportConnection } from "./TransportConnection";
|
|
3
3
|
export declare class ConnectionTransportManager {
|
|
4
4
|
private _cache;
|
|
5
5
|
private _transports;
|
|
6
6
|
constructor(_cache: TTransportCache);
|
|
7
|
-
addTransport(transport:
|
|
7
|
+
addTransport(transport: TransportConnection): void;
|
|
8
8
|
getReadyTransport(routeActionParams: ITransportRouteActionParams): Promise<IActionTransportReady>;
|
|
9
9
|
}
|