@hue-run/sdk 0.19.1 → 0.20.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.
Files changed (50) hide show
  1. package/CLI.md +27 -10
  2. package/ENVIRONMENTS.md +5 -2
  3. package/EVALUATIONS.md +6 -1
  4. package/README.md +2 -2
  5. package/WORLDS.md +133 -0
  6. package/dist/cli/eval.d.ts +4 -0
  7. package/dist/cli/eval.js +434 -186
  8. package/dist/cli/listen.js +1 -1
  9. package/dist/environment/client.d.ts +2 -95
  10. package/dist/environment/client.js +2 -283
  11. package/dist/environment/tools.d.ts +2 -35
  12. package/dist/environment/tools.js +2 -30
  13. package/dist/environment/types.d.ts +2 -623
  14. package/dist/environment/types.js +2 -1
  15. package/dist/environment/world.d.ts +2 -65
  16. package/dist/environment/world.js +2 -171
  17. package/dist/environment.d.ts +7 -7
  18. package/dist/environment.js +3 -3
  19. package/dist/evals/attempt.d.ts +1 -1
  20. package/dist/evals/client.d.ts +3 -2
  21. package/dist/evals/client.js +2 -1
  22. package/dist/evals/environment-target.d.ts +3 -3
  23. package/dist/evals/environment-target.js +3 -3
  24. package/dist/evals/failure.js +1 -1
  25. package/dist/evals/local-worker.d.ts +8 -3
  26. package/dist/evals/local-worker.js +10 -2
  27. package/dist/evals/simulation.d.ts +6 -3
  28. package/dist/evals/simulation.js +2 -1
  29. package/dist/evals/types.d.ts +2 -2
  30. package/dist/version.d.ts +1 -1
  31. package/dist/version.js +1 -1
  32. package/dist/world/client.d.ts +161 -0
  33. package/dist/world/client.js +387 -0
  34. package/dist/world/definitions.d.ts +47 -0
  35. package/dist/world/definitions.js +1 -0
  36. package/dist/world/model-types.d.ts +123 -0
  37. package/dist/world/model-types.js +1 -0
  38. package/dist/world/models.d.ts +42 -0
  39. package/dist/world/models.js +56 -0
  40. package/dist/world/readiness.d.ts +18 -0
  41. package/dist/world/readiness.js +69 -0
  42. package/dist/world/tools.d.ts +35 -0
  43. package/dist/world/tools.js +30 -0
  44. package/dist/world/types.d.ts +625 -0
  45. package/dist/world/types.js +1 -0
  46. package/dist/world/world.d.ts +65 -0
  47. package/dist/world/world.js +175 -0
  48. package/dist/world.d.ts +13 -0
  49. package/dist/world.js +5 -0
  50. package/package.json +8 -2
@@ -0,0 +1,18 @@
1
+ /** Progress of one requested starting World. */
2
+ export interface WorldPreparationProgress {
3
+ /** Whether the request is preparing, usable, or waiting for changed evidence or dependencies. */
4
+ state: "preparing" | "insufficient_evidence" | "processing_limit" | "dependency_unavailable" | "ready";
5
+ /** Evidence cutoff selected for this request. */
6
+ selectedEvidenceCutoff: number;
7
+ /** Latest retained evidence cutoff. */
8
+ retainedEvidenceCutoff: number;
9
+ /** Latest indexed evidence cutoff for the current interpretation. */
10
+ readyEvidenceCutoff: number;
11
+ /** Whether retained evidence is still waiting for indexing. */
12
+ pendingEvidence: boolean;
13
+ }
14
+ /** Retained and indexed progress of an entity history. */
15
+ export interface WorldModelProcessing extends Omit<WorldPreparationProgress, "state" | "selectedEvidenceCutoff"> {
16
+ /** Indexing progress; a requested represented time may still lack required evidence. */
17
+ state: "indexed" | "preparing" | "insufficient_evidence" | "processing_limit" | "dependency_unavailable";
18
+ }
@@ -0,0 +1,69 @@
1
+ const diagnosticStates = {
2
+ world_preparing: "preparing",
3
+ world_insufficient_evidence: "insufficient_evidence",
4
+ world_processing_limit: "processing_limit",
5
+ world_dependency_unavailable: "dependency_unavailable",
6
+ };
7
+ /** @internal Only numeric progress and an allowlisted state cross the error boundary. */
8
+ export async function readWorldPreparation(response, diagnostic) {
9
+ if (response.status !== 503 || diagnostic === undefined || !(diagnostic in diagnosticStates)) {
10
+ await response.body?.cancel().catch(() => { });
11
+ return undefined;
12
+ }
13
+ const reader = response.body?.getReader();
14
+ if (!reader)
15
+ return undefined;
16
+ try {
17
+ const chunks = [];
18
+ let size = 0;
19
+ for (;;) {
20
+ const { done, value } = await reader.read();
21
+ if (done)
22
+ break;
23
+ size += value.byteLength;
24
+ if (size > 16 * 1024)
25
+ return undefined;
26
+ chunks.push(value);
27
+ }
28
+ const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
29
+ if (!body || typeof body !== "object" || !("preparation" in body))
30
+ return undefined;
31
+ const value = body.preparation;
32
+ if (!value || typeof value !== "object")
33
+ return undefined;
34
+ const { state, selectedEvidenceCutoff: selected, retainedEvidenceCutoff: retained, readyEvidenceCutoff: ready, pendingEvidence, } = value;
35
+ const expectedState = diagnosticStates[diagnostic];
36
+ if (expectedState === undefined ||
37
+ state !== expectedState ||
38
+ !Number.isSafeInteger(selected) ||
39
+ !Number.isSafeInteger(retained) ||
40
+ !Number.isSafeInteger(ready) ||
41
+ typeof selected !== "number" ||
42
+ typeof retained !== "number" ||
43
+ typeof ready !== "number" ||
44
+ selected < 0 ||
45
+ ready < 0 ||
46
+ selected > retained ||
47
+ ready > retained ||
48
+ pendingEvidence !== retained > ready)
49
+ return undefined;
50
+ return {
51
+ state: expectedState,
52
+ selectedEvidenceCutoff: selected,
53
+ retainedEvidenceCutoff: retained,
54
+ readyEvidenceCutoff: ready,
55
+ pendingEvidence,
56
+ };
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ finally {
62
+ await reader.cancel().catch(() => { });
63
+ }
64
+ }
65
+ /** @internal These failures require changed evidence or processing, not another identical call. */
66
+ export const TERMINAL_WORLD_DIAGNOSTICS = new Set([
67
+ "world_insufficient_evidence",
68
+ "world_processing_limit",
69
+ ]);
@@ -0,0 +1,35 @@
1
+ import type { Context } from "@opentelemetry/api";
2
+ import type { HueClient } from "../client.js";
3
+ import type { EnvironmentClient } from "./client.js";
4
+ import type { ActionSchema, EnvironmentRun, JsonValue, Observation } from "./types.js";
5
+ /** Framework-neutral callable generated from one environment action. */
6
+ export interface EnvironmentTool {
7
+ /** Tool name. */
8
+ name: string;
9
+ /** Agent-visible description. */
10
+ description?: string;
11
+ /** JSON Schema input contract. */
12
+ inputSchema: ActionSchema;
13
+ /** Executes the action and resolves with the world's observation. */
14
+ execute(args?: Record<string, JsonValue>): Promise<Observation>;
15
+ }
16
+ /** Dependencies and tracing context for {@link bindEnvironmentTools}. */
17
+ export interface BindEnvironmentToolsOptions {
18
+ /** Hue client used to record each action as tool telemetry. */
19
+ hue: HueClient;
20
+ /** Environment client bound to the same Hue origin. */
21
+ client: Pick<EnvironmentClient, "act">;
22
+ /** Fresh environment run whose closed catalog becomes callables. */
23
+ run: EnvironmentRun;
24
+ /** Optional parent span context for generated tool spans. */
25
+ parentContext?: Context;
26
+ /** Optional durable invocation-ID factory for caller-owned resume state. */
27
+ invocationId?(action: string): string;
28
+ }
29
+ /**
30
+ * Binds a run's generated catalog to plain local callables without changing the agent
31
+ * framework. Each call is recorded through {@link HueClient.tool}. Catalog entries that
32
+ * include `mcp` stamp `mcp.server.name` / `mcp.server.version` and `hue.mcp.provider` /
33
+ * `hue.mcp.surface` so a generic verb is attributed to that MCP server and Hue surface.
34
+ */
35
+ export declare function bindEnvironmentTools(options: BindEnvironmentToolsOptions): Record<string, EnvironmentTool>;
@@ -0,0 +1,30 @@
1
+ import { randomUUID } from "node:crypto";
2
+ /**
3
+ * Binds a run's generated catalog to plain local callables without changing the agent
4
+ * framework. Each call is recorded through {@link HueClient.tool}. Catalog entries that
5
+ * include `mcp` stamp `mcp.server.name` / `mcp.server.version` and `hue.mcp.provider` /
6
+ * `hue.mcp.surface` so a generic verb is attributed to that MCP server and Hue surface.
7
+ */
8
+ export function bindEnvironmentTools(options) {
9
+ const tools = {};
10
+ for (const action of options.run.actions) {
11
+ tools[action.name] = {
12
+ name: action.name,
13
+ ...(action.description === undefined ? {} : { description: action.description }),
14
+ inputSchema: action.inputSchema,
15
+ execute: async (args = {}) => {
16
+ const invocationId = options.invocationId?.(action.name) ?? randomUUID();
17
+ const execute = async () => (await options.client.act(options.run.id, {
18
+ invocationId,
19
+ action: action.name,
20
+ args,
21
+ })).observation;
22
+ return options.hue.tool(action.name, args, execute, {
23
+ parentContext: options.parentContext,
24
+ ...(action.mcp === undefined ? {} : { mcp: action.mcp }),
25
+ });
26
+ },
27
+ };
28
+ }
29
+ return tools;
30
+ }