alchemy 0.1.8 → 0.1.9
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/lib/$.d.ts +7 -0
- package/lib/$.d.ts.map +1 -0
- package/lib/$.js +31 -0
- package/lib/$.js.map +1 -0
- package/lib/agent/ai.d.ts +40 -0
- package/lib/agent/ai.d.ts.map +1 -0
- package/lib/agent/ai.js +132 -0
- package/lib/agent/ai.js.map +1 -0
- package/lib/agent/anthropic.d.ts +9 -0
- package/lib/agent/anthropic.d.ts.map +1 -0
- package/lib/agent/anthropic.js +25 -0
- package/lib/agent/anthropic.js.map +1 -0
- package/lib/agent/dependencies.d.ts +4 -0
- package/lib/agent/dependencies.d.ts.map +1 -0
- package/lib/agent/dependencies.js +48 -0
- package/lib/agent/dependencies.js.map +1 -0
- package/lib/agent/file-context.d.ts +13 -0
- package/lib/agent/file-context.d.ts.map +1 -0
- package/lib/agent/file-context.js +6 -0
- package/lib/agent/file-context.js.map +1 -0
- package/lib/agent/index.d.ts +10 -0
- package/lib/agent/index.d.ts.map +1 -0
- package/lib/agent/index.js +10 -0
- package/lib/agent/index.js.map +1 -0
- package/lib/agent/model.d.ts +8 -0
- package/lib/agent/model.d.ts.map +1 -0
- package/lib/agent/model.js +29 -0
- package/lib/agent/model.js.map +1 -0
- package/lib/agent/module.d.ts +81 -0
- package/lib/agent/module.d.ts.map +1 -0
- package/lib/agent/module.js +309 -0
- package/lib/agent/module.js.map +1 -0
- package/lib/agent/openai.d.ts +6 -0
- package/lib/agent/openai.d.ts.map +1 -0
- package/lib/agent/openai.js +41 -0
- package/lib/agent/openai.js.map +1 -0
- package/lib/agent/program.d.ts +12 -0
- package/lib/agent/program.d.ts.map +1 -0
- package/lib/agent/program.js +21 -0
- package/lib/agent/program.js.map +1 -0
- package/lib/agent/prompts.d.ts +4 -0
- package/lib/agent/prompts.d.ts.map +1 -0
- package/lib/agent/prompts.js +11 -0
- package/lib/agent/prompts.js.map +1 -0
- package/lib/agent/scrape.d.ts +71 -0
- package/lib/agent/scrape.d.ts.map +1 -0
- package/lib/agent/scrape.js +45 -0
- package/lib/agent/scrape.js.map +1 -0
- package/lib/alchemize.d.ts +43 -0
- package/lib/alchemize.d.ts.map +1 -0
- package/lib/alchemize.js +105 -0
- package/lib/alchemize.js.map +1 -0
- package/lib/apply.d.ts +23 -0
- package/lib/apply.d.ts.map +1 -0
- package/lib/apply.js +84 -0
- package/lib/apply.js.map +1 -0
- package/lib/aws/auto/docs.d.ts +11 -0
- package/lib/aws/auto/docs.d.ts.map +1 -0
- package/lib/aws/auto/docs.js +56 -0
- package/lib/aws/auto/docs.js.map +1 -0
- package/lib/aws/auto/index.d.ts +5 -0
- package/lib/aws/auto/index.d.ts.map +1 -0
- package/lib/aws/auto/index.js +5 -0
- package/lib/aws/auto/index.js.map +1 -0
- package/lib/aws/auto/resource.d.ts +24 -0
- package/lib/aws/auto/resource.d.ts.map +1 -0
- package/lib/aws/auto/resource.js +194 -0
- package/lib/aws/auto/resource.js.map +1 -0
- package/lib/aws/auto/service.d.ts +10 -0
- package/lib/aws/auto/service.d.ts.map +1 -0
- package/lib/aws/auto/service.js +34 -0
- package/lib/aws/auto/service.js.map +1 -0
- package/lib/aws/auto/spec.d.ts +83 -0
- package/lib/aws/auto/spec.d.ts.map +1 -0
- package/lib/aws/auto/spec.js +58 -0
- package/lib/aws/auto/spec.js.map +1 -0
- package/lib/aws/bucket.d.ts +21 -0
- package/lib/aws/bucket.d.ts.map +1 -0
- package/lib/aws/bucket.js +114 -0
- package/lib/aws/bucket.js.map +1 -0
- package/lib/aws/function.d.ts +53 -0
- package/lib/aws/function.d.ts.map +1 -0
- package/lib/aws/function.js +195 -0
- package/lib/aws/function.js.map +1 -0
- package/lib/aws/index.d.ts +7 -0
- package/lib/aws/index.d.ts.map +1 -0
- package/lib/aws/index.js +7 -0
- package/lib/aws/index.js.map +1 -0
- package/lib/aws/policy.d.ts +46 -0
- package/lib/aws/policy.d.ts.map +1 -0
- package/lib/aws/policy.js +139 -0
- package/lib/aws/policy.js.map +1 -0
- package/lib/aws/queue.d.ts +38 -0
- package/lib/aws/queue.d.ts.map +1 -0
- package/lib/aws/queue.js +162 -0
- package/lib/aws/queue.js.map +1 -0
- package/lib/aws/role.d.ts +27 -0
- package/lib/aws/role.d.ts.map +1 -0
- package/lib/aws/role.js +149 -0
- package/lib/aws/role.js.map +1 -0
- package/lib/aws/table.d.ts +26 -0
- package/lib/aws/table.d.ts.map +1 -0
- package/lib/aws/table.js +120 -0
- package/lib/aws/table.js.map +1 -0
- package/lib/destroy.d.ts +19 -0
- package/lib/destroy.d.ts.map +1 -0
- package/lib/destroy.js +47 -0
- package/lib/destroy.js.map +1 -0
- package/lib/error.d.ts +2 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +13 -0
- package/lib/error.js.map +1 -0
- package/lib/esbuild.d.ts +70 -0
- package/lib/esbuild.d.ts.map +1 -0
- package/lib/esbuild.js +58 -0
- package/lib/esbuild.js.map +1 -0
- package/lib/fs.d.ts +12 -0
- package/lib/fs.d.ts.map +1 -0
- package/lib/fs.js +41 -0
- package/lib/fs.js.map +1 -0
- package/lib/global.d.ts +18 -0
- package/lib/global.d.ts.map +1 -0
- package/lib/global.js +42 -0
- package/lib/global.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/input.d.ts +6 -0
- package/lib/input.d.ts.map +1 -0
- package/lib/input.js +2 -0
- package/lib/input.js.map +1 -0
- package/lib/main.d.ts +3 -0
- package/lib/main.d.ts.map +1 -0
- package/lib/main.js +32 -0
- package/lib/main.js.map +1 -0
- package/lib/markdown/design.d.ts +17 -0
- package/lib/markdown/design.d.ts.map +1 -0
- package/lib/markdown/design.js +92 -0
- package/lib/markdown/design.js.map +1 -0
- package/lib/markdown/extract.d.ts +7 -0
- package/lib/markdown/extract.d.ts.map +1 -0
- package/lib/markdown/extract.js +10 -0
- package/lib/markdown/extract.js.map +1 -0
- package/lib/markdown/index.d.ts +4 -0
- package/lib/markdown/index.d.ts.map +1 -0
- package/lib/markdown/index.js +4 -0
- package/lib/markdown/index.js.map +1 -0
- package/lib/markdown/requirements.d.ts +79 -0
- package/lib/markdown/requirements.d.ts.map +1 -0
- package/lib/markdown/requirements.js +105 -0
- package/lib/markdown/requirements.js.map +1 -0
- package/lib/output.d.ts +19 -0
- package/lib/output.d.ts.map +1 -0
- package/lib/output.js +16 -0
- package/lib/output.js.map +1 -0
- package/lib/resource.d.ts +66 -0
- package/lib/resource.d.ts.map +1 -0
- package/lib/resource.js +242 -0
- package/lib/resource.js.map +1 -0
- package/lib/scope.d.ts +15 -0
- package/lib/scope.d.ts.map +1 -0
- package/lib/scope.js +38 -0
- package/lib/scope.js.map +1 -0
- package/lib/slug.d.ts +2 -0
- package/lib/slug.d.ts.map +1 -0
- package/lib/slug.js +4 -0
- package/lib/slug.js.map +1 -0
- package/lib/state.d.ts +40 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +73 -0
- package/lib/state.js.map +1 -0
- package/lib/stripe/index.d.ts +4 -0
- package/lib/stripe/index.d.ts.map +1 -0
- package/lib/stripe/index.js +4 -0
- package/lib/stripe/index.js.map +1 -0
- package/lib/stripe/price.d.ts +109 -0
- package/lib/stripe/price.d.ts.map +1 -0
- package/lib/stripe/price.js +112 -0
- package/lib/stripe/price.js.map +1 -0
- package/lib/stripe/product.d.ts +86 -0
- package/lib/stripe/product.d.ts.map +1 -0
- package/lib/stripe/product.js +90 -0
- package/lib/stripe/product.js.map +1 -0
- package/lib/stripe/webhook.d.ts +73 -0
- package/lib/stripe/webhook.d.ts.map +1 -0
- package/lib/stripe/webhook.js +94 -0
- package/lib/stripe/webhook.js.map +1 -0
- package/lib/typescript/check-omission.d.ts +2 -0
- package/lib/typescript/check-omission.d.ts.map +1 -0
- package/lib/typescript/check-omission.js +43 -0
- package/lib/typescript/check-omission.js.map +1 -0
- package/lib/typescript/debug-type-errors.d.ts +3 -0
- package/lib/typescript/debug-type-errors.d.ts.map +1 -0
- package/lib/typescript/debug-type-errors.js +35 -0
- package/lib/typescript/debug-type-errors.js.map +1 -0
- package/lib/typescript/extract.d.ts +7 -0
- package/lib/typescript/extract.d.ts.map +1 -0
- package/lib/typescript/extract.js +10 -0
- package/lib/typescript/extract.js.map +1 -0
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/index.js +7 -0
- package/lib/typescript/index.js.map +1 -0
- package/lib/typescript/install-dependencies.d.ts +29 -0
- package/lib/typescript/install-dependencies.d.ts.map +1 -0
- package/lib/typescript/install-dependencies.js +52 -0
- package/lib/typescript/install-dependencies.js.map +1 -0
- package/lib/typescript/package.d.ts +157 -0
- package/lib/typescript/package.d.ts.map +1 -0
- package/lib/typescript/package.js +115 -0
- package/lib/typescript/package.js.map +1 -0
- package/lib/typescript/repair-omissions.d.ts +3 -0
- package/lib/typescript/repair-omissions.d.ts.map +1 -0
- package/lib/typescript/repair-omissions.js +23 -0
- package/lib/typescript/repair-omissions.js.map +1 -0
- package/lib/typescript/repair.d.ts +3 -0
- package/lib/typescript/repair.d.ts.map +1 -0
- package/lib/typescript/repair.js +34 -0
- package/lib/typescript/repair.js.map +1 -0
- package/lib/typescript/tsconfig.d.ts +469 -0
- package/lib/typescript/tsconfig.d.ts.map +1 -0
- package/lib/typescript/tsconfig.js +143 -0
- package/lib/typescript/tsconfig.js.map +1 -0
- package/lib/typescript/typescript.d.ts +107 -0
- package/lib/typescript/typescript.d.ts.map +1 -0
- package/lib/typescript/typescript.js +180 -0
- package/lib/typescript/typescript.js.map +1 -0
- package/lib/typescript/validate.d.ts +10 -0
- package/lib/typescript/validate.d.ts.map +1 -0
- package/lib/typescript/validate.js +49 -0
- package/lib/typescript/validate.js.map +1 -0
- package/package.json +2 -1
- package/test/aws/function.test.ts +0 -144
- package/test/aws/queue.test.ts +0 -85
- package/test/aws/role.test.ts +0 -153
- package/test/aws/table.test.ts +0 -73
- package/test/esbuild.test.ts +0 -41
- package/test/handler.ts +0 -9
- package/test/scope.test.ts +0 -67
- package/test/stripe/stripe.test.ts +0 -136
- package/tsconfig.json +0 -33
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { dependenciesAsMessages, generateText, resolveModel, } from "../agent";
|
|
6
|
+
import { Prompts } from "../agent/prompts";
|
|
7
|
+
import { rm } from "../fs";
|
|
8
|
+
import { extractMarkdown } from "../markdown/extract";
|
|
9
|
+
import { Resource } from "../resource";
|
|
10
|
+
export class Design extends Resource("design", async (ctx, props) => {
|
|
11
|
+
if (ctx.event === "delete") {
|
|
12
|
+
await rm(props.path);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const model = await resolveModel(props.model ?? "gpt-4o");
|
|
16
|
+
const loadFile = tool({
|
|
17
|
+
description: "Load a relevant file into context",
|
|
18
|
+
parameters: z.object({
|
|
19
|
+
file: z.string(),
|
|
20
|
+
}),
|
|
21
|
+
execute: async ({ file }) => fs.readFile(file, "utf-8"),
|
|
22
|
+
});
|
|
23
|
+
let existingContent = undefined;
|
|
24
|
+
if (ctx.event === "update") {
|
|
25
|
+
if (props.path) {
|
|
26
|
+
try {
|
|
27
|
+
existingContent = await fs.readFile(props.path, "utf-8");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// File doesn't exist yet, continue with empty content
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
existingContent = ctx.output.content;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
console.log(ctx.event === "create" ? "Designing" : "Revising design", ":", props.path);
|
|
38
|
+
const result = await generateText({
|
|
39
|
+
model,
|
|
40
|
+
// tools: {
|
|
41
|
+
// import: importFile,
|
|
42
|
+
// },
|
|
43
|
+
providerOptions: props.model === "o3-mini"
|
|
44
|
+
? {
|
|
45
|
+
openai: {
|
|
46
|
+
reasoningEffort: "high",
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
messages: [
|
|
51
|
+
{
|
|
52
|
+
role: "system",
|
|
53
|
+
content: Prompts.program,
|
|
54
|
+
},
|
|
55
|
+
...dependenciesAsMessages(props.dependencies),
|
|
56
|
+
...(existingContent
|
|
57
|
+
? [
|
|
58
|
+
{
|
|
59
|
+
role: "user",
|
|
60
|
+
content: `Here is the prior version of ${props.path}:\n${existingContent}`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
role: "assistant",
|
|
64
|
+
content: "Thanks, I'll make sure to consider this when producing the next revision.",
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
68
|
+
{
|
|
69
|
+
role: "user",
|
|
70
|
+
content: props.prompt,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
role: "user",
|
|
74
|
+
content: [
|
|
75
|
+
`Make sure to list each of the files that need to be implemented and`,
|
|
76
|
+
"and to follow best practices in term of separation of concerns.",
|
|
77
|
+
"Ideally, each component has its own dedicated file.",
|
|
78
|
+
"Each file should be referenced using markdown links, e.g. [file.ts](./file.ts).",
|
|
79
|
+
].join(" "),
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
const content = extractMarkdown(result.text);
|
|
84
|
+
await fs.mkdir(path.dirname(props.path), { recursive: true });
|
|
85
|
+
await fs.writeFile(props.path, content);
|
|
86
|
+
return {
|
|
87
|
+
path: props.path,
|
|
88
|
+
content,
|
|
89
|
+
};
|
|
90
|
+
}) {
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=design.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design.js","sourceRoot":"","sources":["../../src/markdown/design.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,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H,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE9D,MAAM,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO;KACR,CAAC;AACJ,CAAC,CACF;CAAG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts markdown content from a code block or returns the full content
|
|
3
|
+
* @param text Response text that may contain markdown code blocks
|
|
4
|
+
* @returns The markdown content from code block if found, otherwise returns the full text
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractMarkdown(text: string): string;
|
|
7
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/markdown/extract.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGpD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts markdown content from a code block or returns the full content
|
|
3
|
+
* @param text Response text that may contain markdown code blocks
|
|
4
|
+
* @returns The markdown content from code block if found, otherwise returns the full text
|
|
5
|
+
*/
|
|
6
|
+
export function extractMarkdown(text) {
|
|
7
|
+
const matches = text.match(/```md\n([\s\S]*?)```/);
|
|
8
|
+
return matches?.[1]?.trim() ?? text.trim();
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/markdown/extract.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACnD,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ReasoningEffort: z.ZodEnum<["low", "medium", "high"]>;
|
|
3
|
+
export declare const RequirementsInput: z.ZodObject<{
|
|
4
|
+
/**
|
|
5
|
+
* The ID of the model to use for generating requirements documentation
|
|
6
|
+
* @default "gpt-4o"
|
|
7
|
+
*/
|
|
8
|
+
modelId: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["o3-mini", "o1", "o1-2024-12-17", "o1-mini", "o1-mini-2024-09-12", "o1-preview", "o1-preview-2024-09-12", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-2024-11-20", "gpt-4o-audio-preview", "gpt-4o-audio-preview-2024-10-01", "gpt-4o-audio-preview-2024-12-17", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview", "gpt-4-0125-preview", "gpt-4-1106-preview", "gpt-4", "gpt-4-0613", "gpt-3.5-turbo-0125", "gpt-3.5-turbo", "gpt-3.5-turbo-1106"]>, z.ZodEnum<["claude-3-5-sonnet-latest", "claude-3-5-sonnet-20241022", "claude-3-5-sonnet-20240620", "claude-3-5-haiku-latest", "claude-3-5-haiku-20241022", "claude-3-opus", "claude-3-opus-20240229", "claude-3-sonnet", "claude-3-sonnet-20240229", "claude-3-haiku", "claude-3-haiku-20240307"]>]>>;
|
|
9
|
+
/**
|
|
10
|
+
* The effort to put into reasoning about the requirements
|
|
11
|
+
*/
|
|
12
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
|
|
13
|
+
/**
|
|
14
|
+
* List of requirements to document and analyze
|
|
15
|
+
*/
|
|
16
|
+
requirements: z.ZodArray<z.ZodString, "many">;
|
|
17
|
+
/**
|
|
18
|
+
* List of dependencies for the requirements document
|
|
19
|
+
*/
|
|
20
|
+
dependencies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
21
|
+
path: z.ZodString;
|
|
22
|
+
content: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
path: string;
|
|
25
|
+
content?: string | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
path: string;
|
|
28
|
+
content?: string | undefined;
|
|
29
|
+
}>, "many">>;
|
|
30
|
+
/**
|
|
31
|
+
* Temperature setting for model generation (higher = more creative, lower = more focused)
|
|
32
|
+
* @default 0.7
|
|
33
|
+
*/
|
|
34
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
/**
|
|
36
|
+
* File path where the requirements document should be written
|
|
37
|
+
*/
|
|
38
|
+
file: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
requirements: string[];
|
|
41
|
+
temperature?: number | undefined;
|
|
42
|
+
file?: string | undefined;
|
|
43
|
+
reasoningEffort?: "high" | "low" | "medium" | undefined;
|
|
44
|
+
modelId?: "o3-mini" | "o1" | "o1-2024-12-17" | "o1-mini" | "o1-mini-2024-09-12" | "o1-preview" | "o1-preview-2024-09-12" | "gpt-4o" | "gpt-4o-2024-05-13" | "gpt-4o-2024-08-06" | "gpt-4o-2024-11-20" | "gpt-4o-audio-preview" | "gpt-4o-audio-preview-2024-10-01" | "gpt-4o-audio-preview-2024-12-17" | "gpt-4o-mini" | "gpt-4o-mini-2024-07-18" | "gpt-4-turbo" | "gpt-4-turbo-2024-04-09" | "gpt-4-turbo-preview" | "gpt-4-0125-preview" | "gpt-4-1106-preview" | "gpt-4" | "gpt-4-0613" | "gpt-3.5-turbo-0125" | "gpt-3.5-turbo" | "gpt-3.5-turbo-1106" | "claude-3-5-sonnet-latest" | "claude-3-5-sonnet-20241022" | "claude-3-5-sonnet-20240620" | "claude-3-5-haiku-latest" | "claude-3-5-haiku-20241022" | "claude-3-opus" | "claude-3-opus-20240229" | "claude-3-sonnet" | "claude-3-sonnet-20240229" | "claude-3-haiku" | "claude-3-haiku-20240307" | undefined;
|
|
45
|
+
dependencies?: {
|
|
46
|
+
path: string;
|
|
47
|
+
content?: string | undefined;
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
requirements: string[];
|
|
51
|
+
temperature?: number | undefined;
|
|
52
|
+
file?: string | undefined;
|
|
53
|
+
reasoningEffort?: "high" | "low" | "medium" | undefined;
|
|
54
|
+
modelId?: "o3-mini" | "o1" | "o1-2024-12-17" | "o1-mini" | "o1-mini-2024-09-12" | "o1-preview" | "o1-preview-2024-09-12" | "gpt-4o" | "gpt-4o-2024-05-13" | "gpt-4o-2024-08-06" | "gpt-4o-2024-11-20" | "gpt-4o-audio-preview" | "gpt-4o-audio-preview-2024-10-01" | "gpt-4o-audio-preview-2024-12-17" | "gpt-4o-mini" | "gpt-4o-mini-2024-07-18" | "gpt-4-turbo" | "gpt-4-turbo-2024-04-09" | "gpt-4-turbo-preview" | "gpt-4-0125-preview" | "gpt-4-1106-preview" | "gpt-4" | "gpt-4-0613" | "gpt-3.5-turbo-0125" | "gpt-3.5-turbo" | "gpt-3.5-turbo-1106" | "claude-3-5-sonnet-latest" | "claude-3-5-sonnet-20241022" | "claude-3-5-sonnet-20240620" | "claude-3-5-haiku-latest" | "claude-3-5-haiku-20241022" | "claude-3-opus" | "claude-3-opus-20240229" | "claude-3-sonnet" | "claude-3-sonnet-20240229" | "claude-3-haiku" | "claude-3-haiku-20240307" | undefined;
|
|
55
|
+
dependencies?: {
|
|
56
|
+
path: string;
|
|
57
|
+
content?: string | undefined;
|
|
58
|
+
}[] | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
export declare const RequirementsOutput: z.ZodObject<{
|
|
61
|
+
/**
|
|
62
|
+
* Generated markdown document containing organized and analyzed requirements
|
|
63
|
+
*/
|
|
64
|
+
content: z.ZodString;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
content: string;
|
|
67
|
+
}, {
|
|
68
|
+
content: string;
|
|
69
|
+
}>;
|
|
70
|
+
export interface RequirementsInput extends z.infer<typeof RequirementsInput> {
|
|
71
|
+
}
|
|
72
|
+
export type RequirementsOutput = z.infer<typeof RequirementsOutput>;
|
|
73
|
+
declare const Requirements_base: import("../resource").Provider<"code::Requirements", [props: RequirementsInput], {
|
|
74
|
+
content: string;
|
|
75
|
+
}>;
|
|
76
|
+
export declare class Requirements extends Requirements_base {
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=requirements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirements.d.ts","sourceRoot":"","sources":["../../src/markdown/requirements.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,eAAO,MAAM,eAAe,sCAAoC,CAAC;AAEjE,eAAO,MAAM,iBAAiB;IAC5B;;;OAGG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;;;;;;;;;IAGH;;;OAGG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;EAEH,CAAC;AAEH,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;;;;;;EAEH,CAAC;AAEH,MAAM,WAAW,iBAAkB,SAAQ,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC;CAAG;AAC/E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;;;;AAEpE,qBAAa,YAAa,SAAQ,iBA2EjC;CAAG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { FileContext, ModelId, dependenciesAsMessages, generateText, resolveModel, } from "../agent";
|
|
5
|
+
import { rm } from "../fs";
|
|
6
|
+
import { Resource } from "../resource";
|
|
7
|
+
export const ReasoningEffort = z.enum(["low", "medium", "high"]);
|
|
8
|
+
export const RequirementsInput = z.object({
|
|
9
|
+
/**
|
|
10
|
+
* The ID of the model to use for generating requirements documentation
|
|
11
|
+
* @default "gpt-4o"
|
|
12
|
+
*/
|
|
13
|
+
modelId: ModelId.optional(),
|
|
14
|
+
/**
|
|
15
|
+
* The effort to put into reasoning about the requirements
|
|
16
|
+
*/
|
|
17
|
+
reasoningEffort: ReasoningEffort.optional(),
|
|
18
|
+
/**
|
|
19
|
+
* List of requirements to document and analyze
|
|
20
|
+
*/
|
|
21
|
+
requirements: z.array(z.string()),
|
|
22
|
+
/**
|
|
23
|
+
* List of dependencies for the requirements document
|
|
24
|
+
*/
|
|
25
|
+
dependencies: z.array(FileContext).optional(),
|
|
26
|
+
/**
|
|
27
|
+
* Temperature setting for model generation (higher = more creative, lower = more focused)
|
|
28
|
+
* @default 0.7
|
|
29
|
+
*/
|
|
30
|
+
temperature: z.number().optional(),
|
|
31
|
+
/**
|
|
32
|
+
* File path where the requirements document should be written
|
|
33
|
+
*/
|
|
34
|
+
file: z.string().optional(),
|
|
35
|
+
});
|
|
36
|
+
export const RequirementsOutput = z.object({
|
|
37
|
+
/**
|
|
38
|
+
* Generated markdown document containing organized and analyzed requirements
|
|
39
|
+
*/
|
|
40
|
+
content: z.string(),
|
|
41
|
+
});
|
|
42
|
+
export class Requirements extends Resource("code::Requirements", async (ctx, props) => {
|
|
43
|
+
if (ctx.event === "delete") {
|
|
44
|
+
if (props.file) {
|
|
45
|
+
await rm(props.file);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (props.file) {
|
|
50
|
+
console.log(ctx.event === "create" ? "Designing" : "Revising", "requirements", props.file);
|
|
51
|
+
}
|
|
52
|
+
// Get the appropriate model based on the ID
|
|
53
|
+
const model = await resolveModel(props.modelId ?? "gpt-4o");
|
|
54
|
+
// Generate the requirements document
|
|
55
|
+
const { text } = await generateText({
|
|
56
|
+
model,
|
|
57
|
+
temperature: props.temperature ?? 0.7,
|
|
58
|
+
maxSteps: 3, // Allow multiple steps for potential tool usage
|
|
59
|
+
providerOptions: props.reasoningEffort
|
|
60
|
+
? {
|
|
61
|
+
openai: {
|
|
62
|
+
reasoningEffort: props.reasoningEffort,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
tools: {
|
|
67
|
+
// scrapeWebPage,
|
|
68
|
+
},
|
|
69
|
+
messages: [
|
|
70
|
+
{
|
|
71
|
+
role: "system",
|
|
72
|
+
content: "You are a helpful assistant that creates markdown documents from requirements. You can use the scrapeWebPage tool to get additional requirements from relevant URLs if needed.",
|
|
73
|
+
},
|
|
74
|
+
...dependenciesAsMessages(props.dependencies ?? []),
|
|
75
|
+
{
|
|
76
|
+
role: "user",
|
|
77
|
+
content: `Please analyze the following system requirements and create a comprehensive, unambiguous markdown document that covers all aspects:
|
|
78
|
+
|
|
79
|
+
Requirements:
|
|
80
|
+
${props.requirements.map((req) => `- ${req}`).join("\n")}
|
|
81
|
+
|
|
82
|
+
Guidelines:
|
|
83
|
+
1. Make explicit decisions for any ambiguous requirements - do not leave open questions
|
|
84
|
+
2. Document the reasoning behind key decisions
|
|
85
|
+
3. Be specific about technical choices and implementation details
|
|
86
|
+
4. Avoid phrases like "could be", "might need", or "possibly requires" - be definitive
|
|
87
|
+
5. Organize requirements into logical sections with clear dependencies and relationships
|
|
88
|
+
|
|
89
|
+
Format the output in markdown with appropriate headers, lists, and sections, starting with the title as an H1 header.
|
|
90
|
+
Include technical considerations and implementation details, ensuring every requirement has a clear, actionable specification.`,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
if (props.file) {
|
|
95
|
+
// Ensure the directory exists
|
|
96
|
+
await mkdir(dirname(props.file), { recursive: true });
|
|
97
|
+
// Write the requirements to the file
|
|
98
|
+
await writeFile(props.file, text);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
content: text,
|
|
102
|
+
};
|
|
103
|
+
}) {
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=requirements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirements.js","sourceRoot":"","sources":["../../src/markdown/requirements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,OAAO,EACP,sBAAsB,EACtB,YAAY,EACZ,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAgB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,iBAAiB,GA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MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,YAAY,CAAC;QAClC,KAAK;QACL,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,GAAG;QACrC,QAAQ,EAAE,CAAC,EAAE,gDAAgD;QAC7D,eAAe,EAAE,KAAK,CAAC,eAAe;YACpC,CAAC,CAAC;gBACE,MAAM,EAAE;oBACN,eAAe,EAAE,KAAK,CAAC,eAAe;iBACvC;aACF;YACH,CAAC,CAAC,SAAS;QACb,KAAK,EAAE;QACL,iBAAiB;SAClB;QACD,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,QAAQ;gBACd,OAAO,EACL,gLAAgL;aACnL;YACD,GAAG,sBAAsB,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;YACnD;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;;;EAGjB,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;+HAUuE;aACtH;SACF;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,8BAA8B;QAC9B,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtD,qCAAqC;QACrC,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC,CACF;CAAG"}
|
package/lib/output.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Eval<U> = U extends Output<infer V> ? Eval<V> : U;
|
|
2
|
+
export declare function isOutput<T>(value: any): value is Output<T>;
|
|
3
|
+
export type Outputs<P extends readonly any[]> = P extends [
|
|
4
|
+
infer First,
|
|
5
|
+
...infer Rest
|
|
6
|
+
] ? [Output<First>, ...Outputs<Rest>] : [];
|
|
7
|
+
export type Output<T> = {
|
|
8
|
+
apply<U>(fn: (value: T) => U): Output<Eval<U>>;
|
|
9
|
+
} & (T extends string ? {
|
|
10
|
+
[k in keyof typeof String.prototype]: Output<(typeof String.prototype)[k]>;
|
|
11
|
+
} : T extends number ? {
|
|
12
|
+
[K in keyof typeof Number.prototype]: Output<(typeof Number.prototype)[K]>;
|
|
13
|
+
} : T extends boolean ? {
|
|
14
|
+
[K in keyof typeof Boolean.prototype]: Output<(typeof Boolean.prototype)[K]>;
|
|
15
|
+
} : T extends any[] ? Outputs<T> : {
|
|
16
|
+
[k in keyof T]: Output<T[k]>;
|
|
17
|
+
});
|
|
18
|
+
export declare const Output: new <T, U>(parent: Output<T>, fn: (value: T) => U) => Output<U>;
|
|
19
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAE9D,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAI1D;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS;IACxD,MAAM,KAAK;IACX,GAAG,MAAM,IAAI;CACd,GACG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GACjC,EAAE,CAAC;AAEP,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IACtB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;CAChD,GAAG,CAAC,CAAC,SAAS,MAAM,GACjB;KACG,CAAC,IAAI,MAAM,OAAO,MAAM,CAAC,SAAS,GAAG,MAAM,CAC1C,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC7B;CACF,GACD,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,OAAO,MAAM,CAAC,SAAS,GAAG,MAAM,CAC1C,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC7B;CACF,GACD,CAAC,SAAS,OAAO,GACf;KACG,CAAC,IAAI,MAAM,OAAO,OAAO,CAAC,SAAS,GAAG,MAAM,CAC3C,CAAC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC9B;CACF,GACD,CAAC,SAAS,GAAG,EAAE,GACb,OAAO,CAAC,CAAC,CAAC,GACV;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAC;AAEb,eAAO,MAAM,MAAM,EAUd,KAAK,CAAC,EAAE,CAAC,EACZ,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAChB,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
package/lib/output.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isOutput(value) {
|
|
2
|
+
return (value && typeof value === "object" && typeof value.apply === "function");
|
|
3
|
+
}
|
|
4
|
+
export const Output = class {
|
|
5
|
+
parent;
|
|
6
|
+
fn;
|
|
7
|
+
constructor(parent, fn) {
|
|
8
|
+
this.parent = parent;
|
|
9
|
+
this.fn = fn;
|
|
10
|
+
}
|
|
11
|
+
apply(fn) {
|
|
12
|
+
// @ts-expect-error - we know we are an "Output"
|
|
13
|
+
return new Output(this, fn);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAI,KAAU;IACpC,OAAO,CACL,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CACxE,CAAC;AACJ,CAAC;AAmCD,MAAM,CAAC,MAAM,MAAM,GAAG;IAEF;IACA;IAFlB,YACkB,MAAiB,EACjB,EAAmB;QADnB,WAAM,GAAN,MAAM,CAAW;QACjB,OAAE,GAAF,EAAE,CAAiB;IAClC,CAAC;IAEG,KAAK,CAAI,EAAmB;QACjC,gDAAgD;QAChD,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC;CAIW,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type ApplyOptions } from "./apply";
|
|
2
|
+
import type { DestroyOptions } from "./destroy";
|
|
3
|
+
import type { Inputs, Input as input } from "./input";
|
|
4
|
+
import { Output } from "./output";
|
|
5
|
+
import { Scope as IScope } from "./scope";
|
|
6
|
+
import type { State, StateStore } from "./state";
|
|
7
|
+
export type ResourceID = string;
|
|
8
|
+
export type ResourceType = string;
|
|
9
|
+
export declare const ResourceID: unique symbol;
|
|
10
|
+
export declare const Provider: unique symbol;
|
|
11
|
+
export declare const Input: unique symbol;
|
|
12
|
+
export declare const Value: unique symbol;
|
|
13
|
+
export declare const Apply: unique symbol;
|
|
14
|
+
export declare const Provide: unique symbol;
|
|
15
|
+
export declare const Scope: unique symbol;
|
|
16
|
+
export declare const Options: unique symbol;
|
|
17
|
+
export interface ProviderOptions {
|
|
18
|
+
/**
|
|
19
|
+
* If true, the resource will be updated even if the inputs have not changed.
|
|
20
|
+
*/
|
|
21
|
+
alwaysUpdate: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type Resource<In extends any[] = any[], Out = any> = {
|
|
24
|
+
[ResourceID]: string;
|
|
25
|
+
[Provider]: Provider<any, any[], any>;
|
|
26
|
+
[Input]: Inputs<In>;
|
|
27
|
+
[Value]?: Out;
|
|
28
|
+
[Apply]: <O>(value: Out) => O;
|
|
29
|
+
[Provide]: (value: Out) => void;
|
|
30
|
+
[Options]: ProviderOptions;
|
|
31
|
+
} & Output<Out>;
|
|
32
|
+
export interface BaseContext {
|
|
33
|
+
quiet: boolean;
|
|
34
|
+
stage: string;
|
|
35
|
+
resourceID: ResourceID;
|
|
36
|
+
scope: IScope;
|
|
37
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
38
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
39
|
+
delete<T>(key: string): Promise<T | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Indicate that this resource is being replaced.
|
|
42
|
+
* This will cause the resource to be deleted at the end of the stack's CREATE phase.
|
|
43
|
+
*/
|
|
44
|
+
replace(): void;
|
|
45
|
+
}
|
|
46
|
+
export interface CreateContext extends BaseContext {
|
|
47
|
+
event: "create";
|
|
48
|
+
}
|
|
49
|
+
export interface UpdateContext<Outputs> extends BaseContext {
|
|
50
|
+
event: "update";
|
|
51
|
+
output: Outputs;
|
|
52
|
+
}
|
|
53
|
+
export interface DeleteContext<Outputs> extends BaseContext {
|
|
54
|
+
event: "delete";
|
|
55
|
+
output: Outputs;
|
|
56
|
+
}
|
|
57
|
+
export type Context<Outputs> = CreateContext | UpdateContext<Outputs> | DeleteContext<Outputs>;
|
|
58
|
+
export type Provider<Type extends ResourceType = ResourceType, In extends any[] = any[], Out = any> = {
|
|
59
|
+
type: Type;
|
|
60
|
+
update(stage: string, resource: Resource, deps: Set<ResourceID>, inputs: Inputs<In>, stateStore: StateStore, options: ApplyOptions): Promise<Awaited<Out>>;
|
|
61
|
+
delete(stage: string, scope: IScope | undefined, resourceID: ResourceID, state: State, inputs: Inputs<In>, options: DestroyOptions): Promise<void>;
|
|
62
|
+
} & (new (id: string, ...inputs: [...Inputs<In>, ...any[]]) => Resource<In, Out>);
|
|
63
|
+
export declare function isResource(value: any): value is Resource;
|
|
64
|
+
export declare function Resource<const Type extends ResourceType, Args extends any[], Out>(type: Type, options: Partial<ProviderOptions>, func: (ctx: Context<Out>, ...args: Args) => Promise<input<Out> | void> | input<Out> | void): Provider<Type, Args, Awaited<Out>>;
|
|
65
|
+
export declare function Resource<const Type extends ResourceType, Args extends any[], Out>(type: Type, func: (ctx: Context<Out>, ...args: Args) => Promise<input<Out> | void> | input<Out> | void): Provider<Type, Args, Awaited<Out>>;
|
|
66
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAS,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,IAAI,MAAM,EAAuB,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,eAAO,MAAM,UAAU,eAA2B,CAAC;AACnD,eAAO,MAAM,QAAQ,eAAyB,CAAC;AAC/C,eAAO,MAAM,KAAK,eAAsB,CAAC;AACzC,eAAO,MAAM,KAAK,eAAsB,CAAC;AACzC,eAAO,MAAM,KAAK,eAAsB,CAAC;AACzC,eAAO,MAAM,OAAO,eAAwB,CAAC;AAC7C,eAA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