@elaraai/e3-types 1.0.5 → 1.0.7

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/src/runner.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+
6
+ /**
7
+ * Runner wire types for e3 functions.
8
+ *
9
+ * `RunnerType` is the wire image of the SDK's `Runner` union (minus its
10
+ * `custom` raw-argv runtime — see the security note below). It pins the
11
+ * executable to a known runtime for every tag, so a function call can never
12
+ * name its own executable; only platform flags vary.
13
+ *
14
+ * A `platforms` entry is just a `-p <name>` flag on the wire; the SDK's
15
+ * `Platform<Known> | { custom }` distinction is authoring sugar that
16
+ * collapses to a string.
17
+ */
18
+
19
+ import { VariantType, StructType, ArrayType, StringType, ValueTypeOf } from '@elaraai/east';
20
+
21
+ /**
22
+ * Wire representation of a runner — shared by tasks and functions
23
+ * (symmetric: both carry `runner: RunnerType`).
24
+ *
25
+ * The known-runtime tags name a runtime binary; `platforms` are passed as
26
+ * `-p` flags. `custom` carries a raw argv prefix: for functions it is the
27
+ * executed command (the standard `-i/-o/<ir>` suffix is appended, so the
28
+ * command must speak the runner CLI convention); for tasks it is routing
29
+ * metadata only — a task's `commandIr` remains authoritative for execution.
30
+ * Package authors can already execute arbitrary commands via custom tasks,
31
+ * so `custom` grants no capability that tasks don't have.
32
+ */
33
+ export const RunnerType = VariantType({
34
+ east_node: StructType({ platforms: ArrayType(StringType) }),
35
+ east_py: StructType({ platforms: ArrayType(StringType) }),
36
+ east_c: StructType({ platforms: ArrayType(StringType) }),
37
+ custom: StructType({ command: ArrayType(StringType) }),
38
+ });
39
+ export type RunnerType = typeof RunnerType;
40
+
41
+ export type RunnerValue = ValueTypeOf<typeof RunnerType>;
42
+
43
+ function flags(platforms: string[]): string[] {
44
+ return platforms.flatMap((p) => ['-p', p]);
45
+ }
46
+
47
+ /**
48
+ * Resolve a {@link RunnerType} value to the argv prefix (the wire-value
49
+ * analogue of the SDK's `runnerToCommand`). Lives in e3-types so both
50
+ * e3-core (local) and the cloud execution kernel import the one resolver.
51
+ *
52
+ * Variant tags use underscores (`east_node`) mapped to the binary name
53
+ * (`east-node`) here.
54
+ */
55
+ export function runnerToArgv(r: RunnerValue): string[] {
56
+ switch (r.type) {
57
+ case 'east_node': return ['east-node', 'run', ...flags(r.value.platforms)];
58
+ case 'east_py': return ['east-py', 'run', ...flags(r.value.platforms)];
59
+ case 'east_c': return ['east-c', 'run', ...flags(r.value.platforms)];
60
+ case 'custom': return [...r.value.command];
61
+ }
62
+ }
package/src/task.ts CHANGED
@@ -18,6 +18,7 @@
18
18
 
19
19
  import { StructType, StringType, ArrayType, BlobType, OptionType, ValueTypeOf } from '@elaraai/east';
20
20
  import { TreePathType } from './structure.js';
21
+ import { RunnerType } from './runner.js';
21
22
 
22
23
  /**
23
24
  * Task object stored in the object store.
@@ -64,6 +65,15 @@ export const TaskObjectType = StructType({
64
65
  kind: OptionType(StringType),
65
66
  /** Opaque extension metadata (beast2-encoded). Interpreted by the kind-specific consumer. */
66
67
  metadata: OptionType(BlobType),
68
+ /**
69
+ * The task's runner, as routing metadata (symmetric with
70
+ * FunctionObject.runner). For `custom` runners, `commandIr` remains
71
+ * authoritative for execution — the wire command is informational.
72
+ *
73
+ * NOTE: added as a hard cutover (no dual decoder) — packages exported by
74
+ * older SDKs must be re-exported.
75
+ */
76
+ runner: RunnerType,
67
77
  });
68
78
  export type TaskObjectType = typeof TaskObjectType;
69
79