@hydracept/sdk 0.1.0
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 +22 -0
- package/dist/control.d.ts +18 -0
- package/dist/control.d.ts.map +1 -0
- package/dist/control.js +64 -0
- package/dist/http.d.ts +16 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +109 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/runtime.d.ts +24 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +79 -0
- package/dist/sse.d.ts +14 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +65 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @hydracept/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Hydracept public API — AI execution infrastructure for games.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @hydracept/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createHydraceptClient } from '@hydracept/sdk';
|
|
11
|
+
|
|
12
|
+
const client = createHydraceptClient({
|
|
13
|
+
baseUrl: 'https://api.hydracept.com',
|
|
14
|
+
getToken: () => process.env.HYDRACEPT_API_KEY ?? '',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const caps = await client.runtime.capabilities();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Docs: https://docs.hydracept.com
|
|
21
|
+
|
|
22
|
+
A Zencode product · © Zencode Consulting Inc.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HydraceptHttp } from './http.js';
|
|
2
|
+
import type { HydraceptAssetOut } from './types.js';
|
|
3
|
+
/** Control-plane helpers used by product authoring UIs (KOL, Workbench). */
|
|
4
|
+
export declare function createHydraceptControlApi(http: HydraceptHttp): {
|
|
5
|
+
healthz(path?: string): Promise<Response>;
|
|
6
|
+
listProviders<T = unknown>(): Promise<T>;
|
|
7
|
+
syncProject<T = unknown>(projectId: string, body: unknown, init?: RequestInit): Promise<T>;
|
|
8
|
+
listAssets(projectId: string, limit?: number): Promise<HydraceptAssetOut[]>;
|
|
9
|
+
generateAsset<T = unknown>(assetId: string, body?: unknown, init?: RequestInit): Promise<T>;
|
|
10
|
+
getWorkflow<T = unknown>(workflowId: string): Promise<T>;
|
|
11
|
+
getArtifact<T = unknown>(artifactId: string): Promise<T>;
|
|
12
|
+
getArtifactContent(artifactId: string): Promise<Blob>;
|
|
13
|
+
createReview<T = unknown>(body: unknown): Promise<T>;
|
|
14
|
+
createPromotion<T = unknown>(body: unknown): Promise<T>;
|
|
15
|
+
reportPromotion<T = unknown>(promotionId: string, body: unknown): Promise<T>;
|
|
16
|
+
};
|
|
17
|
+
export type HydraceptControlApi = ReturnType<typeof createHydraceptControlApi>;
|
|
18
|
+
//# sourceMappingURL=control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../src/control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,YAAY,CAAC;AAQxE,4EAA4E;AAC5E,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,aAAa;4BAE7B,OAAO,CAAC,QAAQ,CAAC;kBAK/B,CAAC,eAAe,OAAO,CAAC,CAAC,CAAC;gBAI5B,CAAC,uBAAuB,MAAM,QAAQ,OAAO,SAAQ,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;0BAQxE,MAAM,mBAAgB,OAAO,CAAC,iBAAiB,EAAE,CAAC;kBAQ1D,CAAC,qBAAqB,MAAM,SAAQ,OAAO,SAAa,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;gBAQvF,CAAC,wBAAwB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;gBAI5C,CAAC,wBAAwB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;mCAIzB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;iBAIxC,CAAC,kBAAkB,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;oBAOpC,CAAC,kBAAkB,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;oBAOvC,CAAC,yBAAyB,MAAM,QAAQ,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;EAO/E;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
package/dist/control.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function normalizeAssetList(data) {
|
|
2
|
+
if (Array.isArray(data))
|
|
3
|
+
return [...data];
|
|
4
|
+
const page = data;
|
|
5
|
+
return [...(page.items ?? [])];
|
|
6
|
+
}
|
|
7
|
+
/** Control-plane helpers used by product authoring UIs (KOL, Workbench). */
|
|
8
|
+
export function createHydraceptControlApi(http) {
|
|
9
|
+
return {
|
|
10
|
+
healthz(path = '/healthz') {
|
|
11
|
+
// healthz is outside /v1 — call absolute-ish via fetchResponse with special path handling
|
|
12
|
+
return http.fetchResponse(path.startsWith('/healthz') ? path : '/healthz');
|
|
13
|
+
},
|
|
14
|
+
listProviders() {
|
|
15
|
+
return http.fetchJson('/providers');
|
|
16
|
+
},
|
|
17
|
+
syncProject(projectId, body, init = {}) {
|
|
18
|
+
return http.fetchJson(`/projects/${encodeURIComponent(projectId)}/syncs`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
body: JSON.stringify(body),
|
|
21
|
+
...init,
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
listAssets(projectId, limit = 500) {
|
|
25
|
+
return http
|
|
26
|
+
.fetchJson(`/assets?projectId=${encodeURIComponent(projectId)}&limit=${limit}`)
|
|
27
|
+
.then(normalizeAssetList);
|
|
28
|
+
},
|
|
29
|
+
generateAsset(assetId, body = {}, init = {}) {
|
|
30
|
+
return http.fetchJson(`/assets/${encodeURIComponent(assetId)}/generate`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: JSON.stringify(body),
|
|
33
|
+
...init,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
getWorkflow(workflowId) {
|
|
37
|
+
return http.fetchJsonWithRetry(`/workflows/${encodeURIComponent(workflowId)}`);
|
|
38
|
+
},
|
|
39
|
+
getArtifact(artifactId) {
|
|
40
|
+
return http.fetchJson(`/artifacts/${encodeURIComponent(artifactId)}`);
|
|
41
|
+
},
|
|
42
|
+
getArtifactContent(artifactId) {
|
|
43
|
+
return http.fetchBlob(`/artifacts/${encodeURIComponent(artifactId)}/content`);
|
|
44
|
+
},
|
|
45
|
+
createReview(body) {
|
|
46
|
+
return http.fetchJson('/reviews', {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
body: JSON.stringify(body),
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
createPromotion(body) {
|
|
52
|
+
return http.fetchJson('/promotions', {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
body: JSON.stringify(body),
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
reportPromotion(promotionId, body) {
|
|
58
|
+
return http.fetchJson(`/promotions/${encodeURIComponent(promotionId)}/report`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
body: JSON.stringify(body),
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HydraceptClientOptions } from './types.js';
|
|
2
|
+
export declare function createHydraceptHttp(options: HydraceptClientOptions): {
|
|
3
|
+
options: HydraceptClientOptions;
|
|
4
|
+
authHeaders: (extra?: Record<string, string>) => Record<string, string>;
|
|
5
|
+
urlFor: (path: string) => string;
|
|
6
|
+
fetchResponse: (path: string, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
fetchJson: <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
8
|
+
fetchBlob: (path: string, init?: RequestInit) => Promise<Blob>;
|
|
9
|
+
fetchBytes: (path: string, init?: RequestInit) => Promise<ArrayBuffer>;
|
|
10
|
+
fetchJsonWithRetry: <T>(path: string, init?: RequestInit, retry?: {
|
|
11
|
+
maxAttempts?: number;
|
|
12
|
+
baseDelayMs?: number;
|
|
13
|
+
}) => Promise<T>;
|
|
14
|
+
};
|
|
15
|
+
export type HydraceptHttp = ReturnType<typeof createHydraceptHttp>;
|
|
16
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAsB,MAAM,YAAY,CAAC;AAyB7E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,sBAAsB;;0BAIrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;mBAO1D,MAAM,KAAG,MAAM;0BAIF,MAAM,SAAQ,WAAW,KAAQ,OAAO,CAAC,QAAQ,CAAC;gBAuB5D,CAAC,QAAQ,MAAM,SAAQ,WAAW,KAAQ,OAAO,CAAC,CAAC,CAAC;sBAK9C,MAAM,SAAQ,WAAW,KAAQ,OAAO,CAAC,IAAI,CAAC;uBAK7C,MAAM,SAAQ,WAAW,KAAQ,OAAO,CAAC,WAAW,CAAC;yBASnD,CAAC,QAC3B,MAAM,SACN,WAAW,UACV;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,KACpD,OAAO,CAAC,CAAC,CAAC;EA0Cd;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
function resolveToken(options) {
|
|
2
|
+
if (options.getToken)
|
|
3
|
+
return options.getToken();
|
|
4
|
+
return options.token ?? '';
|
|
5
|
+
}
|
|
6
|
+
function joinUrl(baseUrl, path) {
|
|
7
|
+
const base = baseUrl.replace(/\/$/, '');
|
|
8
|
+
const suffix = path.startsWith('/') ? path : `/${path}`;
|
|
9
|
+
return `${base}${suffix}`;
|
|
10
|
+
}
|
|
11
|
+
function toV1Path(path, pathsAreV1Relative) {
|
|
12
|
+
const normalized = path.startsWith('/') ? path : `/${path}`;
|
|
13
|
+
if (pathsAreV1Relative) {
|
|
14
|
+
// Caller already speaks /assets, /workflows, etc. (Vite proxy to /v1).
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
if (normalized.startsWith('/v1/') || normalized === '/v1' || normalized === '/healthz') {
|
|
18
|
+
return normalized;
|
|
19
|
+
}
|
|
20
|
+
return `/v1${normalized}`;
|
|
21
|
+
}
|
|
22
|
+
export function createHydraceptHttp(options) {
|
|
23
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
24
|
+
const credentials = options.credentials ?? 'omit';
|
|
25
|
+
function authHeaders(extra = {}) {
|
|
26
|
+
const token = resolveToken(options);
|
|
27
|
+
const headers = { ...extra };
|
|
28
|
+
if (token)
|
|
29
|
+
headers.Authorization = `Bearer ${token}`;
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
function urlFor(path) {
|
|
33
|
+
return joinUrl(options.baseUrl, toV1Path(path, options.pathsAreV1Relative));
|
|
34
|
+
}
|
|
35
|
+
async function fetchResponse(path, init = {}) {
|
|
36
|
+
const headers = {
|
|
37
|
+
...authHeaders(),
|
|
38
|
+
...init.headers,
|
|
39
|
+
};
|
|
40
|
+
if (init.body && !headers['Content-Type']) {
|
|
41
|
+
headers['Content-Type'] = 'application/json';
|
|
42
|
+
}
|
|
43
|
+
const res = await fetchImpl(urlFor(path), {
|
|
44
|
+
...init,
|
|
45
|
+
headers,
|
|
46
|
+
credentials,
|
|
47
|
+
});
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
const text = await res.text().catch(() => '');
|
|
50
|
+
const error = new Error(`Hydracept ${path} failed (${res.status}): ${text}`);
|
|
51
|
+
error.status = res.status;
|
|
52
|
+
error.body = text;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
async function fetchJson(path, init = {}) {
|
|
58
|
+
const res = await fetchResponse(path, init);
|
|
59
|
+
return res.json();
|
|
60
|
+
}
|
|
61
|
+
async function fetchBlob(path, init = {}) {
|
|
62
|
+
const res = await fetchResponse(path, init);
|
|
63
|
+
return res.blob();
|
|
64
|
+
}
|
|
65
|
+
async function fetchBytes(path, init = {}) {
|
|
66
|
+
const res = await fetchResponse(path, init);
|
|
67
|
+
return res.arrayBuffer();
|
|
68
|
+
}
|
|
69
|
+
function isRetryableStatus(status) {
|
|
70
|
+
return status === 408 || status === 429 || status === 500 || status === 502 || status === 503 || status === 504;
|
|
71
|
+
}
|
|
72
|
+
async function fetchJsonWithRetry(path, init = {}, retry = {}) {
|
|
73
|
+
const maxAttempts = retry.maxAttempts ?? 8;
|
|
74
|
+
const baseDelayMs = retry.baseDelayMs ?? 750;
|
|
75
|
+
let lastError = null;
|
|
76
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
77
|
+
try {
|
|
78
|
+
return await fetchJson(path, init);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
82
|
+
lastError = error;
|
|
83
|
+
const status = error.status;
|
|
84
|
+
const retryable = status !== undefined && isRetryableStatus(status);
|
|
85
|
+
if (!retryable || attempt === maxAttempts)
|
|
86
|
+
throw error;
|
|
87
|
+
const delayMs = baseDelayMs * attempt;
|
|
88
|
+
await new Promise((resolve, reject) => {
|
|
89
|
+
const timer = setTimeout(resolve, delayMs);
|
|
90
|
+
init.signal?.addEventListener('abort', () => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
reject(init.signal?.reason ?? new DOMException('Aborted', 'AbortError'));
|
|
93
|
+
}, { once: true });
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw lastError ?? new Error(`Hydracept ${path} failed after retries`);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
options,
|
|
101
|
+
authHeaders,
|
|
102
|
+
urlFor,
|
|
103
|
+
fetchResponse,
|
|
104
|
+
fetchJson,
|
|
105
|
+
fetchBlob,
|
|
106
|
+
fetchBytes,
|
|
107
|
+
fetchJsonWithRetry,
|
|
108
|
+
};
|
|
109
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createHydraceptControlApi } from './control.js';
|
|
2
|
+
import { type HydraceptHttp } from './http.js';
|
|
3
|
+
import { createHydraceptRuntimeApi } from './runtime.js';
|
|
4
|
+
import type { HydraceptClientOptions } from './types.js';
|
|
5
|
+
export type { HydraceptHttpError, HydraceptClientOptions, HydraceptRuntimeEvent } from './types.js';
|
|
6
|
+
export { createHydraceptHttp } from './http.js';
|
|
7
|
+
export type { HydraceptHttp } from './http.js';
|
|
8
|
+
export { createHydraceptControlApi } from './control.js';
|
|
9
|
+
export type { HydraceptControlApi } from './control.js';
|
|
10
|
+
export { createHydraceptRuntimeApi } from './runtime.js';
|
|
11
|
+
export type { HydraceptRuntimeApi } from './runtime.js';
|
|
12
|
+
export { iterInvocationEvents } from './sse.js';
|
|
13
|
+
export type { HydraceptAssetOut, HydraceptAssetPage, } from './types.js';
|
|
14
|
+
export type HydraceptClient = {
|
|
15
|
+
http: HydraceptHttp;
|
|
16
|
+
control: ReturnType<typeof createHydraceptControlApi>;
|
|
17
|
+
runtime: ReturnType<typeof createHydraceptRuntimeApi>;
|
|
18
|
+
};
|
|
19
|
+
export declare function createHydraceptClient(options: HydraceptClientOptions): HydraceptClient;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;IACtD,OAAO,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;CACvD,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAOtF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createHydraceptControlApi } from './control.js';
|
|
2
|
+
import { createHydraceptHttp } from './http.js';
|
|
3
|
+
import { createHydraceptRuntimeApi } from './runtime.js';
|
|
4
|
+
export { createHydraceptHttp } from './http.js';
|
|
5
|
+
export { createHydraceptControlApi } from './control.js';
|
|
6
|
+
export { createHydraceptRuntimeApi } from './runtime.js';
|
|
7
|
+
export { iterInvocationEvents } from './sse.js';
|
|
8
|
+
export function createHydraceptClient(options) {
|
|
9
|
+
const http = createHydraceptHttp(options);
|
|
10
|
+
return {
|
|
11
|
+
http,
|
|
12
|
+
control: createHydraceptControlApi(http),
|
|
13
|
+
runtime: createHydraceptRuntimeApi(http),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HydraceptHttp } from './http.js';
|
|
2
|
+
import type { HydraceptRuntimeEvent } from './types.js';
|
|
3
|
+
/** Runtime helpers used by trusted product backends (product-backend). */
|
|
4
|
+
export declare function createHydraceptRuntimeApi(http: HydraceptHttp): {
|
|
5
|
+
invoke<T = unknown>(body: unknown, init?: RequestInit): Promise<T>;
|
|
6
|
+
getInvocation<T = unknown>(executionId: string): Promise<T>;
|
|
7
|
+
getReceipt<T = unknown>(executionId: string): Promise<T>;
|
|
8
|
+
cancelInvocation<T = unknown>(executionId: string): Promise<T>;
|
|
9
|
+
submitJob<T = unknown>(body: unknown, init?: RequestInit): Promise<T>;
|
|
10
|
+
getJob<T = unknown>(jobId: string): Promise<T>;
|
|
11
|
+
getJobResult<T = unknown>(jobId: string): Promise<T>;
|
|
12
|
+
getCapabilities<T = unknown>(): Promise<T>;
|
|
13
|
+
describeCapability<T = unknown>(key: string): Promise<T>;
|
|
14
|
+
invokeCapability<T = unknown>(key: string, body: unknown, init?: RequestInit): Promise<T>;
|
|
15
|
+
submitCapabilityJob<T = unknown>(key: string, body: unknown, init?: RequestInit): Promise<T>;
|
|
16
|
+
getJobReceipt<T = unknown>(jobId: string): Promise<T>;
|
|
17
|
+
cancelJob<T = unknown>(jobId: string): Promise<T>;
|
|
18
|
+
streamInvocationEvents(executionId: string, options?: {
|
|
19
|
+
lastEventId?: string;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}): AsyncGenerator<HydraceptRuntimeEvent, void, unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type HydraceptRuntimeApi = ReturnType<typeof createHydraceptRuntimeApi>;
|
|
24
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,0EAA0E;AAC1E,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,aAAa;WAElD,CAAC,kBAAkB,OAAO,SAAQ,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;kBAQxD,CAAC,yBAAyB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;eAIhD,CAAC,yBAAyB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;qBAIvC,CAAC,yBAAyB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;cAMpD,CAAC,kBAAkB,OAAO,SAAQ,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;WAQlE,CAAC,mBAAmB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;iBAIjC,CAAC,mBAAmB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;oBAIpC,CAAC,eAAe,OAAO,CAAC,CAAC,CAAC;uBAIvB,CAAC,iBAAiB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;qBAIvC,CAAC,iBAAiB,MAAM,QAAQ,OAAO,SAAQ,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;wBAQzE,CAAC,iBACd,MAAM,QACL,OAAO,SACP,WAAW,GAChB,OAAO,CAAC,CAAC,CAAC;kBAQC,CAAC,mBAAmB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;cAI3C,CAAC,mBAAmB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;wCAKlC,MAAM,YACV;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACtD,cAAc,CAAC,qBAAqB,EAAE,IAAI,EAAE,OAAO,CAAC;EAmB1D;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { iterInvocationEvents } from './sse.js';
|
|
2
|
+
/** Runtime helpers used by trusted product backends (product-backend). */
|
|
3
|
+
export function createHydraceptRuntimeApi(http) {
|
|
4
|
+
return {
|
|
5
|
+
invoke(body, init = {}) {
|
|
6
|
+
return http.fetchJson('/invocations', {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
body: JSON.stringify(body),
|
|
9
|
+
...init,
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
getInvocation(executionId) {
|
|
13
|
+
return http.fetchJson(`/invocations/${encodeURIComponent(executionId)}`);
|
|
14
|
+
},
|
|
15
|
+
getReceipt(executionId) {
|
|
16
|
+
return http.fetchJson(`/invocations/${encodeURIComponent(executionId)}/receipt`);
|
|
17
|
+
},
|
|
18
|
+
cancelInvocation(executionId) {
|
|
19
|
+
return http.fetchJson(`/invocations/${encodeURIComponent(executionId)}/cancel`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
submitJob(body, init = {}) {
|
|
24
|
+
return http.fetchJson('/jobs', {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
body: JSON.stringify(body),
|
|
27
|
+
...init,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
getJob(jobId) {
|
|
31
|
+
return http.fetchJsonWithRetry(`/jobs/${encodeURIComponent(jobId)}`);
|
|
32
|
+
},
|
|
33
|
+
getJobResult(jobId) {
|
|
34
|
+
return http.fetchJson(`/jobs/${encodeURIComponent(jobId)}/result`);
|
|
35
|
+
},
|
|
36
|
+
getCapabilities() {
|
|
37
|
+
return http.fetchJson('/capabilities');
|
|
38
|
+
},
|
|
39
|
+
describeCapability(key) {
|
|
40
|
+
return http.fetchJson(`/capabilities/${encodeURIComponent(key)}`);
|
|
41
|
+
},
|
|
42
|
+
invokeCapability(key, body, init = {}) {
|
|
43
|
+
return http.fetchJson(`/capabilities/${encodeURIComponent(key)}/invoke`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
...init,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
submitCapabilityJob(key, body, init = {}) {
|
|
50
|
+
return http.fetchJson(`/capabilities/${encodeURIComponent(key)}/jobs`, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
...init,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
getJobReceipt(jobId) {
|
|
57
|
+
return http.fetchJson(`/jobs/${encodeURIComponent(jobId)}/receipt`);
|
|
58
|
+
},
|
|
59
|
+
cancelJob(jobId) {
|
|
60
|
+
return http.fetchJson(`/jobs/${encodeURIComponent(jobId)}/cancel`, { method: 'POST' });
|
|
61
|
+
},
|
|
62
|
+
streamInvocationEvents(executionId, options = {}) {
|
|
63
|
+
const token = http.options.getToken?.() ?? http.options.token ?? '';
|
|
64
|
+
const sseOptions = {};
|
|
65
|
+
if (options.lastEventId !== undefined)
|
|
66
|
+
sseOptions.lastEventId = options.lastEventId;
|
|
67
|
+
if (options.signal !== undefined)
|
|
68
|
+
sseOptions.signal = options.signal;
|
|
69
|
+
if (http.options.pathsAreV1Relative !== undefined) {
|
|
70
|
+
sseOptions.pathsAreV1Relative = http.options.pathsAreV1Relative;
|
|
71
|
+
}
|
|
72
|
+
if (http.options.credentials !== undefined)
|
|
73
|
+
sseOptions.credentials = http.options.credentials;
|
|
74
|
+
if (http.options.fetchImpl !== undefined)
|
|
75
|
+
sseOptions.fetchImpl = http.options.fetchImpl;
|
|
76
|
+
return iterInvocationEvents(http.options.baseUrl, token, executionId, sseOptions);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HydraceptRuntimeEvent } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maintained SSE helper for Hydracept invocation events.
|
|
4
|
+
* Ordinary REST clients should prefer createHydraceptHttp / OpenAPI-generated types.
|
|
5
|
+
*/
|
|
6
|
+
export declare function iterInvocationEvents(baseUrl: string, token: string, executionId: string, options?: {
|
|
7
|
+
lastEventId?: string;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
/** When true, baseUrl already points at /v1 (or a proxy that strips it). */
|
|
10
|
+
pathsAreV1Relative?: boolean;
|
|
11
|
+
fetchImpl?: typeof fetch;
|
|
12
|
+
credentials?: RequestCredentials;
|
|
13
|
+
}): AsyncGenerator<HydraceptRuntimeEvent, void, unknown>;
|
|
14
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;GAGG;AACH,wBAAuB,oBAAoB,CACzC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAC7B,GACL,cAAc,CAAC,qBAAqB,EAAE,IAAI,EAAE,OAAO,CAAC,CAyDtD"}
|
package/dist/sse.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maintained SSE helper for Hydracept invocation events.
|
|
3
|
+
* Ordinary REST clients should prefer createHydraceptHttp / OpenAPI-generated types.
|
|
4
|
+
*/
|
|
5
|
+
export async function* iterInvocationEvents(baseUrl, token, executionId, options = {}) {
|
|
6
|
+
const headers = {
|
|
7
|
+
Authorization: `Bearer ${token}`,
|
|
8
|
+
Accept: 'text/event-stream',
|
|
9
|
+
};
|
|
10
|
+
if (options.lastEventId) {
|
|
11
|
+
headers['Last-Event-ID'] = options.lastEventId;
|
|
12
|
+
}
|
|
13
|
+
const root = baseUrl.replace(/\/$/, '');
|
|
14
|
+
const path = options.pathsAreV1Relative
|
|
15
|
+
? `/invocations/${encodeURIComponent(executionId)}/events`
|
|
16
|
+
: `/v1/invocations/${encodeURIComponent(executionId)}/events`;
|
|
17
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
18
|
+
const response = await fetchImpl(`${root}${path}`, {
|
|
19
|
+
headers,
|
|
20
|
+
credentials: options.credentials ?? 'omit',
|
|
21
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok || !response.body) {
|
|
24
|
+
throw new Error(`SSE failed: ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
const reader = response.body.getReader();
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
let buffer = '';
|
|
29
|
+
let eventName = 'message';
|
|
30
|
+
let dataLines = [];
|
|
31
|
+
let eventId;
|
|
32
|
+
while (true) {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done)
|
|
35
|
+
break;
|
|
36
|
+
buffer += decoder.decode(value, { stream: true });
|
|
37
|
+
const parts = buffer.split('\n');
|
|
38
|
+
buffer = parts.pop() ?? '';
|
|
39
|
+
for (const line of parts) {
|
|
40
|
+
if (line === '') {
|
|
41
|
+
if (dataLines.length) {
|
|
42
|
+
const payload = {
|
|
43
|
+
event: eventName,
|
|
44
|
+
data: JSON.parse(dataLines.join('\n')),
|
|
45
|
+
};
|
|
46
|
+
if (eventId !== undefined)
|
|
47
|
+
payload.id = eventId;
|
|
48
|
+
yield payload;
|
|
49
|
+
}
|
|
50
|
+
eventName = 'message';
|
|
51
|
+
dataLines = [];
|
|
52
|
+
eventId = undefined;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (line.startsWith(':'))
|
|
56
|
+
continue;
|
|
57
|
+
if (line.startsWith('id:'))
|
|
58
|
+
eventId = line.slice(3).trim();
|
|
59
|
+
else if (line.startsWith('event:'))
|
|
60
|
+
eventName = line.slice(6).trim();
|
|
61
|
+
else if (line.startsWith('data:'))
|
|
62
|
+
dataLines.push(line.slice(5).trimStart());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type HydraceptRuntimeEvent = {
|
|
2
|
+
id?: string;
|
|
3
|
+
event: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
};
|
|
6
|
+
export type HydraceptClientOptions = {
|
|
7
|
+
/** Hydracept API origin (https://api.hydracept.com or http://localhost:8080). */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** Static bearer token, or omit and supply getToken. */
|
|
10
|
+
token?: string;
|
|
11
|
+
getToken?: () => string;
|
|
12
|
+
/** fetch credentials mode. Prefer 'omit' for browser API calls. */
|
|
13
|
+
credentials?: RequestCredentials;
|
|
14
|
+
/** When true, paths already include /v1 (or proxy strips it). */
|
|
15
|
+
pathsAreV1Relative?: boolean;
|
|
16
|
+
fetchImpl?: typeof fetch;
|
|
17
|
+
};
|
|
18
|
+
export type HydraceptHttpError = Error & {
|
|
19
|
+
status?: number;
|
|
20
|
+
body?: string;
|
|
21
|
+
};
|
|
22
|
+
export type HydraceptAssetOut = {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly logicalKey: string;
|
|
25
|
+
readonly [key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
export type HydraceptAssetPage = {
|
|
28
|
+
readonly items?: readonly HydraceptAssetOut[];
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC;IACxB,mEAAmE;IACnE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,iEAAiE;IACjE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC/C,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hydracept/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for the Hydracept public API — AI execution infrastructure for games.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"homepage": "https://hydracept.com",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/hydracept/hydracept"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^5.7.2"
|
|
38
|
+
}
|
|
39
|
+
}
|