@oneie/sdk 0.2.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +276 -0
- package/dist/client.d.ts +28 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +173 -20
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/react/context.d.ts +11 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +13 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/hooks.d.ts +19 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +65 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/optimistic.d.ts +45 -0
- package/dist/react/optimistic.d.ts.map +1 -0
- package/dist/react/optimistic.js +52 -0
- package/dist/react/optimistic.js.map +1 -0
- package/dist/react/stream.d.ts +18 -0
- package/dist/react/stream.d.ts.map +1 -0
- package/dist/react/stream.js +60 -0
- package/dist/react/stream.js.map +1 -0
- package/dist/schemas.d.ts +174 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +127 -0
- package/dist/schemas.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +52 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types.d.ts +246 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -6
- package/dist/types.js.map +1 -1
- package/package.json +33 -3
package/dist/errors.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class SubstrateError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
body;
|
|
5
|
+
constructor(message, status, code, body) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.body = body;
|
|
10
|
+
this.name = "SubstrateError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class AuthError extends SubstrateError {
|
|
14
|
+
constructor(message, status) {
|
|
15
|
+
super(message, status, "auth_error");
|
|
16
|
+
this.name = "AuthError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class ValidationError extends SubstrateError {
|
|
20
|
+
constructor(message, status, body) {
|
|
21
|
+
super(message, status, "validation_error", body);
|
|
22
|
+
this.name = "ValidationError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class RateLimitError extends SubstrateError {
|
|
26
|
+
retryAfterMs;
|
|
27
|
+
constructor(message, retryAfterMs) {
|
|
28
|
+
super(message, 429, "rate_limit_error");
|
|
29
|
+
this.retryAfterMs = retryAfterMs;
|
|
30
|
+
this.name = "RateLimitError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class TimeoutError extends SubstrateError {
|
|
34
|
+
constructor(message, status) {
|
|
35
|
+
super(message, status ?? 408, "timeout_error");
|
|
36
|
+
this.name = "TimeoutError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class DissolvedError extends SubstrateError {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message, undefined, "dissolved_error");
|
|
42
|
+
this.name = "DissolvedError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAG5B;IACA;IACA;IAJX,YACE,OAAe,EACN,MAAe,EACf,IAAa,E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index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export { launchToken } from "./launch.js";
|
|
|
6
6
|
export type { LaunchOpts, LaunchResult } from "./launch.js";
|
|
7
7
|
export { SubstrateClient } from "./client.js";
|
|
8
8
|
export { emit as telemetryEmit, isDisabled as isTelemetryDisabled, sessionId } from "./telemetry.js";
|
|
9
|
+
export * from "./errors.js";
|
|
10
|
+
export * from "./schemas.js";
|
|
9
11
|
export declare const SDK_VERSION = "0.2.0";
|
|
10
12
|
//# 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,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,UAAU,IAAI,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErG,eAAO,MAAM,WAAW,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,UAAU,IAAI,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErG,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAE7B,eAAO,MAAM,WAAW,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,5 +5,7 @@ export * from "./handoff.js";
|
|
|
5
5
|
export { launchToken } from "./launch.js";
|
|
6
6
|
export { SubstrateClient } from "./client.js";
|
|
7
7
|
export { emit as telemetryEmit, isDisabled as isTelemetryDisabled, sessionId } from "./telemetry.js";
|
|
8
|
+
export * from "./errors.js";
|
|
9
|
+
export * from "./schemas.js";
|
|
8
10
|
export const SDK_VERSION = "0.2.0";
|
|
9
11
|
//# 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,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,UAAU,IAAI,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErG,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,UAAU,IAAI,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAErG,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAE7B,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { SubstrateClient } from "../client.js";
|
|
3
|
+
export interface SubstrateContextValue {
|
|
4
|
+
client: SubstrateClient;
|
|
5
|
+
}
|
|
6
|
+
export declare function SubstrateProvider({ client, children, }: {
|
|
7
|
+
client: SubstrateClient;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function useSubstrate(): SubstrateContextValue;
|
|
11
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,eAAe,CAAC;CACzB;AAID,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAMA;AAED,wBAAgB,YAAY,IAAI,qBAAqB,CAIpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const SubstrateContext = createContext(null);
|
|
4
|
+
export function SubstrateProvider({ client, children, }) {
|
|
5
|
+
return (_jsx(SubstrateContext.Provider, { value: { client }, children: children }));
|
|
6
|
+
}
|
|
7
|
+
export function useSubstrate() {
|
|
8
|
+
const ctx = useContext(SubstrateContext);
|
|
9
|
+
if (!ctx)
|
|
10
|
+
throw new Error("useSubstrate must be used inside <SubstrateProvider>");
|
|
11
|
+
return ctx;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAOlE,MAAM,gBAAgB,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAC;AAE3E,MAAM,UAAU,iBAAiB,CAAC,EAChC,MAAM,EACN,QAAQ,GAIT;IACC,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,YACzC,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACzC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAClF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DiscoverResponse, HighwaysResponse } from "../types.js";
|
|
2
|
+
export declare function useAgent(uid: string): {
|
|
3
|
+
data: unknown;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
refetch: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useDiscover(skill: string, limit?: number): {
|
|
9
|
+
data: DiscoverResponse | null;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
};
|
|
13
|
+
export declare function useHighways(limit?: number): {
|
|
14
|
+
data: HighwaysResponse | null;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
refetch: () => void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAUtE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;;EAuBnC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK;;;;EAepD;AAED,wBAAgB,WAAW,CAAC,KAAK,SAAK;;;;;EAuBrC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useSubstrate } from "./context.js";
|
|
3
|
+
const _cache = new Map();
|
|
4
|
+
function cached(key, fn) {
|
|
5
|
+
if (!_cache.has(key))
|
|
6
|
+
_cache.set(key, fn());
|
|
7
|
+
return _cache.get(key);
|
|
8
|
+
}
|
|
9
|
+
export function useAgent(uid) {
|
|
10
|
+
const { client } = useSubstrate();
|
|
11
|
+
const [data, setData] = useState(null);
|
|
12
|
+
const [loading, setLoading] = useState(true);
|
|
13
|
+
const [error, setError] = useState(null);
|
|
14
|
+
const refetch = useCallback(() => {
|
|
15
|
+
_cache.delete(`agent:${uid}`);
|
|
16
|
+
setLoading(true);
|
|
17
|
+
cached(`agent:${uid}`, () => client.reveal(uid))
|
|
18
|
+
.then(setData)
|
|
19
|
+
.catch((e) => setError(e instanceof Error ? e : new Error(String(e))))
|
|
20
|
+
.finally(() => setLoading(false));
|
|
21
|
+
}, [uid, client]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
cached(`agent:${uid}`, () => client.reveal(uid))
|
|
24
|
+
.then(setData)
|
|
25
|
+
.catch((e) => setError(e instanceof Error ? e : new Error(String(e))))
|
|
26
|
+
.finally(() => setLoading(false));
|
|
27
|
+
}, [uid, client]);
|
|
28
|
+
return { data, loading, error, refetch };
|
|
29
|
+
}
|
|
30
|
+
export function useDiscover(skill, limit = 10) {
|
|
31
|
+
const { client } = useSubstrate();
|
|
32
|
+
const [data, setData] = useState(null);
|
|
33
|
+
const [loading, setLoading] = useState(true);
|
|
34
|
+
const [error, setError] = useState(null);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setLoading(true);
|
|
37
|
+
cached(`discover:${skill}:${limit}`, () => client.discover(skill, limit))
|
|
38
|
+
.then(setData)
|
|
39
|
+
.catch((e) => setError(e instanceof Error ? e : new Error(String(e))))
|
|
40
|
+
.finally(() => setLoading(false));
|
|
41
|
+
}, [skill, limit, client]);
|
|
42
|
+
return { data, loading, error };
|
|
43
|
+
}
|
|
44
|
+
export function useHighways(limit = 10) {
|
|
45
|
+
const { client } = useSubstrate();
|
|
46
|
+
const [data, setData] = useState(null);
|
|
47
|
+
const [loading, setLoading] = useState(true);
|
|
48
|
+
const [error, setError] = useState(null);
|
|
49
|
+
const refetch = useCallback(() => {
|
|
50
|
+
_cache.delete(`highways:${limit}`);
|
|
51
|
+
setLoading(true);
|
|
52
|
+
cached(`highways:${limit}`, () => client.highways(limit))
|
|
53
|
+
.then(setData)
|
|
54
|
+
.catch((e) => setError(e instanceof Error ? e : new Error(String(e))))
|
|
55
|
+
.finally(() => setLoading(false));
|
|
56
|
+
}, [limit, client]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
cached(`highways:${limit}`, () => client.highways(limit))
|
|
59
|
+
.then(setData)
|
|
60
|
+
.catch((e) => setError(e instanceof Error ? e : new Error(String(e))))
|
|
61
|
+
.finally(() => setLoading(false));
|
|
62
|
+
}, [limit, client]);
|
|
63
|
+
return { data, loading, error, refetch };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["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AC,CAAC;aAC9E,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,YAAY,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACtD,IAAI,CAAC,OAAO,CAAC;aACb,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC9E,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SubstrateProvider, useSubstrate } from "./context.js";
|
|
2
|
+
export { useAgent, useDiscover, useHighways } from "./hooks.js";
|
|
3
|
+
export { useOptimisticMark, useOptimisticPay } from "./optimistic.js";
|
|
4
|
+
export { streamChat, streamTail } from "./stream.js";
|
|
5
|
+
export type { SubstrateContextValue } from "./context.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SubstrateProvider, useSubstrate } from "./context.js";
|
|
2
|
+
export { useAgent, useDiscover, useHighways } from "./hooks.js";
|
|
3
|
+
export { useOptimisticMark, useOptimisticPay } from "./optimistic.js";
|
|
4
|
+
export { streamChat, streamTail } from "./stream.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MarkDimsResponse, PayResponse } from "../types.js";
|
|
2
|
+
export interface MarkState {
|
|
3
|
+
edge: string;
|
|
4
|
+
scores: Partial<{
|
|
5
|
+
fit: number;
|
|
6
|
+
form: number;
|
|
7
|
+
truth: number;
|
|
8
|
+
taste: number;
|
|
9
|
+
}>;
|
|
10
|
+
pending: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function useOptimisticMark(initialEdge?: string): {
|
|
13
|
+
optimistic: {
|
|
14
|
+
pending: boolean;
|
|
15
|
+
edge: string;
|
|
16
|
+
scores: Partial<{
|
|
17
|
+
fit: number;
|
|
18
|
+
form: number;
|
|
19
|
+
truth: number;
|
|
20
|
+
taste: number;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
mark: (edge: string, scores?: Partial<{
|
|
24
|
+
fit: number;
|
|
25
|
+
form: number;
|
|
26
|
+
truth: number;
|
|
27
|
+
taste: number;
|
|
28
|
+
}>) => Promise<MarkDimsResponse>;
|
|
29
|
+
};
|
|
30
|
+
export interface PayState {
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
pending: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare function useOptimisticPay(): {
|
|
37
|
+
optimistic: {
|
|
38
|
+
pending: boolean;
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
amount: number;
|
|
42
|
+
};
|
|
43
|
+
pay: (from: string, to: string, task: string, amount: number) => Promise<PayResponse>;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=optimistic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimistic.d.ts","sourceRoot":"","sources":["../../src/react/optimistic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGjE,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7E,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,WAAW,SAAK;;;cAL1C,MAAM;gBACJ,OAAO,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;;iBAcpE,MAAM,WACH,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,KAC5E,OAAO,CAAC,gBAAgB,CAAC;EAe7B;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,gBAAgB;;;cANxB,MAAM;YACR,MAAM;gBACF,MAAM;;gBAcK,MAAM,MAAM,MAAM,QAAQ,MAAM,UAAU,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC;EAe3F"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useOptimistic, useTransition } from "react";
|
|
2
|
+
import { useSubstrate } from "./context.js";
|
|
3
|
+
export function useOptimisticMark(initialEdge = "") {
|
|
4
|
+
const { client } = useSubstrate();
|
|
5
|
+
const [isPending, startTransition] = useTransition();
|
|
6
|
+
const [optimistic, setOptimistic] = useOptimistic({
|
|
7
|
+
edge: initialEdge,
|
|
8
|
+
scores: { fit: 0, form: 0, truth: 0, taste: 0 },
|
|
9
|
+
pending: false,
|
|
10
|
+
});
|
|
11
|
+
function mark(edge, scores) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
startTransition(async () => {
|
|
14
|
+
setOptimistic({ edge, scores: scores ?? { fit: 1, form: 1, truth: 1, taste: 1 }, pending: true });
|
|
15
|
+
try {
|
|
16
|
+
const result = await client.mark(edge, scores);
|
|
17
|
+
resolve(result);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
reject(err);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return { optimistic: { ...optimistic, pending: isPending }, mark };
|
|
26
|
+
}
|
|
27
|
+
export function useOptimisticPay() {
|
|
28
|
+
const { client } = useSubstrate();
|
|
29
|
+
const [isPending, startTransition] = useTransition();
|
|
30
|
+
const [optimistic, setOptimistic] = useOptimistic({
|
|
31
|
+
from: "",
|
|
32
|
+
to: "",
|
|
33
|
+
amount: 0,
|
|
34
|
+
pending: false,
|
|
35
|
+
});
|
|
36
|
+
function pay(from, to, task, amount) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
startTransition(async () => {
|
|
39
|
+
setOptimistic({ from, to, amount, pending: true });
|
|
40
|
+
try {
|
|
41
|
+
const result = await client.pay(from, to, task, amount);
|
|
42
|
+
resolve(result);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
reject(err);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return { optimistic: { ...optimistic, pending: isPending }, pay };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=optimistic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimistic.js","sourceRoot":"","sources":["../../src/react/optimistic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,MAAM,UAAU,iBAAiB,CAAC,WAAW,GAAG,EAAE;IAChD,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;IAClC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,aAAa,EAAE,CAAC;IACrD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,aAAa,CAAY;QAC3D,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;QAC/C,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,SAAS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BACzB,aAAa,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBACnD,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;oBACxD,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SubstrateClient } from "../client.js";
|
|
2
|
+
export interface ChatMessage {
|
|
3
|
+
role: "user" | "assistant" | "system";
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StreamChatOpts {
|
|
7
|
+
model?: string;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
system?: string;
|
|
10
|
+
agentId?: string;
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function streamChat(client: SubstrateClient, messages: ChatMessage[], opts?: StreamChatOpts): AsyncIterable<string>;
|
|
14
|
+
export declare function streamTail(client: SubstrateClient, opts?: {
|
|
15
|
+
interval?: number;
|
|
16
|
+
reload?: boolean;
|
|
17
|
+
}): AsyncIterable<unknown>;
|
|
18
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/react/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAsBD,wBAAuB,UAAU,CAC/B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,WAAW,EAAE,EACvB,IAAI,GAAE,cAAmB,GACxB,aAAa,CAAC,MAAM,CAAC,CAcvB;AAED,wBAAuB,UAAU,CAC/B,MAAM,EAAE,eAAe,EACvB,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjD,aAAa,CAAC,OAAO,CAAC,CAiBxB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
async function* parseSSE(body) {
|
|
2
|
+
const reader = body.getReader();
|
|
3
|
+
const decoder = new TextDecoder();
|
|
4
|
+
let buffer = "";
|
|
5
|
+
while (true) {
|
|
6
|
+
const { done, value } = await reader.read();
|
|
7
|
+
if (done)
|
|
8
|
+
break;
|
|
9
|
+
buffer += decoder.decode(value, { stream: true });
|
|
10
|
+
const lines = buffer.split("\n");
|
|
11
|
+
buffer = lines.pop() ?? "";
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
if (line.startsWith("data: ")) {
|
|
14
|
+
const data = line.slice(6).trim();
|
|
15
|
+
if (data === "[DONE]")
|
|
16
|
+
return;
|
|
17
|
+
if (data)
|
|
18
|
+
yield data;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function* streamChat(client, messages, opts = {}) {
|
|
24
|
+
const baseUrl = client.baseUrl;
|
|
25
|
+
const apiKey = client.apiKey;
|
|
26
|
+
const headers = { "Content-Type": "application/json" };
|
|
27
|
+
if (apiKey)
|
|
28
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
29
|
+
const res = await fetch(`${baseUrl}/api/chat`, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers,
|
|
32
|
+
body: JSON.stringify({ messages, ...opts }),
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok || !res.body)
|
|
35
|
+
return;
|
|
36
|
+
yield* parseSSE(res.body);
|
|
37
|
+
}
|
|
38
|
+
export async function* streamTail(client, opts = {}) {
|
|
39
|
+
const baseUrl = client.baseUrl;
|
|
40
|
+
const apiKey = client.apiKey;
|
|
41
|
+
const headers = { "Content-Type": "application/json" };
|
|
42
|
+
if (apiKey)
|
|
43
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
44
|
+
const qs = [
|
|
45
|
+
opts.interval != null ? `interval=${opts.interval}` : null,
|
|
46
|
+
opts.reload ? "reload=1" : null,
|
|
47
|
+
].filter(Boolean).join("&");
|
|
48
|
+
const res = await fetch(`${baseUrl}/api/stream${qs ? `?${qs}` : ""}`, { headers });
|
|
49
|
+
if (!res.ok || !res.body)
|
|
50
|
+
return;
|
|
51
|
+
for await (const line of parseSSE(res.body)) {
|
|
52
|
+
try {
|
|
53
|
+
yield JSON.parse(line);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
yield line;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/react/stream.ts"],"names":[],"mappings":"AAeA,KAAK,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAgC;IACvD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IA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C;QAAC,MAAM,CAAC;YAAC,MAAM,IAAI,CAAC;QAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SignalResponseSchema: z.ZodObject<{
|
|
3
|
+
ok: z.ZodBoolean;
|
|
4
|
+
routed: z.ZodNullable<z.ZodString>;
|
|
5
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
6
|
+
latency: z.ZodNumber;
|
|
7
|
+
success: z.ZodBoolean;
|
|
8
|
+
sui: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const HighwaysResponseSchema: z.ZodObject<{
|
|
11
|
+
highways: z.ZodArray<z.ZodObject<{
|
|
12
|
+
path: z.ZodString;
|
|
13
|
+
strength: z.ZodNumber;
|
|
14
|
+
resistance: z.ZodNumber;
|
|
15
|
+
net: z.ZodNumber;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export declare const AuthAgentResponseSchema: z.ZodObject<{
|
|
19
|
+
uid: z.ZodString;
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
kind: z.ZodString;
|
|
22
|
+
wallet: z.ZodNullable<z.ZodString>;
|
|
23
|
+
apiKey: z.ZodString;
|
|
24
|
+
keyId: z.ZodString;
|
|
25
|
+
returning: z.ZodBoolean;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const SyncAgentResponseSchema: z.ZodObject<{
|
|
28
|
+
ok: z.ZodBoolean;
|
|
29
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
30
|
+
uid: z.ZodOptional<z.ZodString>;
|
|
31
|
+
wallet: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
suiObjectId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
34
|
+
world: z.ZodOptional<z.ZodString>;
|
|
35
|
+
agents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
uid: z.ZodString;
|
|
38
|
+
wallet: z.ZodNullable<z.ZodString>;
|
|
39
|
+
suiObjectId: z.ZodNullable<z.ZodString>;
|
|
40
|
+
skills: z.ZodArray<z.ZodString>;
|
|
41
|
+
}, z.core.$strip>>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export declare const DiscoverAgentSchema: z.ZodObject<{
|
|
44
|
+
uid: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
unitKind: z.ZodString;
|
|
47
|
+
skillId: z.ZodString;
|
|
48
|
+
skillName: z.ZodString;
|
|
49
|
+
reputation: z.ZodNumber;
|
|
50
|
+
successRate: z.ZodNumber;
|
|
51
|
+
activityScore: z.ZodNumber;
|
|
52
|
+
price: z.ZodNumber;
|
|
53
|
+
currency: z.ZodString;
|
|
54
|
+
strength: z.ZodNumber;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const DiscoverResponseSchema: z.ZodObject<{
|
|
57
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
58
|
+
uid: z.ZodString;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
unitKind: z.ZodString;
|
|
61
|
+
skillId: z.ZodString;
|
|
62
|
+
skillName: z.ZodString;
|
|
63
|
+
reputation: z.ZodNumber;
|
|
64
|
+
successRate: z.ZodNumber;
|
|
65
|
+
activityScore: z.ZodNumber;
|
|
66
|
+
price: z.ZodNumber;
|
|
67
|
+
currency: z.ZodString;
|
|
68
|
+
strength: z.ZodNumber;
|
|
69
|
+
}, z.core.$strip>>;
|
|
70
|
+
skill: z.ZodString;
|
|
71
|
+
count: z.ZodNumber;
|
|
72
|
+
limit: z.ZodNumber;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
export declare const RegisterResponseSchema: z.ZodObject<{
|
|
75
|
+
ok: z.ZodBoolean;
|
|
76
|
+
uid: z.ZodString;
|
|
77
|
+
status: z.ZodString;
|
|
78
|
+
kind: z.ZodString;
|
|
79
|
+
wallet: z.ZodNullable<z.ZodString>;
|
|
80
|
+
walletLinked: z.ZodBoolean;
|
|
81
|
+
capabilities: z.ZodNumber;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
export declare const PayResponseSchema: z.ZodObject<{
|
|
84
|
+
ok: z.ZodBoolean;
|
|
85
|
+
from: z.ZodString;
|
|
86
|
+
to: z.ZodString;
|
|
87
|
+
task: z.ZodString;
|
|
88
|
+
amount: z.ZodNumber;
|
|
89
|
+
sui: z.ZodNullable<z.ZodString>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
export declare const ClawResponseSchema: z.ZodObject<{
|
|
92
|
+
ok: z.ZodBoolean;
|
|
93
|
+
workerUrl: z.ZodOptional<z.ZodString>;
|
|
94
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
95
|
+
error: z.ZodOptional<z.ZodString>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
export declare const AgentActionResponseSchema: z.ZodObject<{
|
|
98
|
+
ok: z.ZodBoolean;
|
|
99
|
+
id: z.ZodString;
|
|
100
|
+
action: z.ZodString;
|
|
101
|
+
}, z.core.$strip>;
|
|
102
|
+
export declare const AgentStatusResponseSchema: z.ZodObject<{
|
|
103
|
+
ok: z.ZodBoolean;
|
|
104
|
+
id: z.ZodString;
|
|
105
|
+
status: z.ZodString;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export declare const CapabilityItemSchema: z.ZodObject<{
|
|
108
|
+
skillId: z.ZodString;
|
|
109
|
+
skillName: z.ZodString;
|
|
110
|
+
price: z.ZodNumber;
|
|
111
|
+
currency: z.ZodString;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
export declare const StatsSchema: z.ZodObject<{
|
|
114
|
+
units: z.ZodObject<{
|
|
115
|
+
total: z.ZodNumber;
|
|
116
|
+
proven: z.ZodNumber;
|
|
117
|
+
atRisk: z.ZodNumber;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
skills: z.ZodObject<{
|
|
120
|
+
total: z.ZodNumber;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
highways: z.ZodObject<{
|
|
123
|
+
count: z.ZodNumber;
|
|
124
|
+
totalEdges: z.ZodNumber;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
revenue: z.ZodObject<{
|
|
127
|
+
total: z.ZodNumber;
|
|
128
|
+
gdp: z.ZodNumber;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
signals: z.ZodObject<{
|
|
131
|
+
total: z.ZodNumber;
|
|
132
|
+
recent: z.ZodNumber;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
timestamp: z.ZodString;
|
|
135
|
+
}, z.core.$strip>;
|
|
136
|
+
export declare const WorldInfoSchema: z.ZodObject<{
|
|
137
|
+
units: z.ZodNumber;
|
|
138
|
+
agents: z.ZodNumber;
|
|
139
|
+
edges: z.ZodNumber;
|
|
140
|
+
highways: z.ZodNumber;
|
|
141
|
+
loadedAgoMs: z.ZodNumber;
|
|
142
|
+
totalRevenue: z.ZodString;
|
|
143
|
+
avgSuccessRate: z.ZodString;
|
|
144
|
+
topGroup: z.ZodNullable<z.ZodObject<{
|
|
145
|
+
id: z.ZodString;
|
|
146
|
+
name: z.ZodString;
|
|
147
|
+
memberCount: z.ZodNumber;
|
|
148
|
+
}, z.core.$strip>>;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
export declare const HealthSchema: z.ZodObject<{
|
|
151
|
+
status: z.ZodEnum<{
|
|
152
|
+
healthy: "healthy";
|
|
153
|
+
degraded: "degraded";
|
|
154
|
+
}>;
|
|
155
|
+
world: z.ZodObject<{
|
|
156
|
+
units: z.ZodNumber;
|
|
157
|
+
agents: z.ZodNumber;
|
|
158
|
+
edges: z.ZodNumber;
|
|
159
|
+
highways: z.ZodNumber;
|
|
160
|
+
loadedAgoMs: z.ZodNumber;
|
|
161
|
+
totalRevenue: z.ZodString;
|
|
162
|
+
avgSuccessRate: z.ZodString;
|
|
163
|
+
topGroup: z.ZodNullable<z.ZodObject<{
|
|
164
|
+
id: z.ZodString;
|
|
165
|
+
name: z.ZodString;
|
|
166
|
+
memberCount: z.ZodNumber;
|
|
167
|
+
}, z.core.$strip>>;
|
|
168
|
+
}, z.core.$strip>;
|
|
169
|
+
version: z.ZodString;
|
|
170
|
+
phase: z.ZodString;
|
|
171
|
+
uptime: z.ZodNumber;
|
|
172
|
+
timestamp: z.ZodString;
|
|
173
|
+
}, z.core.$strip>;
|
|
174
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,oBAAoB;;;;;;;iBAO/B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;iBAOjC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;iBAQlC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;iBAelC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;iBAY9B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;iBAKjC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;iBAQjC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;iBAO5B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;iBAK7B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;iBAIpC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;iBAIpC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;iBAK/B,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAOtB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;iBAS1B,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;iBAOvB,CAAC"}
|