Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/configuration/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseTriggerDocument } from "../triggers/configuration/index.js";
import { dump } from "js-yaml";
import { dump, load } from "js-yaml";
import { z } from "zod";
import {
compiledConfigurationHash,
Expand Down Expand Up @@ -318,6 +318,9 @@ export function parseProjectConfiguration(
if (adapter.success) {
if (revision.rawYaml === null)
throw new Error("Trigger revision is missing its authored document");
// Preserved legacy workflows share the adapter but retain their original run policy.
const legacy = z.object({ legacy_multistep: z.object({}) }).safeParse(load(revision.rawYaml));
if (legacy.success) return toProjectConfiguration(configuration);
const policy = parseTriggerDocument(revision.rawYaml).run.continuation;
return toProjectConfiguration({
...configuration,
Expand Down
70 changes: 70 additions & 0 deletions src/provider-applications/internal/runtime-owner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,78 @@ import type {
SlackProviderApplicationConfiguration,
} from "../index.js";
import { DynamicProviderRuntime } from "./runtime-owner.js";
import { OutputExecutorRegistry, replyOutputTool } from "../../execution-capabilities/outputs.js";
import { createGitHubReplyExecutor, githubReplyAvailable } from "../../triggers/github/reply.js";

describe("dynamic provider runtime", () => {
it("exposes and delivers GitHub replies through the hosted provider registration", async () => {
const comments: unknown[] = [];
const runtime = new DynamicProviderRuntime({
database: createMemoryDatabase(),
auth: testAuth(),
applicationBaseUrl: "https://hub.test",
registrationFactory: () => ({
...connectionRegistration("github", "A1"),
outputs: [
{
type: "github.reply",
tool: replyOutputTool,
available: githubReplyAvailable,
execute: createGitHubReplyExecutor({
client: {
createIssueComment: async (comment) => {
comments.push(comment);
},
},
}),
},
],
}),
});
const registry = new OutputExecutorRegistry();
for (const registration of runtime.registrations()) {
for (const output of registration.outputs) registry.register(output);
}
const candidate = await runtime.prepare(
"github",
providerConfiguration("github", "A1"),
"https://hub.test",
providerIdentity("github", "A1"),
1,
);
await candidate.start();
candidate.publish();
const outputContext = {
provider: "github",
target: { installationId: 42, repository: "acme/repo" },
event: { github: { item: { number: 7 } } },
};
const grants = [{ type: "github.reply", required: false }];
assert.equal(registry.materialize(grants, outputContext).length, 1);
assert.equal(
registry.materialize(grants, {
...outputContext,
event: { github: { item: null } },
}).length,
0,
);
await registry.execute({
agentExecutionId: "execution-1",
toolType: "github.reply",
args: { content: "remembered" },
outputContext,
});
assert.deepEqual(comments, [
{
installationId: 42,
owner: "acme",
repo: "repo",
issueNumber: 7,
body: "remembered",
},
]);
});

it.each([
"github.issues",
"github.issue_comment",
Expand Down
44 changes: 23 additions & 21 deletions src/provider-applications/internal/runtime-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AuthServer } from "../../auth/server.js";
import { createHash } from "node:crypto";
import type { GitHubConfigurationProvider } from "../../configuration/github-sync.js";
import type { Database } from "../../db/types.js";
import { outputContextProvider, replyOutputTool } from "../../execution-capabilities/outputs.js";
import { replyOutputTool } from "../../execution-capabilities/outputs.js";
import { logger } from "../../logger.js";
import { reportFailure } from "../../failures/index.js";
import { createDiscordRegistration } from "../../providers/discord/index.js";
Expand Down Expand Up @@ -399,26 +399,28 @@ export class DynamicProviderRuntime implements ProviderRuntimeOwner {
},
],
sources: [source],
outputs:
provider === "github"
? []
: [
{
type: `${provider}.reply`,
tool: replyOutputTool,
available: outputContextProvider(provider),
execute: (input) => {
const active = slot.active;
const output = active?.registration.outputs.find(
(candidate) => candidate.type === `${provider}.reply`,
);
if (active === undefined || output === undefined) {
throw unavailable(`${provider}_output_unavailable`);
}
return this.withLease(active, () => output.execute(input));
},
},
],
outputs: [
{
type: `${provider}.reply`,
tool: replyOutputTool,
available: (context) => {
const output = slot.active?.registration.outputs.find(
(candidate) => candidate.type === `${provider}.reply`,
);
return output !== undefined && (output.available?.(context) ?? true);
},
execute: (input) => {
const active = slot.active;
const output = active?.registration.outputs.find(
(candidate) => candidate.type === `${provider}.reply`,
);
if (active === undefined || output === undefined) {
throw unavailable(`${provider}_output_unavailable`);
}
return this.withLease(active, () => output.execute(input));
},
},
],
requests:
provider === "discord"
? []
Expand Down
8 changes: 8 additions & 0 deletions src/triggers/configuration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,12 @@ it("applies the continuation default when reading old trigger revisions without
assert.equal(stored.triggers[0]?.steps[0]?.continuation, undefined);
const legacy = parseProjectConfiguration({ ...revision, sourceEvidence: { kind: "manual" } });
assert.equal(legacy.triggers[0]?.steps[0]?.continuation, undefined);
const migratedLegacy = parseProjectConfiguration({
...revision,
rawYaml: JSON.stringify({
name: "preserved-workflow",
legacy_multistep: { trigger: stored.triggers[0], environments: stored.environments },
}),
});
assert.deepEqual(migratedLegacy, legacy);
});
Loading