@atolis-hq/wake 0.3.100 → 0.3.101
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/src/bootstrap/integration-runtime.js +2 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/integrations/application/agent-run-publication-reactor.js +26 -7
- package/dist/src/integrations/contracts/reply-routing.js +16 -0
- package/dist/src/integrations/github/application/reply-target-selector.js +17 -0
- package/dist/src/integrations/github/contracts/config.js +42 -2
- package/dist/src/integrations/github/index.js +1 -0
- package/dist/src/integrations/github/provider.js +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/package.json +1 -1
|
@@ -96,12 +96,14 @@ export async function composeIntegrationRuntime(input) {
|
|
|
96
96
|
runs: input.execution,
|
|
97
97
|
});
|
|
98
98
|
const runs = new RunRepository(input.journal);
|
|
99
|
+
const replies = providers.find((provider) => provider.replyPublication !== undefined)?.replyPublication;
|
|
99
100
|
const agentRunPublications = new AgentRunPublicationReactor({
|
|
100
101
|
journal: input.journal,
|
|
101
102
|
checkpoints: input.checkpoints,
|
|
102
103
|
runs,
|
|
103
104
|
resources: input.resources,
|
|
104
105
|
orchestration: input.orchestration,
|
|
106
|
+
...(replies === undefined ? {} : { replies }),
|
|
105
107
|
});
|
|
106
108
|
const watch = createWatchReactor(input.orchestration, input.journal, input.checkpoints, runs);
|
|
107
109
|
const resourceTransitionEvidence = createCapabilityResourceTransitionEvidence({
|
|
@@ -2,10 +2,12 @@ import { BuiltInActivityName } from '../../activities/index.js';
|
|
|
2
2
|
import { RunStatus } from '../../execution/index.js';
|
|
3
3
|
import { createEventDraft, EventActorKind, EventSourceKind, } from '../../kernel/index.js';
|
|
4
4
|
import { ApprovalAuthorityKind, isApprovalAwaitingSignalKind, OrchestrationEventType, OrchestrationStreamKind, WatchGateVerdictSignal, } from '../../orchestration/index.js';
|
|
5
|
-
import { ResourceCorrelationRole, resourceStream } from '../../resources/index.js';
|
|
5
|
+
import { BuiltInResourceKind, ResourceCorrelationRole, resourceStream, } from '../../resources/index.js';
|
|
6
|
+
import { ReplyTarget } from '../contracts/reply-routing.js';
|
|
6
7
|
import { DeliveryIntentEventType } from '../delivery/contracts/intents.js';
|
|
8
|
+
import { defaultReplyPublication, selectReplyTarget, } from '../github/application/reply-target-selector.js';
|
|
7
9
|
import { projectTerminalAgentRunReport } from './terminal-agent-run-report.js';
|
|
8
|
-
/** Projects terminal agent runs into one durable outbound intent per
|
|
10
|
+
/** Projects terminal agent runs into one durable outbound intent per configured resource. */
|
|
9
11
|
export class AgentRunPublicationReactor {
|
|
10
12
|
dependencies;
|
|
11
13
|
constructor(dependencies) {
|
|
@@ -39,14 +41,18 @@ export class AgentRunPublicationReactor {
|
|
|
39
41
|
const workflow = allWorkflows.find((value) => value.workflowInstanceId === run.workflowInstanceId);
|
|
40
42
|
if (workflow === undefined)
|
|
41
43
|
return;
|
|
42
|
-
const primary = (await this.dependencies.resources.correlationsForWork(workflow.workItemId)).find((value) => value.role === ResourceCorrelationRole.Primary);
|
|
43
|
-
if (primary === undefined)
|
|
44
|
-
return;
|
|
45
44
|
const stage = await this.stageForActivation(workflow.workflowInstanceId, run.activationId);
|
|
46
45
|
const report = projectTerminalAgentRunReport(reportInput(run, stage, workflow, allWorkflows));
|
|
47
46
|
if (report === null)
|
|
48
47
|
return;
|
|
49
|
-
const
|
|
48
|
+
const replies = this.dependencies.replies ?? defaultReplyPublication;
|
|
49
|
+
const target = selectReplyTarget({ stage, outcome: report.outcome }, replies.rules, replies.default);
|
|
50
|
+
if (target === ReplyTarget.None)
|
|
51
|
+
return;
|
|
52
|
+
const resource = await this.resourceForTarget(workflow.workItemId, target);
|
|
53
|
+
if (resource === undefined)
|
|
54
|
+
return;
|
|
55
|
+
const stream = resourceStream(resource.resourceId);
|
|
50
56
|
const sequence = (await this.dependencies.journal.readStream(stream)).length;
|
|
51
57
|
try {
|
|
52
58
|
await this.dependencies.journal.append(stream, sequence, [
|
|
@@ -62,7 +68,7 @@ export class AgentRunPublicationReactor {
|
|
|
62
68
|
payload: {
|
|
63
69
|
workflowInstanceId: run.workflowInstanceId,
|
|
64
70
|
activationId: run.activationId,
|
|
65
|
-
resourceId:
|
|
71
|
+
resourceId: resource.resourceId,
|
|
66
72
|
report,
|
|
67
73
|
},
|
|
68
74
|
}),
|
|
@@ -72,6 +78,19 @@ export class AgentRunPublicationReactor {
|
|
|
72
78
|
/* idempotency is the deterministic run event id */
|
|
73
79
|
}
|
|
74
80
|
}
|
|
81
|
+
async resourceForTarget(workItemId, target) {
|
|
82
|
+
const correlations = await this.dependencies.resources.correlationsForWork(workItemId);
|
|
83
|
+
const primary = () => correlations.find((value) => value.role === ResourceCorrelationRole.Primary);
|
|
84
|
+
if (target === ReplyTarget.Primary)
|
|
85
|
+
return primary();
|
|
86
|
+
const kind = target === ReplyTarget.Issue ? BuiltInResourceKind.Issue : BuiltInResourceKind.PullRequest;
|
|
87
|
+
for (const correlation of correlations) {
|
|
88
|
+
const resource = await this.dependencies.resources.get(correlation.resourceId);
|
|
89
|
+
if (resource?.kind === kind)
|
|
90
|
+
return correlation;
|
|
91
|
+
}
|
|
92
|
+
return primary();
|
|
93
|
+
}
|
|
75
94
|
async stageForActivation(workflowInstanceId, activationId) {
|
|
76
95
|
const events = await this.dependencies.journal.readStream({
|
|
77
96
|
kind: OrchestrationStreamKind.WorkflowInstance,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ActivityOutcomeKind, ProviderPermission } from '../../activities/index.js';
|
|
2
|
+
import { BuiltInResourceKind, ResourceCorrelationRole } from '../../resources/index.js';
|
|
3
|
+
export const ReplyTarget = {
|
|
4
|
+
Primary: ResourceCorrelationRole.Primary,
|
|
5
|
+
Issue: BuiltInResourceKind.Issue,
|
|
6
|
+
PullRequest: BuiltInResourceKind.PullRequest,
|
|
7
|
+
None: ProviderPermission.None,
|
|
8
|
+
};
|
|
9
|
+
export const ReplyNeedsClarificationConfig = 'needs-clarification';
|
|
10
|
+
export const ReplyOutcomeConfig = {
|
|
11
|
+
Done: ActivityOutcomeKind.Done,
|
|
12
|
+
Rejected: ActivityOutcomeKind.Rejected,
|
|
13
|
+
Blocked: ActivityOutcomeKind.Blocked,
|
|
14
|
+
Failed: ActivityOutcomeKind.Failed,
|
|
15
|
+
NeedsClarification: ReplyNeedsClarificationConfig,
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { matchesRequiredValues } from '../../../kernel/index.js';
|
|
2
|
+
import { ReplyTarget, } from '../../contracts/reply-routing.js';
|
|
3
|
+
/** Selects one configured reply target; the first matching rule wins. */
|
|
4
|
+
export function selectReplyTarget(candidate, rules, fallback) {
|
|
5
|
+
return rules.find((rule) => ruleMatches(rule, candidate))?.target ?? fallback;
|
|
6
|
+
}
|
|
7
|
+
function ruleMatches(rule, candidate) {
|
|
8
|
+
return (matchesRequiredValues(rule.matchMode, rule.match.stage ?? [], singleton(candidate.stage)) &&
|
|
9
|
+
matchesRequiredValues(rule.matchMode, rule.match.outcome ?? [], [candidate.outcome]));
|
|
10
|
+
}
|
|
11
|
+
function singleton(value) {
|
|
12
|
+
return value === undefined ? [] : [value];
|
|
13
|
+
}
|
|
14
|
+
export const defaultReplyPublication = {
|
|
15
|
+
rules: [],
|
|
16
|
+
default: ReplyTarget.Primary,
|
|
17
|
+
};
|
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { MatchMode } from '../../../kernel/index.js';
|
|
3
|
+
import { ReplyOutcomeConfig, ReplyTarget, } from '../../contracts/reply-routing.js';
|
|
3
4
|
import { isGitHubWakeMarker } from './vocabulary.js';
|
|
5
|
+
const replyTargetSchema = z.enum(Object.values(ReplyTarget));
|
|
6
|
+
const replyOutcomeSchema = z
|
|
7
|
+
.enum(Object.values(ReplyOutcomeConfig))
|
|
8
|
+
.transform((value) => replyOutcomeMap[value]);
|
|
9
|
+
const replyOutcomeMap = {
|
|
10
|
+
[ReplyOutcomeConfig.Done]: 'DONE',
|
|
11
|
+
[ReplyOutcomeConfig.Rejected]: 'REJECTED',
|
|
12
|
+
[ReplyOutcomeConfig.Blocked]: 'BLOCKED',
|
|
13
|
+
[ReplyOutcomeConfig.Failed]: 'FAILED',
|
|
14
|
+
[ReplyOutcomeConfig.NeedsClarification]: 'NEEDS_CLARIFICATION',
|
|
15
|
+
};
|
|
16
|
+
const replySelectorValues = (value) => z
|
|
17
|
+
.union([value, z.array(value).min(1)])
|
|
18
|
+
.transform((values) => (Array.isArray(values) ? values : [values]));
|
|
19
|
+
const replyRuleSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
match: z
|
|
22
|
+
.object({
|
|
23
|
+
stage: replySelectorValues(z.string().trim().min(1)).optional(),
|
|
24
|
+
outcome: replySelectorValues(replyOutcomeSchema).optional(),
|
|
25
|
+
})
|
|
26
|
+
.strict()
|
|
27
|
+
.refine((value) => Object.values(value).some((facet) => facet !== undefined), {
|
|
28
|
+
message: 'Reply routing match requires at least one facet',
|
|
29
|
+
}),
|
|
30
|
+
matchMode: z.enum([MatchMode.Any, MatchMode.All]).default(MatchMode.Any),
|
|
31
|
+
target: replyTargetSchema,
|
|
32
|
+
})
|
|
33
|
+
.strict();
|
|
34
|
+
const replyPublicationSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
rules: z.array(replyRuleSchema).default([]),
|
|
37
|
+
default: replyTargetSchema.default(ReplyTarget.Primary),
|
|
38
|
+
})
|
|
39
|
+
.strict()
|
|
40
|
+
.default({ rules: [], default: ReplyTarget.Primary });
|
|
4
41
|
const repositorySchema = z
|
|
5
42
|
.object({ owner: z.string().trim().min(1), repo: z.string().trim().min(1) })
|
|
6
43
|
.strict();
|
|
@@ -49,9 +86,12 @@ export const gitHubConfigSchema = z
|
|
|
49
86
|
}),
|
|
50
87
|
intake: z.array(intakeRuleSchema).default([]),
|
|
51
88
|
publication: z
|
|
52
|
-
.object({
|
|
89
|
+
.object({
|
|
90
|
+
postStatusComments: z.boolean().default(true),
|
|
91
|
+
replies: replyPublicationSchema,
|
|
92
|
+
})
|
|
53
93
|
.strict()
|
|
54
|
-
.default({ postStatusComments: true }),
|
|
94
|
+
.default({ postStatusComments: true, replies: { rules: [], default: ReplyTarget.Primary } }),
|
|
55
95
|
// Additional command syntax to advertise on the commands/instructions
|
|
56
96
|
// surface alongside the adapter's built-in commands. Purely descriptive:
|
|
57
97
|
// Wake does not recognize these itself, so any behavior they imply must
|
|
@@ -14,6 +14,7 @@ export * from '../delivery/contracts/vocabulary.js';
|
|
|
14
14
|
export * from './application/inbound-translator.js';
|
|
15
15
|
export * from './application/agent-context-reader.js';
|
|
16
16
|
export * from './application/poll-service.js';
|
|
17
|
+
export * from './application/reply-target-selector.js';
|
|
17
18
|
export * from './application/resource-links.js';
|
|
18
19
|
export * from './application/review-command-translator.js';
|
|
19
20
|
export * from './application/wake-labels.js';
|
|
@@ -48,6 +48,7 @@ export const gitHubProviderDefinition = {
|
|
|
48
48
|
...Object.values(GitHubBuiltInCommand).map((syntax) => ({ syntax })),
|
|
49
49
|
...config.commands.map((syntax) => ({ syntax })),
|
|
50
50
|
],
|
|
51
|
+
replyPublication: config.publication.replies,
|
|
51
52
|
delivery: createGitHubDelivery(async (intent, idempotencyKey) => {
|
|
52
53
|
const resource = await services.resources.get(resourceId(intent.resourceId));
|
|
53
54
|
if (resource === null)
|
|
@@ -13,6 +13,7 @@ export * from './contracts/identifiers.js';
|
|
|
13
13
|
export * from './contracts/intake-rules.js';
|
|
14
14
|
export * from './contracts/intake.js';
|
|
15
15
|
export * from './contracts/provider.js';
|
|
16
|
+
export * from './contracts/reply-routing.js';
|
|
16
17
|
export * from './contracts/streams.js';
|
|
17
18
|
export * from './delivery/application/delivery-outcome-reactor.js';
|
|
18
19
|
export * from './delivery/application/delivery-projector.js';
|