@hugex/artifact 0.12.1 → 0.12.3

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.
@@ -21,6 +21,14 @@ export type ArtifactRoute = {
21
21
  key: string;
22
22
  flowId: string;
23
23
  sessionId: string;
24
+ }
25
+ /** `<base>/__hx/media/<id>` or `<base>/__hx/media/<id>/share`. */
26
+ | {
27
+ kind: "media";
28
+ slug: string;
29
+ key: string;
30
+ mediaId: string;
31
+ action: "stream" | "share";
24
32
  };
25
33
  export interface RouteInput {
26
34
  pathname: string;
@@ -1,4 +1,6 @@
1
+ import type { AllowsWorkerResult, ArtifactAgentProxyTarget } from '../common/types/artifact-bridge';
1
2
  import type { ToolRunAdmitInput, ToolRunAdmitResult, ToolRunExecutor, ToolRunFinishInput, ToolRunLogEntry } from './mcp/toolRunContract';
3
+ export type { AllowsWorkerResult, ArtifactAgentProxyTarget };
2
4
  /**
3
5
  * Contract shared by the @hugex/artifact runtime (ArtifactDO, ArtifactIndexDO, host routing) and the MCP layer.
4
6
  * Owned by the orchestrator: workers must not change these shapes without updating plans/notes/artifacts-design.md (§10 contract, workspace root).
@@ -58,11 +60,8 @@ export interface ArtifactEnv {
58
60
  * capture is marked `failed` / `no_browser` and the artifact keeps working.
59
61
  */
60
62
  BROWSER?: unknown;
61
- }
62
- /** Target of the same-origin agent route `<base>/__hx/agent/<flowId>/<sessionId>`. */
63
- export interface ArtifactAgentProxyTarget {
64
- flowId: string;
65
- sessionId: string;
63
+ /** Public origin of the tenant used to build absolute `/m/<token>` share URLs. */
64
+ MEDIA_SHARE_ORIGIN?: string;
66
65
  }
67
66
  /**
68
67
  * Injected by the tenant (for example `artifactAgentProxy` from `@hugex/ai`). Runs the tenant's
@@ -141,12 +140,6 @@ export type AllowsWorkerInput = {
141
140
  mode: 'browser' | 'server';
142
141
  artifactUuid?: string;
143
142
  };
144
- export type AllowsWorkerResult = {
145
- ok: true;
146
- owner: string;
147
- } | {
148
- ok: false;
149
- };
150
143
  export type ArtifactGroup = 'none' | 'all' | (string & {});
151
144
  export type VersionState = 'provisional' | 'activa' | 'fallida' | 'anterior';
152
145
  export interface ArtifactMeta {
@@ -553,4 +546,3 @@ export declare const HX_HEADER_KEY = "x-hx-artifact-key";
553
546
  export declare const HX_HEADER_VISIT = "x-hx-artifact-visit";
554
547
  /** Public base path of the artifact including trailing slash, e.g. `/demo/k/abc/` or `/app/demo/`. */
555
548
  export declare const HX_HEADER_BASE = "x-hx-artifact-base";
556
- export {};
@@ -1,4 +1,4 @@
1
- export type NodeTypeName = 'startNode' | 'classifierNode' | 'memoNode' | 'llmNode' | 'answerNode' | 'apiNode' | 'toolNode' | 'workerNode' | 'crawlNode' | 'webActionsNode';
1
+ export type NodeTypeName = 'startNode' | 'classifierNode' | 'memoNode' | 'llmNode' | 'answerNode' | 'apiNode' | 'toolNode' | 'workerNode' | 'crawlNode' | 'webActionsNode' | 'mediaNode';
2
2
  export interface AuthoringNode {
3
3
  id: string;
4
4
  type: string;
@@ -23,7 +23,7 @@ export interface WorkerGraph {
23
23
  }
24
24
  export type IssueSeverity = 'error' | 'warning';
25
25
  export type CredentialKind = 'bearer_token' | 'basic_auth' | 'known_token' | 'url_userinfo' | 'url_query' | 'sensitive_key' | 'high_entropy';
26
- export type IssueCode = 'missing_state' | 'schema_version' | 'var_mapping' | 'classifier_invalid' | 'classifier_edge_missing' | 'out_vars_invalid' | 'start_count' | 'answer_missing' | 'dead_end' | 'unknown_node_type' | 'duplicate_node_id' | 'invalid_node_id' | 'node_id_collides_with_input' | 'edge_unknown_node' | 'edge_bad_handle' | 'edge_duplicate' | 'start_has_input' | 'answer_has_output' | 'multiple_outgoing' | 'field_type' | 'field_required' | 'field_range' | 'field_enum' | 'ref_syntax' | 'ref_unknown_node' | 'ref_out_of_scope' | 'ref_unknown_output' | 'ref_binary_not_allowed' | 'start_input_invalid' | 'answer_mapping_invalid' | 'worker_self_reference' | 'classifier_error_unrouted' | 'classifier_handle_inactive' | 'unreachable_node' | 'graph_cycle' | 'crawl_prompt_literal' | 'model_unknown' | 'param_unsupported' | 'reasoning_effort_unsupported' | 'tool_unavailable' | 'tool_kind_mismatch' | 'skill_unavailable' | 'builtin_unknown' | 'tool_args_invalid' | 'tool_args_unknown' | 'composio_slug_disabled' | 'composio_schema_missing' | 'memo_unavailable' | 'worker_unavailable' | 'worker_child_no_output' | 'worker_inputs_mismatch' | 'worker_child_inactive_forbidden' | 'worker_child_inactive' | 'secret_unknown' | 'secret_check_skipped' | 'personal_memory_inactive' | 'client_tool_unknown' | 'client_tool_inactive' | 'desktop_tools_unknown_family' | 'inline_credential' | 'op_invalid' | 'op_unknown_node' | 'already_connected' | 'edge_not_found' | 'edge_ambiguous' | 'cannot_remove_start';
26
+ export type IssueCode = 'missing_state' | 'schema_version' | 'var_mapping' | 'classifier_invalid' | 'classifier_edge_missing' | 'out_vars_invalid' | 'start_count' | 'answer_missing' | 'dead_end' | 'unknown_node_type' | 'duplicate_node_id' | 'invalid_node_id' | 'node_id_collides_with_input' | 'edge_unknown_node' | 'edge_bad_handle' | 'edge_duplicate' | 'start_has_input' | 'answer_has_output' | 'multiple_outgoing' | 'field_type' | 'field_required' | 'field_range' | 'field_enum' | 'ref_syntax' | 'ref_unknown_node' | 'ref_out_of_scope' | 'ref_unknown_output' | 'ref_binary_not_allowed' | 'start_input_invalid' | 'answer_mapping_invalid' | 'worker_self_reference' | 'classifier_error_unrouted' | 'classifier_handle_inactive' | 'unreachable_node' | 'graph_cycle' | 'crawl_prompt_literal' | 'model_unknown' | 'param_unsupported' | 'reasoning_effort_unsupported' | 'tool_unavailable' | 'tool_kind_mismatch' | 'skill_unavailable' | 'builtin_unknown' | 'tool_args_invalid' | 'tool_args_unknown' | 'composio_slug_disabled' | 'composio_schema_missing' | 'memo_unavailable' | 'worker_unavailable' | 'worker_child_no_output' | 'worker_inputs_mismatch' | 'worker_child_inactive_forbidden' | 'worker_child_inactive' | 'secret_unknown' | 'secret_check_skipped' | 'personal_memory_inactive' | 'client_tool_unknown' | 'client_tool_inactive' | 'desktop_tools_unknown_family' | 'inline_credential' | 'op_invalid' | 'op_unknown_node' | 'already_connected' | 'edge_not_found' | 'edge_ambiguous' | 'cannot_remove_start' | 'media_node_public';
27
27
  export interface GraphIssue {
28
28
  code: IssueCode;
29
29
  severity: IssueSeverity;
@@ -37,7 +37,7 @@ export interface GraphIssue {
37
37
  kind?: CredentialKind;
38
38
  suggestedSecret?: string;
39
39
  }
40
- export type InsertNodeType = 'memoNode' | 'llmNode' | 'apiNode' | 'toolNode' | 'workerNode' | 'crawlNode' | 'webActionsNode';
40
+ export type InsertNodeType = 'memoNode' | 'llmNode' | 'apiNode' | 'toolNode' | 'workerNode' | 'crawlNode' | 'webActionsNode' | 'mediaNode';
41
41
  export type WorkerOp = {
42
42
  op: 'add_node';
43
43
  type: NodeTypeName;
@@ -125,7 +125,7 @@ export interface JsonSchema {
125
125
  /** Six definitions merged into any tool schema that accepts `graph` (N3). */
126
126
  export declare const WORKER_GRAPH_DEFS: {
127
127
  nodeType: {
128
- readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode'];
128
+ readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode', 'mediaNode'];
129
129
  };
130
130
  nodeId: {
131
131
  readonly type: 'string';
@@ -215,7 +215,7 @@ export declare const WORKER_GRAPH_SCHEMA: {
215
215
  readonly $schema: 'https://json-schema.org/draft/2020-12/schema';
216
216
  readonly $defs: {
217
217
  nodeType: {
218
- readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode'];
218
+ readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode', 'mediaNode'];
219
219
  };
220
220
  nodeId: {
221
221
  readonly type: 'string';
@@ -336,7 +336,7 @@ export declare const WORKER_OP_SCHEMA: {
336
336
  };
337
337
  readonly $defs: {
338
338
  readonly nodeType: {
339
- readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode'];
339
+ readonly enum: readonly ['startNode', 'classifierNode', 'memoNode', 'llmNode', 'answerNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode', 'mediaNode'];
340
340
  };
341
341
  readonly existingId: {
342
342
  readonly type: 'string';
@@ -424,7 +424,7 @@ export declare const WORKER_OP_SCHEMA: {
424
424
  readonly const: 'insert_node';
425
425
  };
426
426
  readonly type: {
427
- readonly enum: readonly ['memoNode', 'llmNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode'];
427
+ readonly enum: readonly ['memoNode', 'llmNode', 'apiNode', 'toolNode', 'workerNode', 'crawlNode', 'webActionsNode', 'mediaNode'];
428
428
  };
429
429
  readonly id: {
430
430
  readonly $ref: '#/$defs/newId';
@@ -66,12 +66,14 @@ export declare const ISSUE_SEVERITY: {
66
66
  readonly edge_not_found: 'blocking';
67
67
  readonly edge_ambiguous: 'blocking';
68
68
  readonly cannot_remove_start: 'blocking';
69
+ readonly media_node_public: 'blocking';
69
70
  };
70
71
  /** L1, same order and same messages as FlowEngine.validateFlowStart. */
71
72
  export declare function validateFlowStructure(graph: unknown): GraphIssue[];
72
73
  /** L2 authoring issues, with intrinsic severity. Final severity is classifyIssues. */
73
74
  export declare function validateAuthoring(graph: WorkerGraph, opts?: {
74
75
  flowType?: string;
76
+ visibility?: string;
75
77
  }): GraphIssue[];
76
78
  /** Fingerprint of code, node, field, ref, and credential kind. Message and op are excluded. */
77
79
  export declare function issueFingerprint(issue: GraphIssue): string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Bridge between the artifact host and the agent runtime.
3
+ * `artifactUuid` / `artifactPublic` stay optional: `host.ts` and the proxy tests still
4
+ * build a target with only `flowId` and `sessionId`. Callers that know the artifact set them.
5
+ */
6
+ export interface ArtifactAgentProxyTarget {
7
+ flowId: string;
8
+ sessionId: string;
9
+ artifactUuid?: string;
10
+ artifactPublic?: boolean;
11
+ }
12
+ /**
13
+ * `ArtifactDO.allowsWorker`. Keeps the `{ ok: true, owner }` / `{ ok: false }` shape.
14
+ * `uuid` and `public` are optional until `checkWorker` fills them.
15
+ */
16
+ export type AllowsWorkerResult = {
17
+ ok: true;
18
+ owner: string;
19
+ uuid?: string;
20
+ public?: boolean;
21
+ } | {
22
+ ok: false;
23
+ uuid?: string;
24
+ public?: boolean;
25
+ };
26
+ /** Artifact identity carried into a flow turn (`SessionEnv`, `/message` body, `x-hx-artifact`). */
27
+ export interface ArtifactPrincipal {
28
+ uuid: string;
29
+ public: boolean;
30
+ }
31
+ /** Internal header. Client `x-*` headers are stripped before this one is set. */
32
+ export declare const ARTIFACT_HEADER = "x-hx-artifact";
33
+ /** `<uuid>;public=<0|1>`. */
34
+ export declare function formatArtifactHeader(principal: ArtifactPrincipal): string;
35
+ export declare function parseArtifactHeader(value: string | null | undefined): ArtifactPrincipal | null;
@@ -0,0 +1,105 @@
1
+ /** Shared media-generation contract. Events match `FlowEngineEvent`: `{ type, content, timestamp? }`. */
2
+ export type MediaKind = 'image' | 'video';
3
+ /** Reference to one persisted generated asset. Never includes the prompt or a provider URL. */
4
+ export interface MediaRef {
5
+ kind: 'media';
6
+ /** uuid v4 of the `generated_media` row. */
7
+ id: string;
8
+ mediaType: MediaKind;
9
+ /** `image/png` | `image/jpeg` | `image/webp` | `video/mp4`. */
10
+ mimeType: string;
11
+ bytes?: number;
12
+ width?: number;
13
+ height?: number;
14
+ durationMs?: number;
15
+ }
16
+ export declare function isMediaRef(value: unknown): value is MediaRef;
17
+ export type MediaErrorCode = 'moderated' | 'timeout' | 'provider_error' | 'too_large' | 'cancelled' | 'media_node_public' | 'model_invalid' | 'reference_invalid' | 'ingest_failed' | 'snapshot_too_large' | 'media_job_pending';
18
+ export type MediaEvent = {
19
+ type: 'media:start';
20
+ content: {
21
+ nodeId: string;
22
+ jobId?: string;
23
+ kind: MediaKind;
24
+ modelId: string;
25
+ n: number;
26
+ };
27
+ timestamp?: number;
28
+ } | {
29
+ type: 'media:progress';
30
+ content: {
31
+ nodeId: string;
32
+ jobId: string;
33
+ elapsedMs: number;
34
+ };
35
+ timestamp?: number;
36
+ } | {
37
+ type: 'media:done';
38
+ content: {
39
+ nodeId: string;
40
+ jobId?: string;
41
+ media: MediaRef[];
42
+ };
43
+ timestamp?: number;
44
+ } | {
45
+ type: 'media:error';
46
+ content: {
47
+ nodeId: string;
48
+ jobId?: string;
49
+ code: MediaErrorCode;
50
+ message: string;
51
+ };
52
+ timestamp?: number;
53
+ };
54
+ /** Runtime route that streams a generated asset after flow authorization. */
55
+ export declare const MEDIA_API_PATH = "/api/media";
56
+ export declare function mediaApiUrl(id: string): string;
57
+ /** Path under an artifact base (`<base>/__hx/media/:id`). No leading slash. */
58
+ export declare const ARTIFACT_MEDIA_PATH = "__hx/media";
59
+ export declare function artifactMediaPath(id: string): string;
60
+ /** Public share pages (`/m/:token`). */
61
+ export declare const MEDIA_SHARE_PATH = "/m";
62
+ /** Media ids attached to a start turn (`M::`, `/message`, gateway `ask`). */
63
+ export type StartMediaInput = {
64
+ id: string;
65
+ }[];
66
+ /** Engine context key. Distinct from the `media` outVar of `mediaNode`. */
67
+ export declare const USER_MEDIA_CONTEXT_KEY = "user_media";
68
+ /**
69
+ * Start-node outVar that exposes `StartMediaInput`.
70
+ * `media` is reserved for `mediaNode` and collides with a user input of that name.
71
+ */
72
+ export declare const USER_MEDIA_OUT_VAR = "user_media";
73
+ /** Body of `/message` and of the artifact worker gateway after a run. */
74
+ export interface MediaRunResult {
75
+ answer: string;
76
+ media: MediaRef[];
77
+ outputs?: Record<string, unknown>;
78
+ runId?: string;
79
+ }
80
+ /**
81
+ * `mediaNode.data`. `prompt` is always a string.
82
+ * With no references the runner sends that string to the provider (the object form requires `images`).
83
+ */
84
+ export interface MediaNodeData {
85
+ kind: MediaKind;
86
+ /** Catalog id. Modality must equal `kind`. */
87
+ model: string;
88
+ /** `{{ }}` template. */
89
+ prompt: string;
90
+ /** Upstream outVars of type `image`, or `media` with `mediaType: 'image'`. */
91
+ references?: string[];
92
+ params: {
93
+ aspectRatio?: string;
94
+ seed?: number;
95
+ /** Image: 1..capabilities.media.maxN. Video: always 1. */
96
+ n?: number;
97
+ duration?: number;
98
+ resolution?: string;
99
+ generateAudio?: boolean;
100
+ };
101
+ /** Filtered by `capabilities.media.providerOptionsAllow`. */
102
+ providerOptions?: Record<string, unknown>;
103
+ /** Default `capabilities.media.timeoutMs`. Cap 600_000. */
104
+ timeoutMs?: number;
105
+ }
@@ -8,6 +8,7 @@ export declare enum NodeType {
8
8
  TOOL_NODE = "toolNode",
9
9
  WORKER_NODE = "workerNode",
10
10
  CRAWL_NODE = "crawlNode",
11
- WEB_ACTIONS_NODE = "webActionsNode"
11
+ WEB_ACTIONS_NODE = "webActionsNode",
12
+ MEDIA_NODE = "mediaNode"
12
13
  }
13
- export type NODETYPES = NodeType.START_NODE | NodeType.CLASSIFIER_NODE | NodeType.MEMO_NODE | NodeType.LLM_NODE | NodeType.ANSWER_NODE | NodeType.API_NODE | NodeType.TOOL_NODE | NodeType.WORKER_NODE | NodeType.CRAWL_NODE | NodeType.WEB_ACTIONS_NODE;
14
+ export type NODETYPES = NodeType.START_NODE | NodeType.CLASSIFIER_NODE | NodeType.MEMO_NODE | NodeType.LLM_NODE | NodeType.ANSWER_NODE | NodeType.API_NODE | NodeType.TOOL_NODE | NodeType.WORKER_NODE | NodeType.CRAWL_NODE | NodeType.WEB_ACTIONS_NODE | NodeType.MEDIA_NODE;
@@ -8,13 +8,15 @@ export interface FlowEdge {
8
8
  target: string;
9
9
  sourceHandle?: string | null;
10
10
  }
11
- export type OutVarType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'image' | 'file';
11
+ export type OutVarType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'image' | 'file' | 'media';
12
12
  /** A named, public value exposed by a node result. */
13
13
  export interface OutVar {
14
14
  name: string;
15
15
  path?: string;
16
16
  type?: OutVarType;
17
17
  description?: string;
18
+ /** Set by `mediaNode` from `data.kind`. Image uploads stay `type: 'image'` and omit this. */
19
+ mediaType?: 'image' | 'video';
18
20
  }
19
21
  export interface EffectiveOutVar extends OutVar {
20
22
  source: 'default' | 'user';
@@ -13,4 +13,5 @@ export declare function findScopedSourceNode(ref: string, input: {
13
13
  currentNodeId: string;
14
14
  }): FlowNode | undefined;
15
15
  export declare function getRefTail(ref: string, nodeId: string): string;
16
+ export declare function findScopedOutVar(nodes: FlowNode[], edges: FlowEdge[], nodeId: string, ref: string): ScopedVar | undefined;
16
17
  export declare function isBinaryOutVar(outVar: Pick<OutVar, 'type'>): boolean;
@@ -1,6 +1,8 @@
1
1
  import { NodeType } from '../types/node-types';
2
2
  import type { EffectiveOutVar, FlowNode, OutVar } from '../types/var-scope';
3
- export declare function getDefaultOutVars(nodeType: NodeType): OutVar[];
3
+ export declare function getDefaultOutVars(nodeType: NodeType, data?: {
4
+ kind?: unknown;
5
+ } | null): OutVar[];
4
6
  /** Validates every public output name, including collisions with built-ins and Start inputs. */
5
7
  export declare function validateOutVars(node: FlowNode): string[];
6
8
  export declare function getEffectiveOutVars(node: FlowNode): EffectiveOutVar[];