@vimhead.dev/norn 0.1.0-tip.35436871363.1 → 0.1.0-tip.35570530940.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.d.ts CHANGED
@@ -18,8 +18,7 @@ export type NornWorkflowDeclaration<Id extends string = string, ArgsSchema exten
18
18
  (args: StaticEncode<ArgsSchema>): NornRunNext;
19
19
  readonly kind: typeof WORKFLOW_DECLARATION_KIND;
20
20
  readonly id: Id;
21
- readonly isEntrypoint: boolean;
22
- readonly instructions?: string;
21
+ readonly entrypoint: NornWorkflowEntrypoint;
23
22
  readonly args: ArgsSchema;
24
23
  readonly gate?: NornWorkflowGate<ArgsSchema> & {
25
24
  describe?(context: NornWorkflowContext<ArgsSchema, ConfigSchema, Scope>): MaybePromise<string>;
@@ -43,18 +42,17 @@ export type NornWorkflowGate<ArgsSchema extends TSchema> = unknown extends Stati
43
42
  readonly enabled: true;
44
43
  readonly fields?: never;
45
44
  };
46
- type NornWorkflowInstructions = {
47
- readonly isEntrypoint: true;
45
+ export type NornWorkflowEntrypoint = false | {
48
46
  readonly instructions: string;
49
- } | {
50
- readonly isEntrypoint: false;
51
- readonly instructions?: string;
52
47
  };
53
48
  type WorkflowConfig<Schema extends TSchema | undefined> = Schema extends TSchema ? StaticDecode<Schema> : undefined;
54
49
  export type NornWorkflowContext<ArgsSchema extends TSchema = TSchema, ConfigSchema extends TSchema | undefined = TSchema | undefined, Scope extends NornWorkflowScopeInfo | undefined = NornWorkflowScopeInfo | undefined> = {
55
50
  readonly args: StaticDecode<ArgsSchema>;
56
51
  readonly config: WorkflowConfig<ConfigSchema>;
57
52
  readonly paths: NornWorkflowPaths;
53
+ readonly agents: NornAgents;
54
+ readonly commands: NornCommands;
55
+ readonly logs: NornLogs;
58
56
  readonly run: NornRun;
59
57
  } & (Scope extends NornWorkflowScopeInfo ? {
60
58
  readonly scope: {
@@ -62,35 +60,36 @@ export type NornWorkflowContext<ArgsSchema extends TSchema = TSchema, ConfigSche
62
60
  readonly config: WorkflowConfig<Scope["config"]>;
63
61
  };
64
62
  } : {});
65
- export type NornWorkflowDefinition<Id extends string = string, ArgsSchema extends TSchema = TSchema, ConfigSchema extends TSchema | undefined = undefined, Scope extends NornWorkflowScopeInfo | undefined = undefined> = {
66
- readonly id: Id;
63
+ export type NornWorkflowDefinition<Name extends string = string, ArgsSchema extends TSchema = TSchema, ConfigSchema extends TSchema | undefined = undefined, Scope extends NornWorkflowScopeInfo | undefined = undefined> = {
64
+ readonly name: Name;
65
+ readonly entrypoint: NornWorkflowEntrypoint;
67
66
  readonly args: ArgsSchema;
68
67
  readonly config?: ConfigSchema;
69
68
  readonly gate?: NornWorkflowGate<ArgsSchema> & {
70
69
  describe?(context: NornWorkflowContext<ArgsSchema, ConfigSchema, Scope>): MaybePromise<string>;
71
70
  };
72
71
  execute(context: NornWorkflowContext<ArgsSchema, ConfigSchema, Scope>): MaybePromise<WorkflowResult>;
73
- } & NornWorkflowInstructions;
72
+ };
74
73
  export type NornWorkflowScopeInfo = {
75
74
  readonly id: string;
76
75
  readonly config?: TSchema;
77
76
  };
78
- export type NornWorkflowScope<Id extends string, ConfigSchema extends TSchema | undefined> = {
79
- readonly id: Id;
77
+ export type NornWorkflowScope<Name extends string, ConfigSchema extends TSchema | undefined> = {
78
+ readonly id: Name;
80
79
  readonly config: ConfigSchema;
81
- workflow<const LocalId extends string, ArgsSchema extends TSchema, LocalConfig extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<LocalId, ArgsSchema, LocalConfig, {
82
- readonly id: Id;
80
+ workflow<const LocalName extends string, ArgsSchema extends TSchema, LocalConfig extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<LocalName, ArgsSchema, LocalConfig, {
81
+ readonly id: Name;
83
82
  readonly config: ConfigSchema;
84
- }>): NornWorkflowDeclaration<`${Id}.${LocalId}`, ArgsSchema, LocalConfig, {
85
- readonly id: Id;
83
+ }>): NornWorkflowDeclaration<`${Name}.${LocalName}`, ArgsSchema, LocalConfig, {
84
+ readonly id: Name;
86
85
  readonly config: ConfigSchema;
87
86
  }>;
88
87
  };
89
- export declare function workflow<const Id extends string, ArgsSchema extends TSchema, ConfigSchema extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<Id, ArgsSchema, ConfigSchema>): NornWorkflowDeclaration<Id, ArgsSchema, ConfigSchema, undefined>;
90
- export declare function workflowScope<const Id extends string, ConfigSchema extends TSchema | undefined = undefined>(input: {
91
- readonly id: Id;
88
+ export declare function workflow<const Name extends string, ArgsSchema extends TSchema, ConfigSchema extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<Name, ArgsSchema, ConfigSchema>): NornWorkflowDeclaration<Name, ArgsSchema, ConfigSchema, undefined>;
89
+ export declare function workflowScope<const Name extends string, ConfigSchema extends TSchema | undefined = undefined>(input: {
90
+ readonly name: Name;
92
91
  readonly config?: ConfigSchema;
93
- }): NornWorkflowScope<Id, ConfigSchema>;
92
+ }): NornWorkflowScope<Name, ConfigSchema>;
94
93
  export type NornRunNext = {
95
94
  readonly type: "next";
96
95
  readonly workflowId: string;
@@ -364,16 +363,16 @@ export type NornRun = {
364
363
  fail(metadata: NornRunOutcomeMetadata & {
365
364
  readonly summary: string;
366
365
  }): NornRunFail;
367
- logs: {
368
- read(log: NornLogRef): Promise<string>;
369
- };
370
- commands: {
371
- run(input: NornCommandRunInput): Promise<NornCommandRunResult>;
372
- };
373
- agents: {
374
- createSession(input: NornAgentCreateSessionInput): Promise<NornAgentSession>;
375
- prompt<ResponseSchema extends TSchema>(input: NornAgentSinglePromptInput<ResponseSchema>): Promise<StaticDecode<ResponseSchema>>;
376
- };
366
+ };
367
+ export type NornLogs = {
368
+ read(log: NornLogRef): Promise<string>;
369
+ };
370
+ export type NornCommands = {
371
+ run(input: NornCommandRunInput): Promise<NornCommandRunResult>;
372
+ };
373
+ export type NornAgents = {
374
+ createSession(input: NornAgentCreateSessionInput): Promise<NornAgentSession>;
375
+ prompt<ResponseSchema extends TSchema>(input: NornAgentSinglePromptInput<ResponseSchema>): Promise<StaticDecode<ResponseSchema>>;
377
376
  };
378
377
  export type NornWorkflowSource = {
379
378
  readonly path: string;
package/dist/api.js CHANGED
@@ -12,29 +12,29 @@ import { Value } from "typebox/value";
12
12
  import { assertWorkflowMetadata, isPlainObject, jsonValueSchema } from "./schema.js";
13
13
  var WORKFLOW_DECLARATION_KIND = "norn.workflow";
14
14
  function workflow(definition) {
15
- return createWorkflow({ definition, scope: void 0 });
15
+ return createWorkflow({ definition, id: definition.name, scope: void 0 });
16
16
  }
17
17
  function createWorkflow(input) {
18
- const { definition, scope } = input;
19
- assertDeclarationId(definition.id);
20
- const callable = (args) => createWorkflowTransition({ workflowId: definition.id, args });
21
- const result = Object.assign(callable, definition, {
18
+ const { definition: { name, ...properties }, id, scope } = input;
19
+ assertDeclarationName(name);
20
+ const callable = (args) => createWorkflowTransition({ workflowId: id, args });
21
+ const result = Object.assign(callable, properties, {
22
22
  kind: WORKFLOW_DECLARATION_KIND,
23
+ id,
23
24
  scope
24
25
  });
25
- if (!isWorkflowDeclaration(result)) throw new Error(`Invalid workflow definition: ${definition.id}`);
26
26
  assertWorkflowMetadata(result);
27
+ if (!isWorkflowDeclaration(result)) throw new Error(`Invalid workflow definition: ${id}`);
27
28
  return result;
28
29
  }
29
30
  function workflowScope(input) {
30
- assertDeclarationId(input.id);
31
- const scope = { id: input.id, config: input.config };
31
+ assertDeclarationName(input.name);
32
+ const scope = { id: input.name, config: input.config };
32
33
  return {
33
- id: input.id,
34
- config: input.config,
34
+ id: scope.id,
35
+ config: scope.config,
35
36
  workflow(definition) {
36
- assertDeclarationId(definition.id);
37
- return createWorkflow({ definition: { ...definition, id: `${input.id}.${definition.id}` }, scope });
37
+ return createWorkflow({ definition, id: `${scope.id}.${definition.name}`, scope });
38
38
  }
39
39
  };
40
40
  }
@@ -56,13 +56,13 @@ function workflowRefSchema(options) {
56
56
  };
57
57
  }), { "x-norn-workflow-ref": { contributedArgsSchema: contributionSchema } });
58
58
  }
59
- function assertDeclarationId(id) {
60
- if (typeof id !== "string" || id.trim().length === 0 || id.split(".").some((segment) => segment.length === 0)) throw new Error(`Invalid workflow or scope id: ${id}`);
59
+ 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`);
61
61
  }
62
62
  function isWorkflowDeclaration(value) {
63
63
  if (typeof value !== "function") return false;
64
64
  const candidate = value;
65
- return candidate.kind === WORKFLOW_DECLARATION_KIND && typeof candidate.id === "string" && candidate.id.length > 0 && (candidate.instructions === void 0 || typeof candidate.instructions === "string") && typeof candidate.isEntrypoint === "boolean" && Boolean(candidate.args) && typeof candidate.execute === "function";
65
+ return candidate.kind === WORKFLOW_DECLARATION_KIND && typeof candidate.id === "string" && candidate.id.length > 0 && (candidate.entrypoint === false || isPlainObject(candidate.entrypoint) && typeof candidate.entrypoint.instructions === "string") && Boolean(candidate.args) && typeof candidate.execute === "function";
66
66
  }
67
67
  function isWorkflowNext(value) {
68
68
  if (!value || typeof value !== "object") return false;
package/dist/schema.js CHANGED
@@ -40,11 +40,11 @@ function assertWorkflowReferenceAnnotations(schema) {
40
40
  }
41
41
  }
42
42
  function assertWorkflowMetadata(workflow) {
43
- if (workflow.instructions !== void 0 && (typeof workflow.instructions !== "string" || workflow.instructions.trim().length === 0)) {
44
- throw new Error(`Workflow instructions must be a nonempty string: ${workflow.id}`);
45
- }
46
- if (workflow.isEntrypoint && workflow.instructions === void 0) {
47
- throw new Error(`Entrypoint workflow requires instructions: ${workflow.id}`);
43
+ const { entrypoint } = workflow;
44
+ if (entrypoint === false) return;
45
+ if (!isPlainObject(entrypoint)) throw new Error(`Workflow entrypoint must be false or an object with instructions: ${workflow.id}`);
46
+ if (typeof entrypoint.instructions !== "string" || entrypoint.instructions.trim().length === 0) {
47
+ throw new Error(`Workflow entrypoint.instructions must be a nonempty string: ${workflow.id}`);
48
48
  }
49
49
  }
50
50
  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.35436871363.1",
3
+ "version": "0.1.0-tip.35570530940.1",
4
4
  "description": "TypeScript SDK for building agent-driven and code-driven Norn workflows.",
5
5
  "type": "module",
6
6
  "license": "MIT",