@vimhead.dev/norn 0.1.0-tip.35614826665.1 → 0.1.0-tip.35724621678.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/dist/api.js CHANGED
@@ -1,21 +1,32 @@
1
1
  // src/api.ts
2
- import { Type } from "typebox";
2
+ import {
3
+ Type
4
+ } from "typebox";
3
5
 
4
6
  // ../core/src/workflow-transition.ts
5
7
  function createWorkflowTransition(input) {
6
- if (typeof input.workflowId !== "string" || input.workflowId.trim().length === 0) throw new Error("Workflow transition requires a nonempty workflow ID");
8
+ if (typeof input.workflowId !== "string" || input.workflowId.trim().length === 0)
9
+ throw new Error("Workflow transition requires a nonempty workflow ID");
7
10
  return { type: "next", workflowId: input.workflowId, args: input.args };
8
11
  }
9
12
 
10
13
  // src/api.ts
11
14
  import { Value } from "typebox/value";
12
- import { assertWorkflowMetadata, isPlainObject, jsonValueSchema } from "./schema.js";
15
+ import {
16
+ assertWorkflowMetadata,
17
+ isPlainObject,
18
+ jsonValueSchema
19
+ } from "./schema.js";
13
20
  var WORKFLOW_DECLARATION_KIND = "norn.workflow";
14
21
  function workflow(definition) {
15
22
  return createWorkflow({ definition, id: definition.name, scope: void 0 });
16
23
  }
17
24
  function createWorkflow(input) {
18
- const { definition: { name, ...properties }, id, scope } = input;
25
+ const {
26
+ definition: { name, ...properties },
27
+ id,
28
+ scope
29
+ } = input;
19
30
  assertDeclarationName(name);
20
31
  const callable = (args) => createWorkflowTransition({ workflowId: id, args });
21
32
  const result = Object.assign(callable, properties, {
@@ -24,7 +35,8 @@ function createWorkflow(input) {
24
35
  scope
25
36
  });
26
37
  assertWorkflowMetadata(result);
27
- if (!isWorkflowDeclaration(result)) throw new Error(`Invalid workflow definition: ${id}`);
38
+ if (!isWorkflowDeclaration(result))
39
+ throw new Error(`Invalid workflow definition: ${id}`);
28
40
  return result;
29
41
  }
30
42
  function workflowScope(input) {
@@ -34,30 +46,47 @@ function workflowScope(input) {
34
46
  id: scope.id,
35
47
  config: scope.config,
36
48
  workflow(definition) {
37
- return createWorkflow({ definition, id: `${scope.id}.${definition.name}`, scope });
49
+ return createWorkflow({
50
+ definition,
51
+ id: `${scope.id}.${definition.name}`,
52
+ scope
53
+ });
38
54
  }
39
55
  };
40
56
  }
41
57
  var emptyWorkflowRefArgsSchema = Type.Object({});
42
58
  var workflowReferenceInputSchema = Type.Union([
43
59
  Type.String({ minLength: 1 }),
44
- Type.Object({ workflow: Type.String({ minLength: 1 }), forwardArgs: Type.Record(Type.String(), Type.Unknown()) })
60
+ Type.Object({
61
+ workflow: Type.String({ minLength: 1 }),
62
+ forwardArgs: Type.Record(Type.String(), Type.Unknown())
63
+ })
45
64
  ]);
46
65
  function workflowRefSchema(options) {
47
66
  const contributionSchema = options?.args ?? emptyWorkflowRefArgsSchema;
48
- return Type.With(Type.Decode(workflowReferenceInputSchema, (reference) => {
49
- const workflowId = typeof reference === "string" ? reference : reference.workflow;
50
- const forwardArgs = typeof reference === "string" ? {} : reference.forwardArgs;
51
- return (args) => {
52
- Value.Assert(contributionSchema, args);
53
- if (!isPlainObject(args)) throw new Error("Workflow reference contributions must be objects");
54
- Value.Assert(jsonValueSchema, args);
55
- return createWorkflowTransition({ workflowId, args: { ...forwardArgs, ...args } });
56
- };
57
- }), { "x-norn-workflow-ref": { contributedArgsSchema: contributionSchema } });
67
+ return Type.With(
68
+ Type.Decode(workflowReferenceInputSchema, (reference) => {
69
+ const workflowId = typeof reference === "string" ? reference : reference.workflow;
70
+ const forwardArgs = typeof reference === "string" ? {} : reference.forwardArgs;
71
+ return (args) => {
72
+ Value.Assert(contributionSchema, args);
73
+ if (!isPlainObject(args))
74
+ throw new Error("Workflow reference contributions must be objects");
75
+ Value.Assert(jsonValueSchema, args);
76
+ return createWorkflowTransition({
77
+ workflowId,
78
+ args: { ...forwardArgs, ...args }
79
+ });
80
+ };
81
+ }),
82
+ { "x-norn-workflow-ref": { contributedArgsSchema: contributionSchema } }
83
+ );
58
84
  }
59
85
  function assertDeclarationName(name) {
60
- if (typeof name !== "string" || name.trim().length === 0 || name.includes(".")) throw new Error(`Invalid workflow or scope name: ${name}; expected a nonempty name without dots`);
86
+ if (typeof name !== "string" || name.trim().length === 0 || name.includes("."))
87
+ throw new Error(
88
+ `Invalid workflow or scope name: ${name}; expected a nonempty name without dots`
89
+ );
61
90
  }
62
91
  function isWorkflowDeclaration(value) {
63
92
  if (typeof value !== "function") return false;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { CreateAgentSessionOptions, EventBus, PromptOptions, ToolDefinition } from "@earendil-works/pi-coding-agent";
1
+ export type { CreateAgentSessionOptions, EventBus, PromptOptions, ToolDefinition, } from "@earendil-works/pi-coding-agent";
2
2
  export * from "./api.ts";
package/dist/schema.js CHANGED
@@ -2,20 +2,27 @@
2
2
  import { Type } from "typebox";
3
3
  import { Meta } from "typebox/schema";
4
4
  import { Value } from "typebox/value";
5
- var jsonValueSchema = Type.Cyclic({
6
- Json: Type.Union([
7
- Type.Null(),
8
- Type.Boolean(),
9
- Type.Number(),
10
- Type.String(),
11
- Type.Array(Type.Ref("Json")),
12
- Type.Refine(Type.Record(Type.String(), Type.Ref("Json")), (value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
13
- ])
14
- }, "Json");
5
+ var jsonValueSchema = Type.Cyclic(
6
+ {
7
+ Json: Type.Union([
8
+ Type.Null(),
9
+ Type.Boolean(),
10
+ Type.Number(),
11
+ Type.String(),
12
+ Type.Array(Type.Ref("Json")),
13
+ Type.Refine(
14
+ Type.Record(Type.String(), Type.Ref("Json")),
15
+ (value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null
16
+ )
17
+ ])
18
+ },
19
+ "Json"
20
+ );
15
21
  function inspectSchema(schema) {
16
22
  const inspected = JSON.parse(JSON.stringify(schema));
17
23
  Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], inspected);
18
- if (!isPlainObject(inspected)) throw new Error("Norn inspection requires an object schema");
24
+ if (!isPlainObject(inspected))
25
+ throw new Error("Norn inspection requires an object schema");
19
26
  assertWorkflowReferenceAnnotations(inspected);
20
27
  return inspected;
21
28
  }
@@ -23,28 +30,58 @@ function assertWorkflowReferenceAnnotations(schema) {
23
30
  if (!isPlainObject(schema)) return;
24
31
  if (Object.hasOwn(schema, "x-norn-workflow-ref")) {
25
32
  const annotation = schema["x-norn-workflow-ref"];
26
- if (!isPlainObject(annotation) || !Object.hasOwn(annotation, "contributedArgsSchema")) throw new Error("Invalid workflow reference annotation");
27
- Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], annotation.contributedArgsSchema);
33
+ if (!isPlainObject(annotation) || !Object.hasOwn(annotation, "contributedArgsSchema"))
34
+ throw new Error("Invalid workflow reference annotation");
35
+ Value.Assert(
36
+ Meta["https://json-schema.org/draft/2020-12/schema"],
37
+ annotation.contributedArgsSchema
38
+ );
28
39
  assertWorkflowReferenceAnnotations(annotation.contributedArgsSchema);
29
40
  }
30
- for (const keyword of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) {
41
+ for (const keyword of [
42
+ "properties",
43
+ "patternProperties",
44
+ "$defs",
45
+ "definitions",
46
+ "dependentSchemas"
47
+ ]) {
31
48
  const schemas = schema[keyword];
32
- if (isPlainObject(schemas)) for (const child of Object.values(schemas)) assertWorkflowReferenceAnnotations(child);
49
+ if (isPlainObject(schemas))
50
+ for (const child of Object.values(schemas))
51
+ assertWorkflowReferenceAnnotations(child);
33
52
  }
34
53
  for (const keyword of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
35
54
  const schemas = schema[keyword];
36
- if (Array.isArray(schemas)) for (const child of schemas) assertWorkflowReferenceAnnotations(child);
55
+ if (Array.isArray(schemas))
56
+ for (const child of schemas) assertWorkflowReferenceAnnotations(child);
37
57
  }
38
- for (const keyword of ["additionalProperties", "unevaluatedProperties", "propertyNames", "items", "contains", "not", "if", "then", "else", "unevaluatedItems", "contentSchema"]) {
58
+ for (const keyword of [
59
+ "additionalProperties",
60
+ "unevaluatedProperties",
61
+ "propertyNames",
62
+ "items",
63
+ "contains",
64
+ "not",
65
+ "if",
66
+ "then",
67
+ "else",
68
+ "unevaluatedItems",
69
+ "contentSchema"
70
+ ]) {
39
71
  assertWorkflowReferenceAnnotations(schema[keyword]);
40
72
  }
41
73
  }
42
74
  function assertWorkflowMetadata(workflow) {
43
75
  const { entrypoint } = workflow;
44
76
  if (entrypoint === false) return;
45
- if (!isPlainObject(entrypoint)) throw new Error(`Workflow entrypoint must be false or an object with instructions: ${workflow.id}`);
77
+ if (!isPlainObject(entrypoint))
78
+ throw new Error(
79
+ `Workflow entrypoint must be false or an object with instructions: ${workflow.id}`
80
+ );
46
81
  if (typeof entrypoint.instructions !== "string" || entrypoint.instructions.trim().length === 0) {
47
- throw new Error(`Workflow entrypoint.instructions must be a nonempty string: ${workflow.id}`);
82
+ throw new Error(
83
+ `Workflow entrypoint.instructions must be a nonempty string: ${workflow.id}`
84
+ );
48
85
  }
49
86
  }
50
87
  function unwrapSchema(schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vimhead.dev/norn",
3
- "version": "0.1.0-tip.35614826665.1",
3
+ "version": "0.1.0-tip.35724621678.1",
4
4
  "description": "TypeScript SDK for building agent-driven and code-driven Norn workflows.",
5
5
  "type": "module",
6
6
  "license": "MIT",