@wopr-network/defcon 1.0.1 → 1.0.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.
@@ -138,10 +138,11 @@ export function createHttpServer(deps) {
138
138
  router.add("POST", "/api/entities", async (req) => {
139
139
  const flowName = req.body?.flow;
140
140
  const refs = req.body?.refs;
141
+ const payload = req.body?.payload;
141
142
  if (!flowName)
142
143
  return { status: 400, body: { error: "Missing required field: flow" } };
143
144
  try {
144
- const entity = await deps.engine.createEntity(flowName, refs);
145
+ const entity = await deps.engine.createEntity(flowName, refs, payload);
145
146
  return { status: 201, body: entity };
146
147
  }
147
148
  catch (err) {
@@ -54,7 +54,7 @@ export declare class Engine {
54
54
  adapter: string;
55
55
  id: string;
56
56
  [key: string]: unknown;
57
- }>): Promise<Entity>;
57
+ }>, payload?: Record<string, unknown>): Promise<Entity>;
58
58
  claimWork(role: string, flowName?: string, worker_id?: string): Promise<ClaimWorkResult | "all_claimed" | null>;
59
59
  private buildPromptForEntity;
60
60
  getStatus(): Promise<EngineStatus>;
@@ -241,11 +241,19 @@ export class Engine {
241
241
  }
242
242
  return result;
243
243
  }
244
- async createEntity(flowName, refs) {
244
+ async createEntity(flowName, refs, payload) {
245
245
  const flow = await this.flowRepo.getByName(flowName);
246
246
  if (!flow)
247
247
  throw new NotFoundError(`Flow "${flowName}" not found`);
248
- const entity = await this.entityRepo.create(flow.id, flow.initialState, refs);
248
+ let entity = await this.entityRepo.create(flow.id, flow.initialState, refs);
249
+ // Store any caller-supplied payload as initial artifacts so prompt templates
250
+ // can access refs like {{entity.artifacts.refs.linear.id}}.
251
+ if (payload && Object.keys(payload).length > 0) {
252
+ await this.entityRepo.updateArtifacts(entity.id, payload);
253
+ const refreshed = await this.entityRepo.get(entity.id);
254
+ if (refreshed)
255
+ entity = refreshed;
256
+ }
249
257
  await this.eventEmitter.emit({
250
258
  type: "entity.created",
251
259
  entityId: entity.id,
@@ -30,7 +30,18 @@ export async function buildInvocation(state, entity, adapters, flow, logger = co
30
30
  }
31
31
  }
32
32
  }));
33
- const context = { entity, state, refs: resolvedRefs, flow: flow ?? null };
33
+ // Merge payload-stored refs (entity.artifacts.refs) into entity.refs for template context,
34
+ // so {{entity.refs.linear.id}} works whether refs were set via formal adapters or via payload.
35
+ // Normalize to empty object so Handlebars strict mode doesn't throw on missing paths.
36
+ const artifactRefs = entity.artifacts !== null &&
37
+ typeof entity.artifacts === "object" &&
38
+ "refs" in entity.artifacts &&
39
+ entity.artifacts.refs !== null &&
40
+ typeof entity.artifacts.refs === "object"
41
+ ? entity.artifacts.refs
42
+ : {};
43
+ const entityForContext = { ...entity, refs: { ...artifactRefs, ...(entity.refs ?? {}) } };
44
+ const context = { entity: entityForContext, state, refs: resolvedRefs, flow: flow ?? null };
34
45
  let prompt = "";
35
46
  let systemPrompt = "";
36
47
  let userContent = "";
@@ -10,8 +10,18 @@ export async function executeOnEnter(onEnter, entity, entityRepo) {
10
10
  // Render command via Handlebars
11
11
  const hbs = getHandlebars();
12
12
  let renderedCommand;
13
+ // Merge artifact refs into entity.refs so onEnter command templates like
14
+ // {{entity.refs.github.repo}} resolve correctly for REST-created entities.
15
+ const artifactRefs = entity.artifacts !== null &&
16
+ typeof entity.artifacts === "object" &&
17
+ "refs" in entity.artifacts &&
18
+ entity.artifacts.refs !== null &&
19
+ typeof entity.artifacts.refs === "object"
20
+ ? entity.artifacts.refs
21
+ : {};
22
+ const entityForContext = { ...entity, refs: { ...artifactRefs, ...(entity.refs ?? {}) } };
13
23
  try {
14
- renderedCommand = hbs.compile(onEnter.command)({ entity });
24
+ renderedCommand = hbs.compile(onEnter.command)({ entity: entityForContext });
15
25
  }
16
26
  catch (err) {
17
27
  const error = `onEnter template error: ${err instanceof Error ? err.message : String(err)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/defcon",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@9.15.4",
6
6
  "engines": {