anbaric-state-machine 1.21.4 → 1.22.0

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 (76) hide show
  1. package/dist/StateMachine.d.ts +28 -0
  2. package/dist/StateMachine.d.ts.map +1 -0
  3. package/{src/StateMachine.ts → dist/StateMachine.js} +85 -134
  4. package/dist/StateMachine.js.map +1 -0
  5. package/dist/actions/RemoteLLMAgenticAction.d.ts +9 -0
  6. package/dist/actions/RemoteLLMAgenticAction.d.ts.map +1 -0
  7. package/{src/actions/RemoteLLMAgenticAction.ts → dist/actions/RemoteLLMAgenticAction.js} +7 -13
  8. package/dist/actions/RemoteLLMAgenticAction.js.map +1 -0
  9. package/dist/actors/Code.d.ts +9 -0
  10. package/dist/actors/Code.d.ts.map +1 -0
  11. package/dist/actors/Code.js +11 -0
  12. package/dist/actors/Code.js.map +1 -0
  13. package/dist/actors/Human.d.ts +11 -0
  14. package/dist/actors/Human.d.ts.map +1 -0
  15. package/dist/actors/Human.js +25 -0
  16. package/dist/actors/Human.js.map +1 -0
  17. package/dist/actors/agents/OpenAIAgent.d.ts +21 -0
  18. package/dist/actors/agents/OpenAIAgent.d.ts.map +1 -0
  19. package/{src/actors/agents/OpenAIAgent.ts → dist/actors/agents/OpenAIAgent.js} +17 -36
  20. package/dist/actors/agents/OpenAIAgent.js.map +1 -0
  21. package/dist/auditing/AuditorFactory.d.ts +6 -0
  22. package/dist/auditing/AuditorFactory.d.ts.map +1 -0
  23. package/dist/auditing/AuditorFactory.js +11 -0
  24. package/dist/auditing/AuditorFactory.js.map +1 -0
  25. package/dist/auditing/ConsoleAuditor.d.ts +6 -0
  26. package/dist/auditing/ConsoleAuditor.d.ts.map +1 -0
  27. package/dist/auditing/ConsoleAuditor.js +8 -0
  28. package/dist/auditing/ConsoleAuditor.js.map +1 -0
  29. package/dist/index.d.ts +17 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +17 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/persistence/InMemoryJobPersistence.d.ts +15 -0
  34. package/dist/persistence/InMemoryJobPersistence.d.ts.map +1 -0
  35. package/{src/persistence/InMemoryJobPersistence.ts → dist/persistence/InMemoryJobPersistence.js} +0 -0
  36. package/dist/persistence/InMemoryJobPersistence.js.map +1 -0
  37. package/dist/persistence/JobPersistenceFactory.d.ts +6 -0
  38. package/dist/persistence/JobPersistenceFactory.d.ts.map +1 -0
  39. package/{src/persistence/JobPersistenceFactory.ts → dist/persistence/JobPersistenceFactory.js} +6 -8
  40. package/dist/persistence/JobPersistenceFactory.js.map +1 -0
  41. package/dist/scheduling/ConsumerFactory.d.ts +6 -0
  42. package/dist/scheduling/ConsumerFactory.d.ts.map +1 -0
  43. package/dist/scheduling/ConsumerFactory.js +15 -0
  44. package/dist/scheduling/ConsumerFactory.js.map +1 -0
  45. package/dist/scheduling/InMemoryQueue.d.ts +10 -0
  46. package/dist/scheduling/InMemoryQueue.d.ts.map +1 -0
  47. package/{src/scheduling/InMemoryQueue.ts → dist/scheduling/InMemoryQueue.js} +8 -15
  48. package/dist/scheduling/InMemoryQueue.js.map +1 -0
  49. package/dist/scheduling/PullConsumer.d.ts +17 -0
  50. package/dist/scheduling/PullConsumer.d.ts.map +1 -0
  51. package/{src/scheduling/PullConsumer.ts → dist/scheduling/PullConsumer.js} +25 -28
  52. package/dist/scheduling/PullConsumer.js.map +1 -0
  53. package/dist/scheduling/QueueFactory.d.ts +6 -0
  54. package/dist/scheduling/QueueFactory.d.ts.map +1 -0
  55. package/{src/scheduling/QueueFactory.ts → dist/scheduling/QueueFactory.js} +5 -7
  56. package/dist/scheduling/QueueFactory.js.map +1 -0
  57. package/dist/sessions/InMemorySessionResolver.d.ts +8 -0
  58. package/dist/sessions/InMemorySessionResolver.d.ts.map +1 -0
  59. package/dist/sessions/InMemorySessionResolver.js +14 -0
  60. package/dist/sessions/InMemorySessionResolver.js.map +1 -0
  61. package/dist/sessions/SessionResolverFactory.d.ts +6 -0
  62. package/dist/sessions/SessionResolverFactory.d.ts.map +1 -0
  63. package/{src/sessions/SessionResolverFactory.ts → dist/sessions/SessionResolverFactory.js} +5 -7
  64. package/dist/sessions/SessionResolverFactory.js.map +1 -0
  65. package/dist/sessions/sessionCookie.d.ts +5 -0
  66. package/dist/sessions/sessionCookie.d.ts.map +1 -0
  67. package/{src/sessions/sessionCookie.ts → dist/sessions/sessionCookie.js} +5 -7
  68. package/dist/sessions/sessionCookie.js.map +1 -0
  69. package/package.json +16 -7
  70. package/src/actors/Code.ts +0 -16
  71. package/src/actors/Human.ts +0 -32
  72. package/src/auditing/AuditorFactory.ts +0 -14
  73. package/src/auditing/ConsoleAuditor.ts +0 -13
  74. package/src/index.ts +0 -16
  75. package/src/scheduling/ConsumerFactory.ts +0 -15
  76. package/src/sessions/InMemorySessionResolver.ts +0 -20
@@ -0,0 +1,28 @@
1
+ import { Action, Actor, AppAware, Auditor, Job, JobPersistence, PropertyDefinition, Queue, State } from "anbaric-tsapi";
2
+ declare class StateMachine implements AppAware {
3
+ readonly workflowId: string;
4
+ readonly states: Map<string, State>;
5
+ readonly startState: string;
6
+ readonly dataSchema: Map<string, PropertyDefinition>;
7
+ private persistence;
8
+ private queue;
9
+ private consumer;
10
+ private machineActor;
11
+ private auditor;
12
+ private readonly NO_TRANSITION_REQUEUE_DELAY;
13
+ constructor(workflowId: string, states: Array<State>, startState?: string, dataSchema?: Array<PropertyDefinition>, persistence?: JobPersistence, queue?: Queue, auditor?: Auditor);
14
+ getAppId(): string;
15
+ private describe;
16
+ startJob(properties?: Map<string, any>, actor?: Actor): Promise<Job>;
17
+ updateJob(jobId: string, properties: Map<string, any>, actor: Actor): Promise<void>;
18
+ executeAction(jobId: string, action: Action): Promise<void>;
19
+ private progressJob;
20
+ private updateJobInternal;
21
+ private validateProperties;
22
+ private propertyProblem;
23
+ private sameValue;
24
+ cleanUp(): Promise<void>;
25
+ private authorizeActor;
26
+ }
27
+ export { StateMachine };
28
+ //# sourceMapp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CAAC,EAAE,KAAK,EAAG,KAAK,GAAI,OAAO,CAAC,IAAI,CAAC,CAO5F;IAEK,aAAa,CAAC,KAAK,EAAG,MAAM,EAAE,MAAM,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAcnE;YAEa,WAAW;YA6EX,iBAAiB;IAQ/B,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,SAAS;IAIX,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC,CAE9B;IAED,OAAO,CAAC,cAAc;CAIzB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1,43 +1,21 @@
1
- import {
2
- Action,
3
- Actor,
4
- AppAware,
5
- Auditor,
6
- Await,
7
- Consumer,
8
- currentAppId,
9
- Job,
10
- JobPersistence,
11
- PropertyDefinition,
12
- Queue,
13
- State,
14
- SystemActor,
15
- WorkflowDefinition
16
- } from "anbaric-tsapi";
17
-
18
- import {JobPersistenceFactory} from "./persistence/JobPersistenceFactory";
19
- import {QueueFactory} from "./scheduling/QueueFactory";
20
- import {ConsumerFactory} from "./scheduling/ConsumerFactory";
21
- import {AuditorFactory} from "./auditing/AuditorFactory";
22
- import {Code} from "./actors/Code";
23
-
24
- class StateMachine implements AppAware {
25
-
26
- readonly workflowId: string;
27
- readonly states: Map<string, State>;
28
- readonly startState: string;
29
- readonly dataSchema: Map<string, PropertyDefinition>;
30
-
31
- private persistence: JobPersistence;
32
- private queue: Queue;
33
- private consumer: Consumer;
34
- private machineActor: Code;
35
- private auditor: Auditor;
36
-
37
- private readonly NO_TRANSITION_REQUEUE_DELAY: number = 5 * 60_000;
38
-
39
- constructor(workflowId : string, states : Array<State>, startState? : string, dataSchema : Array<PropertyDefinition> = [], persistence : JobPersistence = JobPersistenceFactory.instance(), queue : Queue = QueueFactory.instance(), auditor : Auditor = AuditorFactory.instance()) {
40
-
1
+ import { Await, currentAppId, Job, SystemActor, WorkflowDefinition } from "anbaric-tsapi";
2
+ import { JobPersistenceFactory } from "./persistence/JobPersistenceFactory.js";
3
+ import { QueueFactory } from "./scheduling/QueueFactory.js";
4
+ import { ConsumerFactory } from "./scheduling/ConsumerFactory.js";
5
+ import { AuditorFactory } from "./auditing/AuditorFactory.js";
6
+ import { Code } from "./actors/Code.js";
7
+ class StateMachine {
8
+ workflowId;
9
+ states;
10
+ startState;
11
+ dataSchema;
12
+ persistence;
13
+ queue;
14
+ consumer;
15
+ machineActor;
16
+ auditor;
17
+ NO_TRANSITION_REQUEUE_DELAY = 5 * 60_000;
18
+ constructor(workflowId, states, startState, dataSchema = [], persistence = JobPersistenceFactory.instance(), queue = QueueFactory.instance(), auditor = AuditorFactory.instance()) {
41
19
  // The workflow's identity is the composite (appId, workflowId): the app
42
20
  // it is deployed in (from the environment, via getAppId()) and the
43
21
  // machine's own id, kept as separate values rather than a concatenated
@@ -50,93 +28,73 @@ class StateMachine implements AppAware {
50
28
  this.queue = queue;
51
29
  this.machineActor = new Code(this.workflowId, "state-machine");
52
30
  this.auditor = auditor;
53
-
54
- this.consumer = ConsumerFactory.instance(queue)
31
+ this.consumer = ConsumerFactory.instance(queue);
55
32
  this.consumer.subscribe(this.getAppId(), this.workflowId, jobId => this.progressJob(jobId));
56
-
57
- void this.auditor.audit(this.getAppId(), "state-machine", this.workflowId, SystemActor.actor, ["INITIALIZE"],
58
- "State machine initialised", this.describe()).catch(() => {});
33
+ void this.auditor.audit(this.getAppId(), "state-machine", this.workflowId, SystemActor.actor, ["INITIALIZE"], "State machine initialised", this.describe()).catch(() => { });
59
34
  }
60
-
61
- getAppId() : string {
35
+ getAppId() {
62
36
  return currentAppId();
63
37
  }
64
-
65
- private describe() : WorkflowDefinition {
66
- return WorkflowDefinition.describe(this.getAppId(), this.workflowId, this.startState,
67
- [...this.states.values()], [...this.dataSchema.values()]);
38
+ describe() {
39
+ return WorkflowDefinition.describe(this.getAppId(), this.workflowId, this.startState, [...this.states.values()], [...this.dataSchema.values()]);
68
40
  }
69
-
70
- async startJob(properties?: Map<string, any>, actor : Actor = this.machineActor): Promise<Job> {
71
-
72
- const job = new Job(crypto.randomUUID(), properties, this.startState, this.workflowId,
73
- this.getAppId(), actor?.id ?? this.workflowId);
74
-
75
- if (! this.validateProperties(properties ?? new Map(), true)) throw new Error("Invalid properties");
76
- if (! this.authorizeActor(actor, job)) throw new Error("Unauthorized");
77
-
41
+ async startJob(properties, actor = this.machineActor) {
42
+ const job = new Job(crypto.randomUUID(), properties, this.startState, this.workflowId, this.getAppId(), actor?.id ?? this.workflowId);
43
+ if (!this.validateProperties(properties ?? new Map(), true))
44
+ throw new Error("Invalid properties");
45
+ if (!this.authorizeActor(actor, job))
46
+ throw new Error("Unauthorized");
78
47
  await this.persistence.create(actor, job);
79
48
  await this.queue.enqueue(job.id, this.getAppId(), this.workflowId);
80
-
81
49
  return job;
82
50
  }
83
-
84
- async updateJob(jobId : string, properties : Map<string, any>, actor : Actor) : Promise<void> {
85
-
51
+ async updateJob(jobId, properties, actor) {
86
52
  const job = await this.persistence.retrieve(jobId, actor);
87
-
88
- if (!this.authorizeActor(actor, job)) throw new Error("Unauthorized");
89
-
53
+ if (!this.authorizeActor(actor, job))
54
+ throw new Error("Unauthorized");
90
55
  await this.updateJobInternal(actor, "Properties Updated", job, properties);
91
56
  }
92
-
93
- async executeAction(jobId : string, action : Action) : Promise<void> {
94
-
57
+ async executeAction(jobId, action) {
95
58
  const job = await this.persistence.retrieve(jobId, action.actor);
96
-
97
- if (! action.predicate(job)) throw new Error("Action predicate unmet");
98
- if (! this.authorizeActor(action.actor, job)) throw new Error("Actor not authorized to execute action");
99
-
59
+ if (!action.predicate(job))
60
+ throw new Error("Action predicate unmet");
61
+ if (!this.authorizeActor(action.actor, job))
62
+ throw new Error("Actor not authorized to execute action");
100
63
  const newProperties = await action.run(job);
101
-
102
64
  try {
103
65
  await this.updateJobInternal(action.actor, `Action ${action.name} executed on job ${job.id}: ${action.description}`, job, newProperties);
104
- } catch (error) {
66
+ }
67
+ catch (error) {
105
68
  throw new Error('The action generated invalid properties');
106
69
  }
107
70
  }
108
-
109
- private async progressJob(jobId : string) : Promise<void> {
110
-
71
+ async progressJob(jobId) {
111
72
  const job = await this.persistence.retrieve(jobId, this.machineActor);
112
- if (job.killed) return;
113
-
73
+ if (job.killed)
74
+ return;
114
75
  const currentState = this.states.get(job.state);
115
- if (currentState?.isTerminal) return;
116
-
76
+ if (currentState?.isTerminal)
77
+ return;
117
78
  // A job resuming from "Awaiting input" (re-enqueued by an update to its
118
79
  // properties) skips its actions entirely and only re-evaluates its
119
80
  // transitions - the input it was parked for drives it on.
120
81
  const wasAwaiting = job.status === Job.Status.AWAITING_INPUT;
121
- const involvedActors : Array<Actor> = [];
82
+ const involvedActors = [];
122
83
  let propertiesChanged = false;
123
-
124
- if (! wasAwaiting) {
84
+ if (!wasAwaiting) {
125
85
  for (const item of currentState?.actions ?? []) {
126
86
  if (item instanceof Await) {
127
87
  job.status = Job.Status.AWAITING_INPUT;
128
88
  job.awaitMetadata = item.waitForInput(job);
129
89
  job.waitingFor = crypto.randomUUID();
130
- await this.persistence.save(this.machineActor, `Job ${job.id} awaiting input`, job,
131
- propertiesChanged ? job.properties : undefined);
90
+ await this.persistence.save(this.machineActor, `Job ${job.id} awaiting input`, job, propertiesChanged ? job.properties : undefined);
132
91
  return;
133
92
  }
134
-
135
- if (! item.predicate(job)) continue;
136
- if (! this.authorizeActor(item.actor, job)) continue;
137
-
93
+ if (!item.predicate(job))
94
+ continue;
95
+ if (!this.authorizeActor(item.actor, job))
96
+ continue;
138
97
  const newProperties = await item.run(job);
139
-
140
98
  let applied = false;
141
99
  for (const [key, value] of newProperties) {
142
100
  const problem = this.propertyProblem(key, value);
@@ -144,86 +102,79 @@ class StateMachine implements AppAware {
144
102
  console.warn(`[${this.workflowId}] action "${item.name}" set "${key}", which ${problem}, on job ${job.id} — skipping that property.`);
145
103
  continue;
146
104
  }
147
- if (job.properties.has(key) && this.sameValue(job.properties.get(key), value)) continue;
105
+ if (job.properties.has(key) && this.sameValue(job.properties.get(key), value))
106
+ continue;
148
107
  job.properties.set(key, value);
149
108
  propertiesChanged = true;
150
109
  applied = true;
151
110
  }
152
-
153
- if (applied) involvedActors.push(item.actor);
111
+ if (applied)
112
+ involvedActors.push(item.actor);
154
113
  }
155
114
  }
156
-
157
- let newState : string | undefined = undefined;
115
+ let newState = undefined;
158
116
  for (const transition of currentState?.transitions ?? []) {
159
- if (! this.states.has(transition.to)) continue;
117
+ if (!this.states.has(transition.to))
118
+ continue;
160
119
  if (transition.predicate(job)) {
161
120
  newState = transition.to;
162
121
  break;
163
122
  }
164
123
  }
165
-
166
124
  // TODO: persistence.save should have the ability to accept multiple actors for this case.
167
125
  if (newState !== undefined) {
168
126
  job.status = Job.Status.ACTIVE;
169
127
  job.awaitMetadata = undefined;
170
128
  job.waitingFor = undefined;
171
- await this.persistence.save(involvedActors[0] ?? this.machineActor, `Job ${job.id} progressed automatically`,
172
- job, propertiesChanged ? job.properties : undefined, newState);
173
- if (! this.states.get(newState)?.isTerminal) await this.queue.enqueue(job.id, this.getAppId(), this.workflowId);
129
+ await this.persistence.save(involvedActors[0] ?? this.machineActor, `Job ${job.id} progressed automatically`, job, propertiesChanged ? job.properties : undefined, newState);
130
+ if (!this.states.get(newState)?.isTerminal)
131
+ await this.queue.enqueue(job.id, this.getAppId(), this.workflowId);
174
132
  return;
175
133
  }
176
-
177
134
  // Parked (still awaiting) or nothing changed: leave the job be until the
178
135
  // next update. Otherwise re-check this state after the back-off delay.
179
- if (wasAwaiting || ! propertiesChanged) return;
180
-
181
- await this.persistence.save(involvedActors[0] ?? this.machineActor, `Job ${job.id} progressed automatically`,
182
- job, job.properties);
136
+ if (wasAwaiting || !propertiesChanged)
137
+ return;
138
+ await this.persistence.save(involvedActors[0] ?? this.machineActor, `Job ${job.id} progressed automatically`, job, job.properties);
183
139
  await this.queue.schedule(job.id, this.getAppId(), this.workflowId, new Date(Date.now() + this.NO_TRANSITION_REQUEUE_DELAY));
184
140
  }
185
-
186
- private async updateJobInternal(actor: Actor, message : string, job: Job, newProperties?: Map<string, any>, newState? : string) {
187
-
188
- if (newProperties && !this.validateProperties(newProperties, false)) throw new Error("Invalid properties");
189
-
190
- await this.persistence.save(actor, "Properties Updated", job, newProperties, newState)
141
+ async updateJobInternal(actor, message, job, newProperties, newState) {
142
+ if (newProperties && !this.validateProperties(newProperties, false))
143
+ throw new Error("Invalid properties");
144
+ await this.persistence.save(actor, "Properties Updated", job, newProperties, newState);
191
145
  await this.queue.enqueue(job.id, this.getAppId(), this.workflowId);
192
146
  }
193
-
194
- private validateProperties(properties : Map<string, any>, isNew : boolean) : boolean {
147
+ validateProperties(properties, isNew) {
195
148
  for (const [key, value] of properties) {
196
- if (this.propertyProblem(key, value)) return false;
149
+ if (this.propertyProblem(key, value))
150
+ return false;
197
151
  }
198
-
199
- if (! isNew) return true;
200
-
152
+ if (!isNew)
153
+ return true;
201
154
  for (const [key, definition] of this.dataSchema) {
202
- if (definition.required && ! properties.has(key)) return false;
155
+ if (definition.required && !properties.has(key))
156
+ return false;
203
157
  }
204
-
205
158
  return true;
206
159
  }
207
-
208
- private propertyProblem(key : string, value : any) : string | undefined {
160
+ propertyProblem(key, value) {
209
161
  const definition = this.dataSchema.get(key);
210
- if (! definition) return "is not declared in the data schema";
211
- if (! definition.validation(value)) return "failed its validation";
162
+ if (!definition)
163
+ return "is not declared in the data schema";
164
+ if (!definition.validation(value))
165
+ return "failed its validation";
212
166
  return undefined;
213
167
  }
214
-
215
- private sameValue(a : any, b : any) : boolean {
168
+ sameValue(a, b) {
216
169
  return a === b || JSON.stringify(a) === JSON.stringify(b);
217
170
  }
218
-
219
- async cleanUp() : Promise<void> {
171
+ async cleanUp() {
220
172
  await this.consumer.cleanUp();
221
173
  }
222
-
223
- private authorizeActor(actor: Actor | undefined, job: Job) : boolean {
174
+ authorizeActor(actor, job) {
224
175
  // TODO
225
176
  return true;
226
177
  }
227
178
  }
228
-
229
- export { StateMachine }
179
+ export { StateMachine };
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Request, Job } from "anbaric-tsapi";
2
+ declare class RemoteLLMAgenticAction extends AgenticAction {
3
+ private messages;
4
+ private outputSchema;
5
+ constructor(name: string, agent: Agent, messages: Array<AgentMessage>, outputSchema: object, description?: string, id?: string);
6
+ protected requestFor(job: Job): AgentRequest;
7
+ }
8
+ export { RemoteLLMAgenticAction };
9
+ //# sourceMappingURL=RemoteLLMAgenticAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteLLMAgenticAction.d.ts","sourceRoot":"","sources":["../../src/actions/RemoteLLMAgenticAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,EAAC,MAAM,eAAe,CAAC;AAKpF,cAAM,sBAAuB,SAAQ,aAAa;IAE9C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,YAAY,CAAU;IAE9B,YAAY,IAAI,EAAG,MAAM,EAAE,KAAK,EAAG,KAAK,EAAE,QAAQ,EAAG,KAAK,CAAC,YAAY,CAAC,EAAE,YAAY,EAAG,MAAM,EACnF,WAAW,GAAG,MAAW,EAAE,EAAE,CAAC,EAAG,MAAM,EAIlD;IAED,SAAS,CAAC,UAAU,CAAC,GAAG,EAAG,GAAG,GAAI,YAAY,CAK7C;CAEJ;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
@@ -1,27 +1,21 @@
1
- import {Agent, AgenticAction, AgentMessage, AgentRequest, Job} from "anbaric-tsapi";
2
-
1
+ import { AgenticAction } from "anbaric-tsapi";
3
2
  /* An OpenAI-API-compatible agentic action: it carries a prompt as an array of
4
3
  chat messages and a JSON Schema, appends the job's properties as the final
5
4
  user message, and lets its agent's client generate the properties to write. */
6
5
  class RemoteLLMAgenticAction extends AgenticAction {
7
-
8
- private messages : Array<AgentMessage>;
9
- private outputSchema : object;
10
-
11
- constructor(name : string, agent : Agent, messages : Array<AgentMessage>, outputSchema : object,
12
- description : string = "", id? : string) {
6
+ messages;
7
+ outputSchema;
8
+ constructor(name, agent, messages, outputSchema, description = "", id) {
13
9
  super(name, agent, description, id);
14
10
  this.messages = messages;
15
11
  this.outputSchema = outputSchema;
16
12
  }
17
-
18
- protected requestFor(job : Job) : AgentRequest {
13
+ requestFor(job) {
19
14
  return {
20
15
  messages: [...this.messages, { role: "user", content: JSON.stringify(Object.fromEntries(job.properties)) }],
21
16
  outputSchema: this.outputSchema,
22
17
  };
23
18
  }
24
-
25
19
  }
26
-
27
- export { RemoteLLMAgenticAction }
20
+ export { RemoteLLMAgenticAction };
21
+ //# sourceMappingURL=RemoteLLMAgenticAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoteLLMAgenticAction.js","sourceRoot":"","sources":["../../src/actions/RemoteLLMAgenticAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,aAAa,EAAkC,MAAM,eAAe,CAAC;AAEpF;;iFAEiF;AACjF,MAAM,sBAAuB,SAAQ,aAAa;IAEtC,QAAQ,CAAuB;IAC/B,YAAY,CAAU;IAE9B,YAAY,IAAa,EAAE,KAAa,EAAE,QAA8B,EAAE,YAAqB,EACnF,WAAW,GAAY,EAAE,EAAE,EAAY;QAC/C,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAES,UAAU,CAAC,GAAS;QAC1B,OAAO;YACH,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAC3G,YAAY,EAAE,IAAI,CAAC,YAAY;SAClC,CAAC;IACN,CAAC;CAEJ;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Actor } from "anbaric-tsapi";
2
+ declare class Code implements Actor {
3
+ readonly type: "CODE";
4
+ readonly id: string;
5
+ readonly roles: Array<string>;
6
+ constructor(id: string, roles?: Array<string> | string);
7
+ }
8
+ export { Code };
9
+ //# sourceMappingURL=Code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../src/actors/Code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,cAAM,IAAK,YAAW,KAAK;IAEvB,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAU;IAChC,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B,YAAY,EAAE,EAAG,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAe,EAG/D;CAEJ;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ class Code {
2
+ type = "CODE";
3
+ id;
4
+ roles;
5
+ constructor(id, roles = "code") {
6
+ this.id = id;
7
+ this.roles = typeof roles === "string" ? [roles] : roles;
8
+ }
9
+ }
10
+ export { Code };
11
+ //# sourceMappingURL=Code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Code.js","sourceRoot":"","sources":["../../src/actors/Code.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI;IAEG,IAAI,GAAG,MAAe,CAAC;IACvB,EAAE,CAAU;IACZ,KAAK,CAAiB;IAE/B,YAAY,EAAW,EAAE,KAAK,GAA4B,MAAM;QAC5D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,CAAC;CAEJ;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { IncomingMessage } from "node:http";
2
+ import { Actor, SessionResolver } from "anbaric-tsapi";
3
+ declare class Human implements Actor {
4
+ readonly type: "HUMAN";
5
+ readonly id: string;
6
+ readonly roles: Array<string>;
7
+ constructor(id: string, roles: Array<string> | string);
8
+ static fromSession(source: string | IncomingMessage, resolver?: SessionResolver): Promise<Human>;
9
+ }
10
+ export { Human };
11
+ //# sourceMappingURL=Human.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Human.d.ts","sourceRoot":"","sources":["../../src/actors/Human.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAC,KAAK,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAIrD,cAAM,KAAM,YAAW,KAAK;IAExB,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAU;IACjC,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B,YAAY,EAAE,EAAG,MAAM,EAAE,KAAK,EAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,EAGtD;IAOD,OAAa,WAAW,CAAC,MAAM,EAAG,MAAM,GAAG,eAAe,EACjC,QAAQ,GAAG,eAAmD,GAAI,OAAO,CAAC,KAAK,CAAC,CAKxG;CAEJ;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { SessionResolverFactory } from "../sessions/SessionResolverFactory.js";
2
+ import { sessionCookie } from "../sessions/sessionCookie.js";
3
+ class Human {
4
+ type = "HUMAN";
5
+ id;
6
+ roles;
7
+ constructor(id, roles) {
8
+ this.id = id;
9
+ this.roles = typeof roles === "string" ? [roles] : roles;
10
+ }
11
+ /* Resolves the browser user behind a request to an app page into a Human,
12
+ for auditing. Takes the platform session - either the anbaric_session
13
+ token, or the incoming request to read the cookie from - and asks the
14
+ platform to verify it (an app cannot: the signing secret is platform
15
+ only). */
16
+ static async fromSession(source, resolver = SessionResolverFactory.instance()) {
17
+ const token = typeof source === "string" ? source : sessionCookie(source);
18
+ const session = token ? await resolver.resolve(token) : undefined;
19
+ if (!session)
20
+ throw new Error("Could not resolve the session");
21
+ return new Human(session.id, session.roles);
22
+ }
23
+ }
24
+ export { Human };
25
+ //# sourceMappingURL=Human.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Human.js","sourceRoot":"","sources":["../../src/actors/Human.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,sBAAsB,EAAC,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAE3D,MAAM,KAAK;IAEE,IAAI,GAAG,OAAgB,CAAC;IACxB,EAAE,CAAU;IACZ,KAAK,CAAiB;IAE/B,YAAY,EAAW,EAAE,KAA8B;QACnD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,CAAC;IAED;;;;gBAIY;IACZ,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAiC,EACjC,QAAQ,GAAqB,sBAAsB,CAAC,QAAQ,EAAE;QACnF,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAClE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;CAEJ;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { Agent, AgentRequest } from "anbaric-tsapi";
2
+ type FetchFn = (url: string, init: RequestInit) => Promise<Response>;
3
+ type OpenAIConnection = {
4
+ apiKey: string;
5
+ model: string;
6
+ baseUrl?: string;
7
+ organization?: string;
8
+ };
9
+ declare class OpenAIClient extends Agent.Client {
10
+ private connection;
11
+ private fetchFn;
12
+ private baseUrl;
13
+ constructor(connection: OpenAIConnection, fetchFn?: FetchFn);
14
+ generate(request: AgentRequest): Promise<Record<string, any>>;
15
+ }
16
+ declare class OpenAIAgent extends Agent {
17
+ constructor(id: string, role: string, connection: OpenAIConnection, fetchFn?: FetchFn);
18
+ }
19
+ export { OpenAIAgent, OpenAIClient };
20
+ export type { OpenAIConnection };
21
+ //# sourceMappingURL=OpenAIAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIAgent.d.ts","sourceRoot":"","sources":["../../../src/actors/agents/OpenAIAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAElD,KAAK,OAAO,GAAG,CAAC,GAAG,EAAG,MAAM,EAAE,IAAI,EAAG,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvE,KAAK,gBAAgB,GAAG;IACpB,MAAM,EAAG,MAAM,CAAC;IAChB,KAAK,EAAG,MAAM,CAAC;IACf,OAAO,CAAC,EAAG,MAAM,CAAC;IAClB,YAAY,CAAC,EAAG,MAAM,CAAC;CAC1B,CAAC;AAqBF,cAAM,YAAa,SAAQ,KAAK,CAAC,MAAM;IAIvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,OAAO,CAAU;IAEzB,YAAoB,UAAU,EAAG,gBAAgB,EAC7B,OAAO,GAAG,OAAyC,EAGtE;IAEK,QAAQ,CAAC,OAAO,EAAG,YAAY,GAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CA2BpE;CAEJ;AAGD,cAAM,WAAY,SAAQ,KAAK;IAE3B,YAAY,EAAE,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,EAAE,UAAU,EAAG,gBAAgB,EACzD,OAAO,GAAG,OAAyC,EAE9D;CAEJ;AAED,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA;AACpC,YAAY,EAAE,gBAAgB,EAAE,CAAA"}
@@ -1,22 +1,11 @@
1
- import {Agent, AgentRequest} from "anbaric-tsapi";
2
-
3
- type FetchFn = (url : string, init : RequestInit) => Promise<Response>;
4
-
5
- type OpenAIConnection = {
6
- apiKey : string,
7
- model : string,
8
- baseUrl? : string,
9
- organization? : string,
10
- };
11
-
12
- const strictSchema = (schema : any) : any => {
1
+ import { Agent } from "anbaric-tsapi";
2
+ const strictSchema = (schema) => {
13
3
  if (schema?.type === "object" && schema.properties) {
14
4
  return {
15
5
  ...schema,
16
6
  required: Object.keys(schema.properties),
17
7
  additionalProperties: false,
18
- properties: Object.fromEntries(
19
- Object.entries(schema.properties).map(([key, property]) => [key, strictSchema(property)])),
8
+ properties: Object.fromEntries(Object.entries(schema.properties).map(([key, property]) => [key, strictSchema(property)])),
20
9
  };
21
10
  }
22
11
  if (schema?.type === "array" && schema.items) {
@@ -24,21 +13,20 @@ const strictSchema = (schema : any) : any => {
24
13
  }
25
14
  return schema;
26
15
  };
27
-
28
16
  /* The functional half of an OpenAI agent: asks an OpenAI-compatible chat
29
17
  completions endpoint for JSON conforming to the request's schema via
30
18
  structured outputs. */
31
19
  class OpenAIClient extends Agent.Client {
32
-
33
- private baseUrl : string;
34
-
35
- constructor(private connection : OpenAIConnection,
36
- private fetchFn : FetchFn = (url, init) => fetch(url, init)) {
20
+ connection;
21
+ fetchFn;
22
+ baseUrl;
23
+ constructor(connection, fetchFn = (url, init) => fetch(url, init)) {
37
24
  super();
25
+ this.connection = connection;
26
+ this.fetchFn = fetchFn;
38
27
  this.baseUrl = connection.baseUrl ?? "https://api.openai.com/v1";
39
28
  }
40
-
41
- async generate(request : AgentRequest) : Promise<Record<string, any>> {
29
+ async generate(request) {
42
30
  const response = await this.fetchFn(`${this.baseUrl}/chat/completions`, {
43
31
  method: "POST",
44
32
  headers: {
@@ -55,29 +43,22 @@ class OpenAIClient extends Agent.Client {
55
43
  },
56
44
  }),
57
45
  });
58
-
59
46
  if (!response.ok) {
60
- const problem = await response.json().catch(() => ({})) as { error? : { message? : string } };
47
+ const problem = await response.json().catch(() => ({}));
61
48
  throw new Error(`The OpenAI request failed with status ${response.status}${problem.error?.message ? `: ${problem.error.message}` : ""}`);
62
49
  }
63
-
64
- const body = await response.json() as { choices? : Array<{ message? : { content? : string } }> };
50
+ const body = await response.json();
65
51
  const content = body.choices?.[0]?.message?.content;
66
- if (typeof content !== "string") throw new Error("The OpenAI response carried no structured content");
52
+ if (typeof content !== "string")
53
+ throw new Error("The OpenAI response carried no structured content");
67
54
  return JSON.parse(content);
68
55
  }
69
-
70
56
  }
71
-
72
57
  /* A light agent backed by an OpenAI-compatible chat completions endpoint. */
73
58
  class OpenAIAgent extends Agent {
74
-
75
- constructor(id : string, role : string, connection : OpenAIConnection,
76
- fetchFn : FetchFn = (url, init) => fetch(url, init)) {
59
+ constructor(id, role, connection, fetchFn = (url, init) => fetch(url, init)) {
77
60
  super(id, role, new OpenAIClient(connection, fetchFn));
78
61
  }
79
-
80
62
  }
81
-
82
- export { OpenAIAgent, OpenAIClient }
83
- export type { OpenAIConnection }
63
+ export { OpenAIAgent, OpenAIClient };
64
+ //# sourceMappingURL=OpenAIAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAIAgent.js","sourceRoot":"","sources":["../../../src/actors/agents/OpenAIAgent.ts"],"names":[],"mappings":"AAAA,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E,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;CAEJ;AAED,6EAA6E;AAC7E,MAAM,WAAY,SAAQ,KAAK;IAE3B,YAAY,EAAW,EAAE,IAAa,EAAE,UAA6B,EACzD,OAAO,GAAa,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC;QAC3D,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;CAEJ;AAED,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { Auditor } from "anbaric-tsapi";
2
+ declare const AuditorFactory: {
3
+ instance(): Auditor;
4
+ };
5
+ export { AuditorFactory };
6
+ //# sourceMappingURL=AuditorFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditorFactory.d.ts","sourceRoot":"","sources":["../../src/auditing/AuditorFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAItC,QAAA,MAAM,cAAc;IAEhB,QAAQ,IAAK,OAAO;CAKvB,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAA"}