@roj-ai/client 0.1.4 → 0.1.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/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/platform/errors.d.ts +1 -1
- package/dist/platform/errors.d.ts.map +1 -1
- package/dist/platform/index.d.ts +18 -18
- package/dist/platform/index.d.ts.map +1 -1
- package/dist/platform/index.js +8 -8
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/instance-methods.d.ts +15 -15
- package/dist/platform/instance-methods.d.ts.map +1 -1
- package/dist/platform/instance-methods.js +1 -1
- package/dist/platform/instance-methods.js.map +1 -1
- package/dist/platform/methods.d.ts +52 -18
- package/dist/platform/methods.d.ts.map +1 -1
- package/dist/platform/methods.js +3 -1
- package/dist/platform/methods.js.map +1 -1
- package/dist/platform/rest-client.d.ts +25 -1
- package/dist/platform/rest-client.d.ts.map +1 -1
- package/dist/platform/rest-client.js +60 -2
- package/dist/platform/rest-client.js.map +1 -1
- package/dist/platform/rpc-client.d.ts +1 -1
- package/dist/platform/rpc-client.d.ts.map +1 -1
- package/dist/platform/rpc-server.d.ts +1 -1
- package/dist/platform/rpc-server.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +3 -3
- package/src/platform/errors.ts +1 -1
- package/src/platform/index.ts +18 -18
- package/src/platform/instance-methods.ts +2 -2
- package/src/platform/methods.ts +45 -2
- package/src/platform/rest-client.ts +96 -5
- package/src/platform/rpc-client.ts +1 -1
- package/src/platform/rpc-server.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Vanilla TypeScript client for the roj agent server. No React — React hooks
|
|
5
5
|
* and chat components live in `@roj-ai/client-react`.
|
|
6
6
|
*/
|
|
7
|
-
export { api, configureApiBaseUrl, createApiClient, getApiBaseUrl, configureProjectId, RpcClient, RpcError, useApiError, } from './api/client';
|
|
8
|
-
export type { ApiClient } from './api/client';
|
|
9
|
-
export { unwrap } from './api/unwrap';
|
|
7
|
+
export { api, configureApiBaseUrl, createApiClient, getApiBaseUrl, configureProjectId, RpcClient, RpcError, useApiError, } from './api/client.js';
|
|
8
|
+
export type { ApiClient } from './api/client.js';
|
|
9
|
+
export { unwrap } from './api/unwrap.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,GAAG,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,WAAW,GACX,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,GAAG,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,WAAW,GACX,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* Vanilla TypeScript client for the roj agent server. No React — React hooks
|
|
5
5
|
* and chat components live in `@roj-ai/client-react`.
|
|
6
6
|
*/
|
|
7
|
-
export { api, configureApiBaseUrl, createApiClient, getApiBaseUrl, configureProjectId, RpcClient, RpcError, useApiError, } from './api/client';
|
|
8
|
-
export { unwrap } from './api/unwrap';
|
|
7
|
+
export { api, configureApiBaseUrl, createApiClient, getApiBaseUrl, configureProjectId, RpcClient, RpcError, useApiError, } from './api/client.js';
|
|
8
|
+
export { unwrap } from './api/unwrap.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,GAAG,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,WAAW,GACX,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,GAAG,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,WAAW,GACX,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/platform/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/platform/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,qBAAa,WAAY,SAAQ,KAAK;aAGT,KAAK,EAAE,QAAQ;IAF3C,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAEA,KAAK,EAAE,QAAQ;CAK3C"}
|
package/dist/platform/index.d.ts
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
* Client SDK for the roj platform REST API. Works against both the full
|
|
5
5
|
* platform (Cloudflare worker) and the standalone server.
|
|
6
6
|
*/
|
|
7
|
-
export { defineMethods, method } from './rpc-definition';
|
|
8
|
-
export type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse, RpcError } from './rpc-definition';
|
|
9
|
-
export { createRpcClient } from './rpc-client';
|
|
10
|
-
export type { RpcClient, RpcClientOptions, RpcResult } from './rpc-client';
|
|
11
|
-
export { createRpcRouter } from './rpc-server';
|
|
12
|
-
export type { RpcRouter, MethodHandler, MethodHandlers } from './rpc-server';
|
|
13
|
-
export { platformMethods } from './methods';
|
|
14
|
-
export type { PlatformMethods, PlatformMethodName } from './methods';
|
|
15
|
-
export type * from './methods';
|
|
16
|
-
export { instanceMethods } from './instance-methods';
|
|
17
|
-
export type { InstanceMethods, InstanceMethodName } from './instance-methods';
|
|
18
|
-
export type * from './instance-methods';
|
|
19
|
-
export type { SandboxState } from './sandbox-state';
|
|
20
|
-
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls';
|
|
21
|
-
export type { BuildPreviewUrlOptions, BuildWsUrlOptions } from './urls';
|
|
22
|
-
export { createRojClient } from './rest-client';
|
|
23
|
-
export type { RojClient, RojClientOptions } from './rest-client';
|
|
24
|
-
export { RojApiError } from './errors';
|
|
7
|
+
export { defineMethods, method } from './rpc-definition.js';
|
|
8
|
+
export type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse, RpcError } from './rpc-definition.js';
|
|
9
|
+
export { createRpcClient } from './rpc-client.js';
|
|
10
|
+
export type { RpcClient, RpcClientOptions, RpcResult } from './rpc-client.js';
|
|
11
|
+
export { createRpcRouter } from './rpc-server.js';
|
|
12
|
+
export type { RpcRouter, MethodHandler, MethodHandlers } from './rpc-server.js';
|
|
13
|
+
export { platformMethods } from './methods.js';
|
|
14
|
+
export type { PlatformMethods, PlatformMethodName } from './methods.js';
|
|
15
|
+
export type * from './methods.js';
|
|
16
|
+
export { instanceMethods } from './instance-methods.js';
|
|
17
|
+
export type { InstanceMethods, InstanceMethodName } from './instance-methods.js';
|
|
18
|
+
export type * from './instance-methods.js';
|
|
19
|
+
export type { SandboxState } from './sandbox-state.js';
|
|
20
|
+
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls.js';
|
|
21
|
+
export type { BuildPreviewUrlOptions, BuildWsUrlOptions } from './urls.js';
|
|
22
|
+
export { createRojClient } from './rest-client.js';
|
|
23
|
+
export type { RojClient, RojClientOptions, SessionRpcInput } from './rest-client.js';
|
|
24
|
+
export { RojApiError } from './errors.js';
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC3D,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACvE,mBAAmB,cAAc,CAAA;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAChF,mBAAmB,uBAAuB,CAAA;AAG1C,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AACzF,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGpF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/platform/index.js
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* platform (Cloudflare worker) and the standalone server.
|
|
6
6
|
*/
|
|
7
7
|
// Generic RPC framework
|
|
8
|
-
export { defineMethods, method } from './rpc-definition';
|
|
9
|
-
export { createRpcClient } from './rpc-client';
|
|
10
|
-
export { createRpcRouter } from './rpc-server';
|
|
8
|
+
export { defineMethods, method } from './rpc-definition.js';
|
|
9
|
+
export { createRpcClient } from './rpc-client.js';
|
|
10
|
+
export { createRpcRouter } from './rpc-server.js';
|
|
11
11
|
// Platform method contracts
|
|
12
|
-
export { platformMethods } from './methods';
|
|
13
|
-
export { instanceMethods } from './instance-methods';
|
|
12
|
+
export { platformMethods } from './methods.js';
|
|
13
|
+
export { instanceMethods } from './instance-methods.js';
|
|
14
14
|
// URL builders
|
|
15
|
-
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls';
|
|
15
|
+
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls.js';
|
|
16
16
|
// REST client
|
|
17
|
-
export { createRojClient } from './rest-client';
|
|
17
|
+
export { createRojClient } from './rest-client.js';
|
|
18
18
|
// Errors
|
|
19
|
-
export { RojApiError } from './errors';
|
|
19
|
+
export { RojApiError } from './errors.js';
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAwB;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAwB;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,4BAA4B;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAI9C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAOvD,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAGzF,cAAc;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGlD,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublishSessionOutput, GetAgentLogsOutput } from './methods';
|
|
1
|
+
import type { PublishSessionOutput, GetAgentLogsOutput } from './methods.js';
|
|
2
2
|
export type InstanceCreateSandboxInput = {};
|
|
3
3
|
export interface InstanceCreateSandboxOutput {
|
|
4
4
|
sandboxId: string;
|
|
@@ -75,20 +75,20 @@ export interface InstanceOkOutput {
|
|
|
75
75
|
ok: boolean;
|
|
76
76
|
}
|
|
77
77
|
export declare const instanceMethods: {
|
|
78
|
-
createSandbox: import("./rpc-definition").MethodDef<InstanceCreateSandboxInput, InstanceCreateSandboxOutput>;
|
|
79
|
-
pauseSandbox: import("./rpc-definition").MethodDef<InstancePauseSandboxInput, InstanceOkOutput>;
|
|
80
|
-
resumeSandbox: import("./rpc-definition").MethodDef<InstanceResumeSandboxInput, InstanceOkOutput>;
|
|
81
|
-
terminateSandbox: import("./rpc-definition").MethodDef<InstanceTerminateSandboxInput, InstanceOkOutput>;
|
|
82
|
-
restartAgent: import("./rpc-definition").MethodDef<InstanceRestartAgentInput, InstanceOkOutput>;
|
|
83
|
-
getAgentLogs: import("./rpc-definition").MethodDef<InstanceGetAgentLogsInput, GetAgentLogsOutput>;
|
|
84
|
-
execInSandbox: import("./rpc-definition").MethodDef<InstanceExecInSandboxInput, InstanceExecInSandboxOutput>;
|
|
85
|
-
validateSandboxToken: import("./rpc-definition").MethodDef<InstanceValidateSandboxTokenInput, InstanceValidateSandboxTokenOutput>;
|
|
86
|
-
createSession: import("./rpc-definition").MethodDef<InstanceCreateSessionInput, InstanceCreateSessionOutput>;
|
|
87
|
-
listSessions: import("./rpc-definition").MethodDef<InstanceListSessionsInput, InstanceListSessionsOutput>;
|
|
88
|
-
publishSession: import("./rpc-definition").MethodDef<InstancePublishSessionInput, PublishSessionOutput>;
|
|
89
|
-
getServiceUrl: import("./rpc-definition").MethodDef<InstanceGetServiceUrlInput, InstanceGetServiceUrlOutput>;
|
|
90
|
-
getServiceUrls: import("./rpc-definition").MethodDef<InstanceGetServiceUrlsInput, InstanceGetServiceUrlsOutput>;
|
|
91
|
-
ensureSandbox: import("./rpc-definition").MethodDef<{}, InstanceEnsureSandboxOutput>;
|
|
78
|
+
createSandbox: import("./rpc-definition.js").MethodDef<InstanceCreateSandboxInput, InstanceCreateSandboxOutput>;
|
|
79
|
+
pauseSandbox: import("./rpc-definition.js").MethodDef<InstancePauseSandboxInput, InstanceOkOutput>;
|
|
80
|
+
resumeSandbox: import("./rpc-definition.js").MethodDef<InstanceResumeSandboxInput, InstanceOkOutput>;
|
|
81
|
+
terminateSandbox: import("./rpc-definition.js").MethodDef<InstanceTerminateSandboxInput, InstanceOkOutput>;
|
|
82
|
+
restartAgent: import("./rpc-definition.js").MethodDef<InstanceRestartAgentInput, InstanceOkOutput>;
|
|
83
|
+
getAgentLogs: import("./rpc-definition.js").MethodDef<InstanceGetAgentLogsInput, GetAgentLogsOutput>;
|
|
84
|
+
execInSandbox: import("./rpc-definition.js").MethodDef<InstanceExecInSandboxInput, InstanceExecInSandboxOutput>;
|
|
85
|
+
validateSandboxToken: import("./rpc-definition.js").MethodDef<InstanceValidateSandboxTokenInput, InstanceValidateSandboxTokenOutput>;
|
|
86
|
+
createSession: import("./rpc-definition.js").MethodDef<InstanceCreateSessionInput, InstanceCreateSessionOutput>;
|
|
87
|
+
listSessions: import("./rpc-definition.js").MethodDef<InstanceListSessionsInput, InstanceListSessionsOutput>;
|
|
88
|
+
publishSession: import("./rpc-definition.js").MethodDef<InstancePublishSessionInput, PublishSessionOutput>;
|
|
89
|
+
getServiceUrl: import("./rpc-definition.js").MethodDef<InstanceGetServiceUrlInput, InstanceGetServiceUrlOutput>;
|
|
90
|
+
getServiceUrls: import("./rpc-definition.js").MethodDef<InstanceGetServiceUrlsInput, InstanceGetServiceUrlsOutput>;
|
|
91
|
+
ensureSandbox: import("./rpc-definition.js").MethodDef<{}, InstanceEnsureSandboxOutput>;
|
|
92
92
|
};
|
|
93
93
|
export type InstanceMethods = typeof instanceMethods;
|
|
94
94
|
export type InstanceMethodName = keyof InstanceMethods;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance-methods.d.ts","sourceRoot":"","sources":["../../src/platform/instance-methods.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"instance-methods.d.ts","sourceRoot":"","sources":["../../src/platform/instance-methods.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAM5E,MAAM,MAAM,0BAA0B,GAAG,EAAE,CAAA;AAC3C,MAAM,WAAW,2BAA2B;IAC3C,SAAS,EAAE,MAAM,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A2B;IAC3C,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAClB;AAED,MAAM,WAAW,2BAA2B;IAC3C,SAAS,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC5C,QAAQ,EAAE,KAAK,CAAC;QACf,WAAW,EAAE,MAAM,CAAA;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACZ,CAAC,CAAA;CACF;AAED,MAAM,WAAW,2BAA2B;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACb;AAMD,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,OAAO,CAAA;CACX;AAMD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;CAsB1B,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAA;AACpD,MAAM,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAA"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Shared between worker (server) and client SDK.
|
|
9
9
|
*/
|
|
10
|
-
import { defineMethods, method } from './rpc-definition';
|
|
10
|
+
import { defineMethods, method } from './rpc-definition.js';
|
|
11
11
|
// ============================================================================
|
|
12
12
|
// Method registry
|
|
13
13
|
// ============================================================================
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance-methods.js","sourceRoot":"","sources":["../../src/platform/instance-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"instance-methods.js","sourceRoot":"","sources":["../../src/platform/instance-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAkH3D,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;IAC5C,UAAU;IACV,aAAa,EAAE,MAAM,EAA2D;IAChF,YAAY,EAAE,MAAM,EAA+C;IACnE,aAAa,EAAE,MAAM,EAAgD;IACrE,gBAAgB,EAAE,MAAM,EAAmD;IAC3E,YAAY,EAAE,MAAM,EAA+C;IACnE,YAAY,EAAE,MAAM,EAAiD;IACrE,aAAa,EAAE,MAAM,EAA2D;IAChF,oBAAoB,EAAE,MAAM,EAAyE;IAErG,WAAW;IACX,aAAa,EAAE,MAAM,EAA2D;IAChF,YAAY,EAAE,MAAM,EAAyD;IAC7E,cAAc,EAAE,MAAM,EAAqD;IAE3E,WAAW;IACX,aAAa,EAAE,MAAM,EAA2D;IAChF,cAAc,EAAE,MAAM,EAA6D;IAEnF,4BAA4B;IAC5B,aAAa,EAAE,MAAM,EAAmC;CACxD,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SandboxState } from './sandbox-state';
|
|
1
|
+
import type { SandboxState } from './sandbox-state.js';
|
|
2
2
|
export interface CreateInstanceInput {
|
|
3
3
|
templateSlug: string;
|
|
4
4
|
bundleSlug?: string;
|
|
@@ -115,10 +115,22 @@ export interface CreateInstanceTokenInput {
|
|
|
115
115
|
origin?: string;
|
|
116
116
|
expiresIn?: number;
|
|
117
117
|
meta?: Record<string, unknown>;
|
|
118
|
+
/**
|
|
119
|
+
* Service codes (e.g. ['dev']) for which the platform should also build a
|
|
120
|
+
* ready-to-use preview URL with the freshly minted token baked in.
|
|
121
|
+
* Saves callers from having to know `baseDomain` or compose the URL.
|
|
122
|
+
*/
|
|
123
|
+
previewServiceCodes?: string[];
|
|
118
124
|
}
|
|
119
125
|
export interface CreateInstanceTokenOutput {
|
|
120
126
|
token: string;
|
|
121
127
|
expiresAt: string;
|
|
128
|
+
/**
|
|
129
|
+
* Preview URLs keyed by service code, populated when `previewServiceCodes`
|
|
130
|
+
* was set on the request. Each URL carries the token in `?token=` and is
|
|
131
|
+
* suitable for direct use as an iframe `src`.
|
|
132
|
+
*/
|
|
133
|
+
previewUrls?: Record<string, string>;
|
|
122
134
|
}
|
|
123
135
|
export interface ListBundlesInput {
|
|
124
136
|
limit?: number;
|
|
@@ -237,24 +249,46 @@ export interface GetServiceUrlInput {
|
|
|
237
249
|
export interface GetServiceUrlOutput {
|
|
238
250
|
url: string | null;
|
|
239
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Which file namespace inside the session to read from.
|
|
254
|
+
* - `workspace` — the user-facing workspace dir produced by session plugins (e.g. `dist/Course.zip`).
|
|
255
|
+
* - `session` — internal session storage under the SDK's `dataPath/sessions/{sessionId}`.
|
|
256
|
+
*/
|
|
257
|
+
export type SessionFileScope = 'workspace' | 'session';
|
|
258
|
+
export interface CreateSessionFileDownloadUrlInput {
|
|
259
|
+
instanceId: string;
|
|
260
|
+
sessionId: string;
|
|
261
|
+
scope: SessionFileScope;
|
|
262
|
+
/** Scope-relative path (no leading slash). Path traversal (`..`) is rejected. */
|
|
263
|
+
path: string;
|
|
264
|
+
/** TTL in seconds. Default 300, max 3600. */
|
|
265
|
+
ttlSeconds?: number;
|
|
266
|
+
}
|
|
267
|
+
export interface CreateSessionFileDownloadUrlOutput {
|
|
268
|
+
/** Signed, time-limited URL serving the file's bytes. */
|
|
269
|
+
url: string;
|
|
270
|
+
/** ISO 8601 expiry of the signed URL. */
|
|
271
|
+
expiresAt: string;
|
|
272
|
+
}
|
|
240
273
|
export declare const platformMethods: {
|
|
241
|
-
'instances.create': import("./rpc-definition").MethodDef<CreateInstanceInput, CreateInstanceOutput>;
|
|
242
|
-
'instances.get': import("./rpc-definition").MethodDef<GetInstanceInput, GetInstanceOutput>;
|
|
243
|
-
'instances.list': import("./rpc-definition").MethodDef<ListInstancesInput, ListInstancesOutput>;
|
|
244
|
-
'instances.status': import("./rpc-definition").MethodDef<GetInstanceStatusInput, GetInstanceStatusOutput>;
|
|
245
|
-
'instances.archive': import("./rpc-definition").MethodDef<ArchiveInstanceInput, ArchiveInstanceOutput>;
|
|
246
|
-
'sessions.create': import("./rpc-definition").MethodDef<CreateSessionInput, CreateSessionOutput>;
|
|
247
|
-
'sessions.list': import("./rpc-definition").MethodDef<ListSessionsInput, ListSessionsOutput>;
|
|
248
|
-
'sessions.publish': import("./rpc-definition").MethodDef<PublishSessionInput, PublishSessionOutput>;
|
|
249
|
-
'tokens.create': import("./rpc-definition").MethodDef<CreateInstanceTokenInput, CreateInstanceTokenOutput>;
|
|
250
|
-
'services.getUrl': import("./rpc-definition").MethodDef<GetServiceUrlInput, GetServiceUrlOutput>;
|
|
251
|
-
'
|
|
252
|
-
'bundles.
|
|
253
|
-
'
|
|
254
|
-
'resources.
|
|
255
|
-
'resources.
|
|
256
|
-
'resources.
|
|
257
|
-
'resources.
|
|
274
|
+
'instances.create': import("./rpc-definition.js").MethodDef<CreateInstanceInput, CreateInstanceOutput>;
|
|
275
|
+
'instances.get': import("./rpc-definition.js").MethodDef<GetInstanceInput, GetInstanceOutput>;
|
|
276
|
+
'instances.list': import("./rpc-definition.js").MethodDef<ListInstancesInput, ListInstancesOutput>;
|
|
277
|
+
'instances.status': import("./rpc-definition.js").MethodDef<GetInstanceStatusInput, GetInstanceStatusOutput>;
|
|
278
|
+
'instances.archive': import("./rpc-definition.js").MethodDef<ArchiveInstanceInput, ArchiveInstanceOutput>;
|
|
279
|
+
'sessions.create': import("./rpc-definition.js").MethodDef<CreateSessionInput, CreateSessionOutput>;
|
|
280
|
+
'sessions.list': import("./rpc-definition.js").MethodDef<ListSessionsInput, ListSessionsOutput>;
|
|
281
|
+
'sessions.publish': import("./rpc-definition.js").MethodDef<PublishSessionInput, PublishSessionOutput>;
|
|
282
|
+
'tokens.create': import("./rpc-definition.js").MethodDef<CreateInstanceTokenInput, CreateInstanceTokenOutput>;
|
|
283
|
+
'services.getUrl': import("./rpc-definition.js").MethodDef<GetServiceUrlInput, GetServiceUrlOutput>;
|
|
284
|
+
'sessionFiles.createDownloadUrl': import("./rpc-definition.js").MethodDef<CreateSessionFileDownloadUrlInput, CreateSessionFileDownloadUrlOutput>;
|
|
285
|
+
'bundles.list': import("./rpc-definition.js").MethodDef<ListBundlesInput, ListBundlesOutput>;
|
|
286
|
+
'bundles.delete': import("./rpc-definition.js").MethodDef<DeleteBundleInput, DeleteBundleOutput>;
|
|
287
|
+
'resources.create': import("./rpc-definition.js").MethodDef<CreateResourceInput, CreateResourceOutput>;
|
|
288
|
+
'resources.addRevision': import("./rpc-definition.js").MethodDef<AddResourceRevisionInput, AddResourceRevisionOutput>;
|
|
289
|
+
'resources.get': import("./rpc-definition.js").MethodDef<GetResourceInput, GetResourceOutput>;
|
|
290
|
+
'resources.list': import("./rpc-definition.js").MethodDef<ListResourcesInput, ListResourcesOutput>;
|
|
291
|
+
'resources.delete': import("./rpc-definition.js").MethodDef<DeleteResourceInput, DeleteResourceOutput>;
|
|
258
292
|
};
|
|
259
293
|
export type PlatformMethods = typeof platformMethods;
|
|
260
294
|
export type PlatformMethodName = keyof PlatformMethods;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../src/platform/methods.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../src/platform/methods.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAMtD,MAAM,WAAW,mBAAmB;IACnC,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAA;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,iBAAiB,CAAC,EAAE;QACnB,QAAQ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ClB;AAMD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAA;AAEtD,MAAM,WAAW,iCAAiC;IACjD,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,gBAAgB,CAAA;IACvB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAA;IACZ,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,kCAAkC;IAClD,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAA;IACX,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAA;CACjB;AAMD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;CAgC1B,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAA;AACpD,MAAM,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAA"}
|
package/dist/platform/methods.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Single source of truth for all platform API method types.
|
|
5
5
|
* Shared between worker (server) and client SDK.
|
|
6
6
|
*/
|
|
7
|
-
import { defineMethods, method } from './rpc-definition';
|
|
7
|
+
import { defineMethods, method } from './rpc-definition.js';
|
|
8
8
|
// ============================================================================
|
|
9
9
|
// Method registry
|
|
10
10
|
// ============================================================================
|
|
@@ -23,6 +23,8 @@ export const platformMethods = defineMethods({
|
|
|
23
23
|
'tokens.create': method(),
|
|
24
24
|
// Services
|
|
25
25
|
'services.getUrl': method(),
|
|
26
|
+
// Session files (signed-URL gateway in front of SDK's session/workspace + session/files routes)
|
|
27
|
+
'sessionFiles.createDownloadUrl': method(),
|
|
26
28
|
// Bundles
|
|
27
29
|
'bundles.list': method(),
|
|
28
30
|
'bundles.delete': method(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/platform/methods.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/platform/methods.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAoV3D,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;IAC5C,YAAY;IACZ,kBAAkB,EAAE,MAAM,EAA6C;IACvE,eAAe,EAAE,MAAM,EAAuC;IAC9D,gBAAgB,EAAE,MAAM,EAA2C;IACnE,kBAAkB,EAAE,MAAM,EAAmD;IAC7E,mBAAmB,EAAE,MAAM,EAA+C;IAE1E,WAAW;IACX,iBAAiB,EAAE,MAAM,EAA2C;IACpE,eAAe,EAAE,MAAM,EAAyC;IAChE,kBAAkB,EAAE,MAAM,EAA6C;IAEvE,SAAS;IACT,eAAe,EAAE,MAAM,EAAuD;IAE9E,WAAW;IACX,iBAAiB,EAAE,MAAM,EAA2C;IAEpE,gGAAgG;IAChG,gCAAgC,EAAE,MAAM,EAAyE;IAEjH,UAAU;IACV,cAAc,EAAE,MAAM,EAAuC;IAC7D,gBAAgB,EAAE,MAAM,EAAyC;IAEjE,YAAY;IACZ,kBAAkB,EAAE,MAAM,EAA6C;IACvE,uBAAuB,EAAE,MAAM,EAAuD;IACtF,eAAe,EAAE,MAAM,EAAuC;IAC9D,gBAAgB,EAAE,MAAM,EAA2C;IACnE,kBAAkB,EAAE,MAAM,EAA6C;CACvE,CAAC,CAAA"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import type { CreateInstanceInput, CreateInstanceOutput, GetInstanceOutput, GetInstanceStatusOutput, ListInstancesInput, ListInstancesOutput, ArchiveInstanceOutput, CreateSessionInput, CreateSessionOutput, ListSessionsOutput, PublishSessionInput, PublishSessionOutput, CreateInstanceTokenInput, CreateInstanceTokenOutput, ListBundlesInput, ListBundlesOutput, DeleteBundleOutput, CreateResourceInput, CreateResourceOutput, AddResourceRevisionInput, AddResourceRevisionOutput, GetResourceInput, GetResourceOutput, ListResourcesInput, ListResourcesOutput, DeleteResourceOutput } from './methods';
|
|
1
|
+
import type { CreateInstanceInput, CreateInstanceOutput, GetInstanceOutput, GetInstanceStatusOutput, ListInstancesInput, ListInstancesOutput, ArchiveInstanceOutput, CreateSessionInput, CreateSessionOutput, ListSessionsOutput, PublishSessionInput, PublishSessionOutput, CreateInstanceTokenInput, CreateInstanceTokenOutput, CreateSessionFileDownloadUrlInput, CreateSessionFileDownloadUrlOutput, ListBundlesInput, ListBundlesOutput, DeleteBundleOutput, CreateResourceInput, CreateResourceOutput, AddResourceRevisionInput, AddResourceRevisionOutput, GetResourceInput, GetResourceOutput, ListResourcesInput, ListResourcesOutput, DeleteResourceOutput } from './methods.js';
|
|
2
2
|
export interface RojClientOptions {
|
|
3
3
|
/** Platform URL (e.g. https://roj.example.com) */
|
|
4
4
|
url: string;
|
|
5
5
|
/** Platform API key */
|
|
6
6
|
apiKey: string;
|
|
7
7
|
}
|
|
8
|
+
export interface SessionRpcInput {
|
|
9
|
+
instanceId: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
method: string;
|
|
12
|
+
input?: Record<string, unknown>;
|
|
13
|
+
}
|
|
8
14
|
export interface RojClient {
|
|
9
15
|
instances: {
|
|
10
16
|
create(input: CreateInstanceInput): Promise<CreateInstanceOutput>;
|
|
@@ -17,10 +23,28 @@ export interface RojClient {
|
|
|
17
23
|
create(input: CreateSessionInput): Promise<CreateSessionOutput>;
|
|
18
24
|
list(instanceId: string): Promise<ListSessionsOutput>;
|
|
19
25
|
publish(input: PublishSessionInput): Promise<PublishSessionOutput>;
|
|
26
|
+
/**
|
|
27
|
+
* Call a plugin/session RPC method on a running session.
|
|
28
|
+
*
|
|
29
|
+
* Auto-mints and caches an instance token; the cached token is reused until
|
|
30
|
+
* its expiry minus a small leeway. Suitable for server-to-server callers
|
|
31
|
+
* that don't have a browser cookie or pre-existing instance token.
|
|
32
|
+
*/
|
|
33
|
+
rpc<T = unknown>(input: SessionRpcInput): Promise<T>;
|
|
20
34
|
};
|
|
21
35
|
tokens: {
|
|
22
36
|
create(input: CreateInstanceTokenInput): Promise<CreateInstanceTokenOutput>;
|
|
23
37
|
};
|
|
38
|
+
sessionFiles: {
|
|
39
|
+
/**
|
|
40
|
+
* Mint a short-lived signed URL that streams the bytes of a session-bound file
|
|
41
|
+
* back to the caller. Use after a session plugin has produced an artifact
|
|
42
|
+
* (e.g. workspace `dist/Course.zip`) and the caller wants to fetch it without
|
|
43
|
+
* routing through the dev preview proxy. `scope` selects between the workspace
|
|
44
|
+
* dir and the SDK's session storage.
|
|
45
|
+
*/
|
|
46
|
+
createDownloadUrl(input: CreateSessionFileDownloadUrlInput): Promise<CreateSessionFileDownloadUrlOutput>;
|
|
47
|
+
};
|
|
24
48
|
bundles: {
|
|
25
49
|
list(input?: ListBundlesInput): Promise<ListBundlesOutput>;
|
|
26
50
|
delete(input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-client.d.ts","sourceRoot":"","sources":["../../src/platform/rest-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,MAAM,
|
|
1
|
+
{"version":3,"file":"rest-client.d.ts","sourceRoot":"","sources":["../../src/platform/rest-client.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CAAC,oBAAoB,CAAC,CAAA;QACjE,WAAW,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;QAChF,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;QACxD,IAAI,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;QAC9D,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;KACzD,CAAA;CACD;AAYD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAgHpE"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { createRpcClient } from './rpc-client';
|
|
2
|
-
import { RojApiError } from './errors';
|
|
1
|
+
import { createRpcClient } from './rpc-client.js';
|
|
2
|
+
import { RojApiError } from './errors.js';
|
|
3
|
+
// Re-mint instance tokens this many milliseconds before their server-stated expiry.
|
|
4
|
+
// Covers both clock skew between client and server and the latency of an in-flight
|
|
5
|
+
// session RPC that started just before expiry.
|
|
6
|
+
const TOKEN_REFRESH_LEEWAY_MS = 30000;
|
|
3
7
|
export function createRojClient(options) {
|
|
4
8
|
const rpc = createRpcClient(`${options.url}/api/v1`, {
|
|
5
9
|
headers: { Authorization: `Bearer ${options.apiKey}` },
|
|
@@ -10,6 +14,56 @@ export function createRojClient(options) {
|
|
|
10
14
|
throw new RojApiError(result.error);
|
|
11
15
|
return result.value;
|
|
12
16
|
}
|
|
17
|
+
const instanceTokenCache = new Map();
|
|
18
|
+
const inflightTokenMint = new Map();
|
|
19
|
+
async function getInstanceToken(instanceId) {
|
|
20
|
+
const cached = instanceTokenCache.get(instanceId);
|
|
21
|
+
if (cached && cached.expiresAtMs - TOKEN_REFRESH_LEEWAY_MS > Date.now()) {
|
|
22
|
+
return cached.token;
|
|
23
|
+
}
|
|
24
|
+
const inflight = inflightTokenMint.get(instanceId);
|
|
25
|
+
if (inflight)
|
|
26
|
+
return inflight;
|
|
27
|
+
const promise = (async () => {
|
|
28
|
+
try {
|
|
29
|
+
const fresh = await call('tokens.create', { instanceId });
|
|
30
|
+
instanceTokenCache.set(instanceId, {
|
|
31
|
+
token: fresh.token,
|
|
32
|
+
expiresAtMs: new Date(fresh.expiresAt).getTime(),
|
|
33
|
+
});
|
|
34
|
+
return fresh.token;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
inflightTokenMint.delete(instanceId);
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
inflightTokenMint.set(instanceId, promise);
|
|
41
|
+
return promise;
|
|
42
|
+
}
|
|
43
|
+
async function callSessionRpc(input, retriedAfter401 = false) {
|
|
44
|
+
const token = await getInstanceToken(input.instanceId);
|
|
45
|
+
const url = `${options.url}/api/v1/instances/${input.instanceId}/sessions/${input.sessionId}/rpc`;
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
Authorization: `Bearer ${token}`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({ method: input.method, input: input.input ?? {} }),
|
|
53
|
+
});
|
|
54
|
+
// Token may have been revoked or rotated server-side before its stated `expiresAt`.
|
|
55
|
+
// Evict the cache and retry once with a freshly minted token.
|
|
56
|
+
if (response.status === 401 && !retriedAfter401) {
|
|
57
|
+
instanceTokenCache.delete(input.instanceId);
|
|
58
|
+
return callSessionRpc(input, true);
|
|
59
|
+
}
|
|
60
|
+
const body = await response.json().catch(() => null);
|
|
61
|
+
if (!response.ok || !body || body.ok === false) {
|
|
62
|
+
const error = body?.error ?? { type: 'transport_error', message: `HTTP ${response.status}` };
|
|
63
|
+
throw new RojApiError(error);
|
|
64
|
+
}
|
|
65
|
+
return body.value;
|
|
66
|
+
}
|
|
13
67
|
return {
|
|
14
68
|
instances: {
|
|
15
69
|
create: (input) => call('instances.create', input),
|
|
@@ -22,10 +76,14 @@ export function createRojClient(options) {
|
|
|
22
76
|
create: (input) => call('sessions.create', input),
|
|
23
77
|
list: (instanceId) => call('sessions.list', { instanceId }),
|
|
24
78
|
publish: (input) => call('sessions.publish', input),
|
|
79
|
+
rpc: (input) => callSessionRpc(input),
|
|
25
80
|
},
|
|
26
81
|
tokens: {
|
|
27
82
|
create: (input) => call('tokens.create', input),
|
|
28
83
|
},
|
|
84
|
+
sessionFiles: {
|
|
85
|
+
createDownloadUrl: (input) => call('sessionFiles.createDownloadUrl', input),
|
|
86
|
+
},
|
|
29
87
|
bundles: {
|
|
30
88
|
list: (input) => call('bundles.list', input ?? {}),
|
|
31
89
|
delete: (input) => call('bundles.delete', input),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-client.js","sourceRoot":"","sources":["../../src/platform/rest-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rest-client.js","sourceRoot":"","sources":["../../src/platform/rest-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAiCjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAkEzC,oFAAoF;AACpF,mFAAmF;AACnF,+CAA+C;AAC/C,MAAM,uBAAuB,GAAG,KAAM,CAAA;AAOtC,MAAM,UAAU,eAAe,CAAC,OAAyB;IACxD,MAAM,GAAG,GAAG,eAAe,CAAkB,GAAG,OAAO,CAAC,GAAG,SAAS,EAAE;QACrE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,MAAM,EAAE,EAAE;KACtD,CAAC,CAAA;IAEF,KAAK,UAAU,IAAI,CAClB,MAAS,EACT,KAAsC;QAEtC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5C,IAAI,CAAC,MAAM,CAAC,EAAE;YA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I,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE,CAAC;YACpD,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,UAAU,EAAE,CAAC;SAChE;KACD,CAAA;AACF,CAAC"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* })
|
|
9
9
|
* const result = await client.call('instances.create', { ... })
|
|
10
10
|
*/
|
|
11
|
-
import type { MethodDef, MethodInput, MethodOutput, RpcError } from './rpc-definition';
|
|
11
|
+
import type { MethodDef, MethodInput, MethodOutput, RpcError } from './rpc-definition.js';
|
|
12
12
|
export interface RpcClientOptions {
|
|
13
13
|
headers?: Record<string, string>;
|
|
14
14
|
credentials?: RequestCredentials;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../src/platform/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../src/platform/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAe,MAAM,qBAAqB,CAAA;AAEtG,MAAM,WAAW,gBAAgB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,WAAW,CAAC,EAAE,kBAAkB,CAAA;CAChC;AAED,MAAM,WAAW,SAAS,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IACnE,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,OAAO,EACpC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,GAC5B,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC/C;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IACpB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAA;AAEjC,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACxE,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,gBAAgB,GACxB,SAAS,CAAC,OAAO,CAAC,CAmCpB"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* // In Hono route:
|
|
11
11
|
* app.post('/rpc', (c) => router.handle(c.req.json(), ctx))
|
|
12
12
|
*/
|
|
13
|
-
import type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse } from './rpc-definition';
|
|
13
|
+
import type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse } from './rpc-definition.js';
|
|
14
14
|
export type MethodHandler<Methods extends Record<string, MethodDef>, M extends keyof Methods, Ctx> = (input: MethodInput<Methods, M>, ctx: Ctx) => Promise<MethodOutput<Methods, M>>;
|
|
15
15
|
export type MethodHandlers<Methods extends Record<string, MethodDef>, Ctx> = {
|
|
16
16
|
[M in keyof Methods]: MethodHandler<Methods, M, Ctx>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-server.d.ts","sourceRoot":"","sources":["../../src/platform/rpc-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAY,UAAU,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rpc-server.d.ts","sourceRoot":"","sources":["../../src/platform/rpc-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAY,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAElH,MAAM,MAAM,aAAa,CACxB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,CAAC,SAAS,MAAM,OAAO,EACvB,GAAG,IACA,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;AAEnF,MAAM,MAAM,cAAc,CACzB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,GAAG,IACA;KACF,CAAC,IAAI,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC;CACpD,CAAA;AAED,MAAM,WAAW,SAAS,CAAC,GAAG;IAC7B,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;CAC3D;AAED,wBAAgB,eAAe,CAC9B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,GAAG,EAEH,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,cAAc,CAAC,OAAO,EAAE,GAAG,CAAC,GACpC,SAAS,CAAC,GAAG,CAAC,CAsBhB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roj-ai/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"type-check": "tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@roj-ai/shared": "^0.1.
|
|
43
|
+
"@roj-ai/shared": "^0.1.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,6 @@ export {
|
|
|
14
14
|
RpcClient,
|
|
15
15
|
RpcError,
|
|
16
16
|
useApiError,
|
|
17
|
-
} from './api/client'
|
|
18
|
-
export type { ApiClient } from './api/client'
|
|
19
|
-
export { unwrap } from './api/unwrap'
|
|
17
|
+
} from './api/client.js'
|
|
18
|
+
export type { ApiClient } from './api/client.js'
|
|
19
|
+
export { unwrap } from './api/unwrap.js'
|
package/src/platform/errors.ts
CHANGED
package/src/platform/index.ts
CHANGED
|
@@ -6,32 +6,32 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// Generic RPC framework
|
|
9
|
-
export { defineMethods, method } from './rpc-definition'
|
|
10
|
-
export type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse, RpcError } from './rpc-definition'
|
|
11
|
-
export { createRpcClient } from './rpc-client'
|
|
12
|
-
export type { RpcClient, RpcClientOptions, RpcResult } from './rpc-client'
|
|
13
|
-
export { createRpcRouter } from './rpc-server'
|
|
14
|
-
export type { RpcRouter, MethodHandler, MethodHandlers } from './rpc-server'
|
|
9
|
+
export { defineMethods, method } from './rpc-definition.js'
|
|
10
|
+
export type { MethodDef, MethodInput, MethodOutput, RpcRequest, RpcResponse, RpcError } from './rpc-definition.js'
|
|
11
|
+
export { createRpcClient } from './rpc-client.js'
|
|
12
|
+
export type { RpcClient, RpcClientOptions, RpcResult } from './rpc-client.js'
|
|
13
|
+
export { createRpcRouter } from './rpc-server.js'
|
|
14
|
+
export type { RpcRouter, MethodHandler, MethodHandlers } from './rpc-server.js'
|
|
15
15
|
|
|
16
16
|
// Platform method contracts
|
|
17
|
-
export { platformMethods } from './methods'
|
|
18
|
-
export type { PlatformMethods, PlatformMethodName } from './methods'
|
|
19
|
-
export type * from './methods'
|
|
17
|
+
export { platformMethods } from './methods.js'
|
|
18
|
+
export type { PlatformMethods, PlatformMethodName } from './methods.js'
|
|
19
|
+
export type * from './methods.js'
|
|
20
20
|
|
|
21
|
-
export { instanceMethods } from './instance-methods'
|
|
22
|
-
export type { InstanceMethods, InstanceMethodName } from './instance-methods'
|
|
23
|
-
export type * from './instance-methods'
|
|
21
|
+
export { instanceMethods } from './instance-methods.js'
|
|
22
|
+
export type { InstanceMethods, InstanceMethodName } from './instance-methods.js'
|
|
23
|
+
export type * from './instance-methods.js'
|
|
24
24
|
|
|
25
25
|
// Types
|
|
26
|
-
export type { SandboxState } from './sandbox-state'
|
|
26
|
+
export type { SandboxState } from './sandbox-state.js'
|
|
27
27
|
|
|
28
28
|
// URL builders
|
|
29
|
-
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls'
|
|
30
|
-
export type { BuildPreviewUrlOptions, BuildWsUrlOptions } from './urls'
|
|
29
|
+
export { buildPreviewUrl, buildWsUrl, buildApiBaseUrl, instanceIdToHex } from './urls.js'
|
|
30
|
+
export type { BuildPreviewUrlOptions, BuildWsUrlOptions } from './urls.js'
|
|
31
31
|
|
|
32
32
|
// REST client
|
|
33
|
-
export { createRojClient } from './rest-client'
|
|
34
|
-
export type { RojClient, RojClientOptions } from './rest-client'
|
|
33
|
+
export { createRojClient } from './rest-client.js'
|
|
34
|
+
export type { RojClient, RojClientOptions, SessionRpcInput } from './rest-client.js'
|
|
35
35
|
|
|
36
36
|
// Errors
|
|
37
|
-
export { RojApiError } from './errors'
|
|
37
|
+
export { RojApiError } from './errors.js'
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Shared between worker (server) and client SDK.
|
|
9
9
|
*/
|
|
10
|
-
import { defineMethods, method } from './rpc-definition'
|
|
11
|
-
import type { PublishSessionOutput, GetAgentLogsOutput } from './methods'
|
|
10
|
+
import { defineMethods, method } from './rpc-definition.js'
|
|
11
|
+
import type { PublishSessionOutput, GetAgentLogsOutput } from './methods.js'
|
|
12
12
|
|
|
13
13
|
// ============================================================================
|
|
14
14
|
// Sandbox methods
|
package/src/platform/methods.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Single source of truth for all platform API method types.
|
|
5
5
|
* Shared between worker (server) and client SDK.
|
|
6
6
|
*/
|
|
7
|
-
import { defineMethods, method } from './rpc-definition'
|
|
8
|
-
import type { SandboxState } from './sandbox-state'
|
|
7
|
+
import { defineMethods, method } from './rpc-definition.js'
|
|
8
|
+
import type { SandboxState } from './sandbox-state.js'
|
|
9
9
|
|
|
10
10
|
// ============================================================================
|
|
11
11
|
// Instance methods
|
|
@@ -151,11 +151,23 @@ export interface CreateInstanceTokenInput {
|
|
|
151
151
|
origin?: string
|
|
152
152
|
expiresIn?: number // token TTL in seconds (default 24h, max 7d)
|
|
153
153
|
meta?: Record<string, unknown> // custom claims propagated to plugin method caller context
|
|
154
|
+
/**
|
|
155
|
+
* Service codes (e.g. ['dev']) for which the platform should also build a
|
|
156
|
+
* ready-to-use preview URL with the freshly minted token baked in.
|
|
157
|
+
* Saves callers from having to know `baseDomain` or compose the URL.
|
|
158
|
+
*/
|
|
159
|
+
previewServiceCodes?: string[]
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
export interface CreateInstanceTokenOutput {
|
|
157
163
|
token: string
|
|
158
164
|
expiresAt: string
|
|
165
|
+
/**
|
|
166
|
+
* Preview URLs keyed by service code, populated when `previewServiceCodes`
|
|
167
|
+
* was set on the request. Each URL carries the token in `?token=` and is
|
|
168
|
+
* suitable for direct use as an iframe `src`.
|
|
169
|
+
*/
|
|
170
|
+
previewUrls?: Record<string, string>
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
// ============================================================================
|
|
@@ -304,6 +316,34 @@ export interface GetServiceUrlOutput {
|
|
|
304
316
|
url: string | null
|
|
305
317
|
}
|
|
306
318
|
|
|
319
|
+
// ============================================================================
|
|
320
|
+
// Session files
|
|
321
|
+
// ============================================================================
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Which file namespace inside the session to read from.
|
|
325
|
+
* - `workspace` — the user-facing workspace dir produced by session plugins (e.g. `dist/Course.zip`).
|
|
326
|
+
* - `session` — internal session storage under the SDK's `dataPath/sessions/{sessionId}`.
|
|
327
|
+
*/
|
|
328
|
+
export type SessionFileScope = 'workspace' | 'session'
|
|
329
|
+
|
|
330
|
+
export interface CreateSessionFileDownloadUrlInput {
|
|
331
|
+
instanceId: string
|
|
332
|
+
sessionId: string
|
|
333
|
+
scope: SessionFileScope
|
|
334
|
+
/** Scope-relative path (no leading slash). Path traversal (`..`) is rejected. */
|
|
335
|
+
path: string
|
|
336
|
+
/** TTL in seconds. Default 300, max 3600. */
|
|
337
|
+
ttlSeconds?: number
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface CreateSessionFileDownloadUrlOutput {
|
|
341
|
+
/** Signed, time-limited URL serving the file's bytes. */
|
|
342
|
+
url: string
|
|
343
|
+
/** ISO 8601 expiry of the signed URL. */
|
|
344
|
+
expiresAt: string
|
|
345
|
+
}
|
|
346
|
+
|
|
307
347
|
// ============================================================================
|
|
308
348
|
// Method registry
|
|
309
349
|
// ============================================================================
|
|
@@ -327,6 +367,9 @@ export const platformMethods = defineMethods({
|
|
|
327
367
|
// Services
|
|
328
368
|
'services.getUrl': method<GetServiceUrlInput, GetServiceUrlOutput>(),
|
|
329
369
|
|
|
370
|
+
// Session files (signed-URL gateway in front of SDK's session/workspace + session/files routes)
|
|
371
|
+
'sessionFiles.createDownloadUrl': method<CreateSessionFileDownloadUrlInput, CreateSessionFileDownloadUrlOutput>(),
|
|
372
|
+
|
|
330
373
|
// Bundles
|
|
331
374
|
'bundles.list': method<ListBundlesInput, ListBundlesOutput>(),
|
|
332
375
|
'bundles.delete': method<DeleteBundleInput, DeleteBundleOutput>(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createRpcClient } from './rpc-client'
|
|
2
|
-
import type { MethodInput, MethodOutput } from './rpc-definition'
|
|
3
|
-
import type { PlatformMethods, PlatformMethodName } from './methods'
|
|
1
|
+
import { createRpcClient } from './rpc-client.js'
|
|
2
|
+
import type { MethodInput, MethodOutput } from './rpc-definition.js'
|
|
3
|
+
import type { PlatformMethods, PlatformMethodName } from './methods.js'
|
|
4
4
|
import type {
|
|
5
5
|
CreateInstanceInput,
|
|
6
6
|
CreateInstanceOutput,
|
|
@@ -16,6 +16,8 @@ import type {
|
|
|
16
16
|
PublishSessionOutput,
|
|
17
17
|
CreateInstanceTokenInput,
|
|
18
18
|
CreateInstanceTokenOutput,
|
|
19
|
+
CreateSessionFileDownloadUrlInput,
|
|
20
|
+
CreateSessionFileDownloadUrlOutput,
|
|
19
21
|
ListBundlesInput,
|
|
20
22
|
ListBundlesOutput,
|
|
21
23
|
DeleteBundleOutput,
|
|
@@ -28,8 +30,8 @@ import type {
|
|
|
28
30
|
ListResourcesInput,
|
|
29
31
|
ListResourcesOutput,
|
|
30
32
|
DeleteResourceOutput,
|
|
31
|
-
} from './methods'
|
|
32
|
-
import { RojApiError } from './errors'
|
|
33
|
+
} from './methods.js'
|
|
34
|
+
import { RojApiError } from './errors.js'
|
|
33
35
|
|
|
34
36
|
export interface RojClientOptions {
|
|
35
37
|
/** Platform URL (e.g. https://roj.example.com) */
|
|
@@ -38,6 +40,13 @@ export interface RojClientOptions {
|
|
|
38
40
|
apiKey: string
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
export interface SessionRpcInput {
|
|
44
|
+
instanceId: string
|
|
45
|
+
sessionId: string
|
|
46
|
+
method: string
|
|
47
|
+
input?: Record<string, unknown>
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
export interface RojClient {
|
|
42
51
|
instances: {
|
|
43
52
|
create(input: CreateInstanceInput): Promise<CreateInstanceOutput>
|
|
@@ -50,10 +59,28 @@ export interface RojClient {
|
|
|
50
59
|
create(input: CreateSessionInput): Promise<CreateSessionOutput>
|
|
51
60
|
list(instanceId: string): Promise<ListSessionsOutput>
|
|
52
61
|
publish(input: PublishSessionInput): Promise<PublishSessionOutput>
|
|
62
|
+
/**
|
|
63
|
+
* Call a plugin/session RPC method on a running session.
|
|
64
|
+
*
|
|
65
|
+
* Auto-mints and caches an instance token; the cached token is reused until
|
|
66
|
+
* its expiry minus a small leeway. Suitable for server-to-server callers
|
|
67
|
+
* that don't have a browser cookie or pre-existing instance token.
|
|
68
|
+
*/
|
|
69
|
+
rpc<T = unknown>(input: SessionRpcInput): Promise<T>
|
|
53
70
|
}
|
|
54
71
|
tokens: {
|
|
55
72
|
create(input: CreateInstanceTokenInput): Promise<CreateInstanceTokenOutput>
|
|
56
73
|
}
|
|
74
|
+
sessionFiles: {
|
|
75
|
+
/**
|
|
76
|
+
* Mint a short-lived signed URL that streams the bytes of a session-bound file
|
|
77
|
+
* back to the caller. Use after a session plugin has produced an artifact
|
|
78
|
+
* (e.g. workspace `dist/Course.zip`) and the caller wants to fetch it without
|
|
79
|
+
* routing through the dev preview proxy. `scope` selects between the workspace
|
|
80
|
+
* dir and the SDK's session storage.
|
|
81
|
+
*/
|
|
82
|
+
createDownloadUrl(input: CreateSessionFileDownloadUrlInput): Promise<CreateSessionFileDownloadUrlOutput>
|
|
83
|
+
}
|
|
57
84
|
bundles: {
|
|
58
85
|
list(input?: ListBundlesInput): Promise<ListBundlesOutput>
|
|
59
86
|
delete(input: { bundleId?: string; bundleSlug?: string }): Promise<DeleteBundleOutput>
|
|
@@ -70,6 +97,16 @@ export interface RojClient {
|
|
|
70
97
|
}
|
|
71
98
|
}
|
|
72
99
|
|
|
100
|
+
// Re-mint instance tokens this many milliseconds before their server-stated expiry.
|
|
101
|
+
// Covers both clock skew between client and server and the latency of an in-flight
|
|
102
|
+
// session RPC that started just before expiry.
|
|
103
|
+
const TOKEN_REFRESH_LEEWAY_MS = 30_000
|
|
104
|
+
|
|
105
|
+
interface CachedToken {
|
|
106
|
+
token: string
|
|
107
|
+
expiresAtMs: number
|
|
108
|
+
}
|
|
109
|
+
|
|
73
110
|
export function createRojClient(options: RojClientOptions): RojClient {
|
|
74
111
|
const rpc = createRpcClient<PlatformMethods>(`${options.url}/api/v1`, {
|
|
75
112
|
headers: { Authorization: `Bearer ${options.apiKey}` },
|
|
@@ -84,6 +121,56 @@ export function createRojClient(options: RojClientOptions): RojClient {
|
|
|
84
121
|
return result.value
|
|
85
122
|
}
|
|
86
123
|
|
|
124
|
+
const instanceTokenCache = new Map<string, CachedToken>()
|
|
125
|
+
const inflightTokenMint = new Map<string, Promise<string>>()
|
|
126
|
+
async function getInstanceToken(instanceId: string): Promise<string> {
|
|
127
|
+
const cached = instanceTokenCache.get(instanceId)
|
|
128
|
+
if (cached && cached.expiresAtMs - TOKEN_REFRESH_LEEWAY_MS > Date.now()) {
|
|
129
|
+
return cached.token
|
|
130
|
+
}
|
|
131
|
+
const inflight = inflightTokenMint.get(instanceId)
|
|
132
|
+
if (inflight) return inflight
|
|
133
|
+
const promise = (async () => {
|
|
134
|
+
try {
|
|
135
|
+
const fresh = await call('tokens.create', { instanceId })
|
|
136
|
+
instanceTokenCache.set(instanceId, {
|
|
137
|
+
token: fresh.token,
|
|
138
|
+
expiresAtMs: new Date(fresh.expiresAt).getTime(),
|
|
139
|
+
})
|
|
140
|
+
return fresh.token
|
|
141
|
+
} finally {
|
|
142
|
+
inflightTokenMint.delete(instanceId)
|
|
143
|
+
}
|
|
144
|
+
})()
|
|
145
|
+
inflightTokenMint.set(instanceId, promise)
|
|
146
|
+
return promise
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function callSessionRpc<T>(input: SessionRpcInput, retriedAfter401 = false): Promise<T> {
|
|
150
|
+
const token = await getInstanceToken(input.instanceId)
|
|
151
|
+
const url = `${options.url}/api/v1/instances/${input.instanceId}/sessions/${input.sessionId}/rpc`
|
|
152
|
+
const response = await fetch(url, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
Authorization: `Bearer ${token}`,
|
|
157
|
+
},
|
|
158
|
+
body: JSON.stringify({ method: input.method, input: input.input ?? {} }),
|
|
159
|
+
})
|
|
160
|
+
// Token may have been revoked or rotated server-side before its stated `expiresAt`.
|
|
161
|
+
// Evict the cache and retry once with a freshly minted token.
|
|
162
|
+
if (response.status === 401 && !retriedAfter401) {
|
|
163
|
+
instanceTokenCache.delete(input.instanceId)
|
|
164
|
+
return callSessionRpc<T>(input, true)
|
|
165
|
+
}
|
|
166
|
+
const body = await response.json().catch(() => null) as { ok?: boolean; value?: unknown; error?: { type: string; message: string } } | null
|
|
167
|
+
if (!response.ok || !body || body.ok === false) {
|
|
168
|
+
const error = body?.error ?? { type: 'transport_error', message: `HTTP ${response.status}` }
|
|
169
|
+
throw new RojApiError(error)
|
|
170
|
+
}
|
|
171
|
+
return body.value as T
|
|
172
|
+
}
|
|
173
|
+
|
|
87
174
|
return {
|
|
88
175
|
instances: {
|
|
89
176
|
create: (input) => call('instances.create', input),
|
|
@@ -96,10 +183,14 @@ export function createRojClient(options: RojClientOptions): RojClient {
|
|
|
96
183
|
create: (input) => call('sessions.create', input),
|
|
97
184
|
list: (instanceId) => call('sessions.list', { instanceId }),
|
|
98
185
|
publish: (input) => call('sessions.publish', input),
|
|
186
|
+
rpc: (input) => callSessionRpc(input),
|
|
99
187
|
},
|
|
100
188
|
tokens: {
|
|
101
189
|
create: (input) => call('tokens.create', input),
|
|
102
190
|
},
|
|
191
|
+
sessionFiles: {
|
|
192
|
+
createDownloadUrl: (input) => call('sessionFiles.createDownloadUrl', input),
|
|
193
|
+
},
|
|
103
194
|
bundles: {
|
|
104
195
|
list: (input) => call('bundles.list', input ?? {}),
|
|
105
196
|
delete: (input) => call('bundles.delete', input),
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* })
|
|
9
9
|
* const result = await client.call('instances.create', { ... })
|
|
10
10
|
*/
|
|
11
|
-
import type { MethodDef, MethodInput, MethodOutput, RpcError, RpcResponse } from './rpc-definition'
|
|
11
|
+
import type { MethodDef, MethodInput, MethodOutput, RpcError, RpcResponse } from './rpc-definition.js'
|
|
12
12
|
|
|
13
13
|
export interface RpcClientOptions {
|
|
14
14
|
headers?: Record<string, string>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* // In Hono route:
|
|
11
11
|
* app.post('/rpc', (c) => router.handle(c.req.json(), ctx))
|
|
12
12
|
*/
|
|
13
|
-
import type { MethodDef, MethodInput, MethodOutput, RpcError, RpcRequest, RpcResponse } from './rpc-definition'
|
|
13
|
+
import type { MethodDef, MethodInput, MethodOutput, RpcError, RpcRequest, RpcResponse } from './rpc-definition.js'
|
|
14
14
|
|
|
15
15
|
export type MethodHandler<
|
|
16
16
|
Methods extends Record<string, MethodDef>,
|