@usepipr/sdk 0.1.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.
@@ -0,0 +1,95 @@
1
+ import { t as renderPromptValue } from "./prompt-render-CHlrR9Sa.mjs";
2
+ import path from "node:path";
3
+ //#region src/standalone-declaration.ts
4
+ async function readSdkDeclarationSourceWithChunk(module, declarationPath) {
5
+ const source = await Bun.file(declarationPath).text();
6
+ if (module.moduleName !== "@usepipr/sdk") return source;
7
+ const chunkFileName = source.match(/from "\.\/(?<chunk>index-[A-Za-z0-9_-]+)\.mjs"/)?.groups?.chunk;
8
+ if (!chunkFileName) return source;
9
+ const chunkPath = path.join(path.dirname(declarationPath), `${chunkFileName}.d.mts`);
10
+ return `${(await Bun.file(chunkPath).text()).replace(/^export \{.*\};$/gm, "")}\n${source}`;
11
+ }
12
+ function embeddedSdkDeclaration(modules) {
13
+ const declaration = [
14
+ "// biome-ignore-all format: generated from @usepipr/sdk declarations",
15
+ "// biome-ignore-all assist/source/organizeImports: generated from @usepipr/sdk declarations",
16
+ ...modules.map(declarationModuleBlock),
17
+ ""
18
+ ].join("\n");
19
+ if (declaration.includes("from \"zod\"") || declaration.includes("z.ZodType")) throw new Error("embedded SDK declaration must be standalone and must not import zod");
20
+ return declaration;
21
+ }
22
+ function declarationModuleBlock(module) {
23
+ return [
24
+ `declare module "${module.moduleName}" {`,
25
+ declarationSource(module).trim(),
26
+ "}"
27
+ ].join("\n");
28
+ }
29
+ function declarationSource(module) {
30
+ const source = module.source.replace(/^declare /gm, "").replace(/^import \{ (?:z|z, z as z\$1|z as z\$1) \} from "zod";$/gm, zodShimDeclaration()).replaceAll("z$1.", "z.").replaceAll("z.ZodType", "ZodType").replaceAll("from \"./index.js\"", "from \"@usepipr/sdk\"").replaceAll("from \"./index.mjs\"", "from \"@usepipr/sdk\"").replace(/from "\.\/index-[^"]+\.mjs"/g, "from \"@usepipr/sdk\"").replace(/^import .* from "@usepipr\/sdk";$/gm, "").replace(/^\/\/# sourceMappingURL=.*$/gm, "");
31
+ return module.moduleName === "@usepipr/sdk" ? source : source.replace(/^export type \{(?<exports>.*)\};$/gm, "export type {$<exports>} from \"@usepipr/sdk\";").replace(/^export \{(?<exports>.*)\};$/gm, "export {$<exports>} from \"@usepipr/sdk\";");
32
+ }
33
+ function zodShimDeclaration() {
34
+ return [
35
+ "type ZodInfer<T> = T extends { parse(value: unknown): infer Output } ? Output : never;",
36
+ "type ZodType<T = unknown, Optional extends boolean = false> = {",
37
+ " readonly _piprOptional: Optional;",
38
+ " parse(value: unknown): T;",
39
+ " optional(): ZodType<T | undefined, true>;",
40
+ " min(value: number): ZodType<T, Optional>;",
41
+ " max(value: number): ZodType<T, Optional>;",
42
+ " int(): ZodType<T, Optional>;",
43
+ " positive(): ZodType<T, Optional>;",
44
+ " finite(): ZodType<T, Optional>;",
45
+ "};",
46
+ "type ZodAny = ZodType<unknown, boolean>;",
47
+ "type ZodOptionalKeys<T extends Record<string, ZodAny>> = { [K in keyof T]: T[K] extends ZodType<unknown, true> ? K : never }[keyof T];",
48
+ "type ZodObjectOutput<T extends Record<string, ZodAny>> = { [K in Exclude<keyof T, ZodOptionalKeys<T>>]: ZodInfer<T[K]> } & { [K in ZodOptionalKeys<T>]?: ZodInfer<T[K]> };",
49
+ "const z: {",
50
+ " string(): ZodType<string>;",
51
+ " number(): ZodType<number>;",
52
+ " boolean(): ZodType<boolean>;",
53
+ " null(): ZodType<null>;",
54
+ " unknown(): ZodType<unknown>;",
55
+ " any(): ZodType<unknown>;",
56
+ " literal<T extends string | number | boolean | null>(value: T): ZodType<T>;",
57
+ " enum<const T extends readonly [string, ...string[]]>(values: T): ZodType<T[number]>;",
58
+ " array<T extends ZodAny>(schema: T): ZodType<Array<ZodInfer<T>>>;",
59
+ " record<T extends ZodAny>(key: ZodType<string>, value: T): ZodType<Record<string, ZodInfer<T>>>;",
60
+ " strictObject<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T>>;",
61
+ " object<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T>>;",
62
+ " looseObject<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T> & Record<string, unknown>>;",
63
+ " union<const T extends readonly [ZodAny, ZodAny, ...ZodAny[]]>(schemas: T): ZodType<ZodInfer<T[number]>>;",
64
+ " json(): ZodType<JsonValue>;",
65
+ " fromJSONSchema(schema: JsonSchema): ZodType<unknown>;",
66
+ " toJSONSchema(schema: ZodAny): JsonSchema;",
67
+ "};"
68
+ ].join("\n");
69
+ }
70
+ //#endregion
71
+ //#region src/internal.ts
72
+ /** Stable identifier for pipr's built-in pull request review output schema. */
73
+ const reviewOutputSchemaId = "core/pr-review";
74
+ const configFactoryBrand = Symbol.for("pipr.config.factory");
75
+ const builtinReadOnlyToolBrand = Symbol.for("pipr.builtin.readOnlyTool");
76
+ /** Returns whether a tool is one of pipr's built-in read-only tools. */
77
+ function isBuiltinReadOnlyTool(tool) {
78
+ return Reflect.get(tool, builtinReadOnlyToolBrand) === true;
79
+ }
80
+ /** Checks that an unknown value is a pipr configuration factory. */
81
+ function isPiprConfigFactory(value) {
82
+ return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "pipr.config-factory" && Reflect.get(value, configFactoryBrand) === true;
83
+ }
84
+ /** Builds a runtime plan from a pipr configuration factory. */
85
+ function buildPiprPlan(factory) {
86
+ if (!isInternalPiprConfigFactory(factory)) throw new Error("Expected a pipr configuration factory");
87
+ return factory.build();
88
+ }
89
+ function isInternalPiprConfigFactory(value) {
90
+ return isPiprConfigFactory(value) && typeof Reflect.get(value, "build") === "function";
91
+ }
92
+ //#endregion
93
+ export { buildPiprPlan, embeddedSdkDeclaration, isBuiltinReadOnlyTool, isPiprConfigFactory, readSdkDeclarationSourceWithChunk, renderPromptValue, reviewOutputSchemaId };
94
+
95
+ //# sourceMappingURL=internal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.mjs","names":[],"sources":["../src/standalone-declaration.ts","../src/internal.ts"],"sourcesContent":["import path from \"node:path\";\n\nexport type SdkDeclarationModule = {\n moduleName: string;\n source: string;\n};\n\nexport async function readSdkDeclarationSourceWithChunk(\n module: { moduleName: string },\n declarationPath: string,\n): Promise<string> {\n const source = await Bun.file(declarationPath).text();\n if (module.moduleName !== \"@usepipr/sdk\") {\n return source;\n }\n const chunkFileName = source.match(/from \"\\.\\/(?<chunk>index-[A-Za-z0-9_-]+)\\.mjs\"/)?.groups\n ?.chunk;\n if (!chunkFileName) {\n return source;\n }\n const chunkPath = path.join(path.dirname(declarationPath), `${chunkFileName}.d.mts`);\n const chunk = await Bun.file(chunkPath).text();\n const declarations = chunk.replace(/^export \\{.*\\};$/gm, \"\");\n return `${declarations}\\n${source}`;\n}\n\nexport function embeddedSdkDeclaration(modules: SdkDeclarationModule[]): string {\n const declaration = [\n \"// biome-ignore-all format: generated from @usepipr/sdk declarations\",\n \"// biome-ignore-all assist/source/organizeImports: generated from @usepipr/sdk declarations\",\n ...modules.map(declarationModuleBlock),\n \"\",\n ].join(\"\\n\");\n if (declaration.includes('from \"zod\"') || declaration.includes(\"z.ZodType\")) {\n throw new Error(\"embedded SDK declaration must be standalone and must not import zod\");\n }\n return declaration;\n}\n\nfunction declarationModuleBlock(module: SdkDeclarationModule): string {\n return [`declare module \"${module.moduleName}\" {`, declarationSource(module).trim(), \"}\"].join(\n \"\\n\",\n );\n}\n\nfunction declarationSource(module: SdkDeclarationModule): string {\n const source = module.source\n .replace(/^declare /gm, \"\")\n .replace(/^import \\{ (?:z|z, z as z\\$1|z as z\\$1) \\} from \"zod\";$/gm, zodShimDeclaration())\n .replaceAll(\"z$1.\", \"z.\")\n .replaceAll(\"z.ZodType\", \"ZodType\")\n .replaceAll('from \"./index.js\"', 'from \"@usepipr/sdk\"')\n .replaceAll('from \"./index.mjs\"', 'from \"@usepipr/sdk\"')\n .replace(/from \"\\.\\/index-[^\"]+\\.mjs\"/g, 'from \"@usepipr/sdk\"')\n .replace(/^import .* from \"@usepipr\\/sdk\";$/gm, \"\")\n .replace(/^\\/\\/# sourceMappingURL=.*$/gm, \"\");\n return module.moduleName === \"@usepipr/sdk\"\n ? source\n : source\n .replace(\n /^export type \\{(?<exports>.*)\\};$/gm,\n 'export type {$<exports>} from \"@usepipr/sdk\";',\n )\n .replace(/^export \\{(?<exports>.*)\\};$/gm, 'export {$<exports>} from \"@usepipr/sdk\";');\n}\n\nfunction zodShimDeclaration(): string {\n return [\n \"type ZodInfer<T> = T extends { parse(value: unknown): infer Output } ? Output : never;\",\n \"type ZodType<T = unknown, Optional extends boolean = false> = {\",\n \" readonly _piprOptional: Optional;\",\n \" parse(value: unknown): T;\",\n \" optional(): ZodType<T | undefined, true>;\",\n \" min(value: number): ZodType<T, Optional>;\",\n \" max(value: number): ZodType<T, Optional>;\",\n \" int(): ZodType<T, Optional>;\",\n \" positive(): ZodType<T, Optional>;\",\n \" finite(): ZodType<T, Optional>;\",\n \"};\",\n \"type ZodAny = ZodType<unknown, boolean>;\",\n \"type ZodOptionalKeys<T extends Record<string, ZodAny>> = { [K in keyof T]: T[K] extends ZodType<unknown, true> ? K : never }[keyof T];\",\n \"type ZodObjectOutput<T extends Record<string, ZodAny>> = { [K in Exclude<keyof T, ZodOptionalKeys<T>>]: ZodInfer<T[K]> } & { [K in ZodOptionalKeys<T>]?: ZodInfer<T[K]> };\",\n \"const z: {\",\n \" string(): ZodType<string>;\",\n \" number(): ZodType<number>;\",\n \" boolean(): ZodType<boolean>;\",\n \" null(): ZodType<null>;\",\n \" unknown(): ZodType<unknown>;\",\n \" any(): ZodType<unknown>;\",\n \" literal<T extends string | number | boolean | null>(value: T): ZodType<T>;\",\n \" enum<const T extends readonly [string, ...string[]]>(values: T): ZodType<T[number]>;\",\n \" array<T extends ZodAny>(schema: T): ZodType<Array<ZodInfer<T>>>;\",\n \" record<T extends ZodAny>(key: ZodType<string>, value: T): ZodType<Record<string, ZodInfer<T>>>;\",\n \" strictObject<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T>>;\",\n \" object<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T>>;\",\n \" looseObject<T extends Record<string, ZodAny>>(shape: T): ZodType<ZodObjectOutput<T> & Record<string, unknown>>;\",\n \" union<const T extends readonly [ZodAny, ZodAny, ...ZodAny[]]>(schemas: T): ZodType<ZodInfer<T[number]>>;\",\n \" json(): ZodType<JsonValue>;\",\n \" fromJSONSchema(schema: JsonSchema): ZodType<unknown>;\",\n \" toJSONSchema(schema: ZodAny): JsonSchema;\",\n \"};\",\n ].join(\"\\n\");\n}\n","import type { AgentTool } from \"./index.js\";\n\nexport type { RuntimePlan } from \"./runtime-contract.js\";\n\nimport type { RuntimePlan } from \"./runtime-contract.js\";\n\nexport { renderPromptValue } from \"./prompt-render.js\";\nexport type { SdkDeclarationModule } from \"./standalone-declaration.js\";\nexport {\n embeddedSdkDeclaration,\n readSdkDeclarationSourceWithChunk,\n} from \"./standalone-declaration.js\";\n\n/** Stable identifier for pipr's built-in pull request review output schema. */\nexport const reviewOutputSchemaId = \"core/pr-review\";\n\nconst configFactoryBrand = Symbol.for(\"pipr.config.factory\");\nconst builtinReadOnlyToolBrand = Symbol.for(\"pipr.builtin.readOnlyTool\");\n\ntype ConfigFactoryValue = {\n readonly kind: \"pipr.config-factory\";\n};\n\ntype InternalPiprConfigFactory = ConfigFactoryValue & {\n readonly [configFactoryBrand]: true;\n build(): RuntimePlan;\n};\n\n/** Returns whether a tool is one of pipr's built-in read-only tools. */\nexport function isBuiltinReadOnlyTool(tool: AgentTool): boolean {\n return Reflect.get(tool, builtinReadOnlyToolBrand) === true;\n}\n\n/** Checks that an unknown value is a pipr configuration factory. */\nexport function isPiprConfigFactory(value: unknown): value is ConfigFactoryValue {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Reflect.get(value, \"kind\") === \"pipr.config-factory\" &&\n Reflect.get(value, configFactoryBrand) === true\n );\n}\n\n/** Builds a runtime plan from a pipr configuration factory. */\nexport function buildPiprPlan(factory: unknown): RuntimePlan {\n if (!isInternalPiprConfigFactory(factory)) {\n throw new Error(\"Expected a pipr configuration factory\");\n }\n return factory.build();\n}\n\nfunction isInternalPiprConfigFactory(value: unknown): value is InternalPiprConfigFactory {\n return isPiprConfigFactory(value) && typeof Reflect.get(value, \"build\") === \"function\";\n}\n"],"mappings":";;;AAOA,eAAsB,kCACpB,QACA,iBACiB;CACjB,MAAM,SAAS,MAAM,IAAI,KAAK,eAAe,CAAC,CAAC,KAAK;CACpD,IAAI,OAAO,eAAe,gBACxB,OAAO;CAET,MAAM,gBAAgB,OAAO,MAAM,gDAAgD,CAAC,EAAE,QAClF;CACJ,IAAI,CAAC,eACH,OAAO;CAET,MAAM,YAAY,KAAK,KAAK,KAAK,QAAQ,eAAe,GAAG,GAAG,cAAc,OAAO;CAGnF,OAAO,IADc,MADD,IAAI,KAAK,SAAS,CAAC,CAAC,KAAK,EAAA,CAClB,QAAQ,sBAAsB,EACpC,EAAE,IAAI;AAC7B;AAEA,SAAgB,uBAAuB,SAAyC;CAC9E,MAAM,cAAc;EAClB;EACA;EACA,GAAG,QAAQ,IAAI,sBAAsB;EACrC;CACF,CAAC,CAAC,KAAK,IAAI;CACX,IAAI,YAAY,SAAS,cAAY,KAAK,YAAY,SAAS,WAAW,GACxE,MAAM,IAAI,MAAM,qEAAqE;CAEvF,OAAO;AACT;AAEA,SAAS,uBAAuB,QAAsC;CACpE,OAAO;EAAC,mBAAmB,OAAO,WAAW;EAAM,kBAAkB,MAAM,CAAC,CAAC,KAAK;EAAG;CAAG,CAAC,CAAC,KACxF,IACF;AACF;AAEA,SAAS,kBAAkB,QAAsC;CAC/D,MAAM,SAAS,OAAO,OACnB,QAAQ,eAAe,EAAE,CAAC,CAC1B,QAAQ,6DAA6D,mBAAmB,CAAC,CAAC,CAC1F,WAAW,QAAQ,IAAI,CAAC,CACxB,WAAW,aAAa,SAAS,CAAC,CAClC,WAAW,uBAAqB,uBAAqB,CAAC,CACtD,WAAW,wBAAsB,uBAAqB,CAAC,CACvD,QAAQ,gCAAgC,uBAAqB,CAAC,CAC9D,QAAQ,uCAAuC,EAAE,CAAC,CAClD,QAAQ,iCAAiC,EAAE;CAC9C,OAAO,OAAO,eAAe,iBACzB,SACA,OACG,QACC,uCACA,iDACF,CAAC,CACA,QAAQ,kCAAkC,4CAA0C;AAC7F;AAEA,SAAS,qBAA6B;CACpC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;;;;ACxFA,MAAa,uBAAuB;AAEpC,MAAM,qBAAqB,OAAO,IAAI,qBAAqB;AAC3D,MAAM,2BAA2B,OAAO,IAAI,2BAA2B;;AAYvE,SAAgB,sBAAsB,MAA0B;CAC9D,OAAO,QAAQ,IAAI,MAAM,wBAAwB,MAAM;AACzD;;AAGA,SAAgB,oBAAoB,OAA6C;CAC/E,OACE,OAAO,UAAU,YACjB,UAAU,QACV,QAAQ,IAAI,OAAO,MAAM,MAAM,yBAC/B,QAAQ,IAAI,OAAO,kBAAkB,MAAM;AAE/C;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,IAAI,CAAC,4BAA4B,OAAO,GACtC,MAAM,IAAI,MAAM,uCAAuC;CAEzD,OAAO,QAAQ,MAAM;AACvB;AAEA,SAAS,4BAA4B,OAAoD;CACvF,OAAO,oBAAoB,KAAK,KAAK,OAAO,QAAQ,IAAI,OAAO,OAAO,MAAM;AAC9E"}
@@ -0,0 +1,13 @@
1
+ //#region src/prompt-render.ts
2
+ /** Renders a prompt source/value into plain text for Pi prompts. */
3
+ function renderPromptValue(value) {
4
+ if (value === void 0 || value === null) return "";
5
+ if (typeof value === "string") return value;
6
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
7
+ if (typeof value === "object" && value !== null && Reflect.get(value, "kind") === "pipr.prompt") return value.value;
8
+ return JSON.stringify(value, null, 2);
9
+ }
10
+ //#endregion
11
+ export { renderPromptValue as t };
12
+
13
+ //# sourceMappingURL=prompt-render-CHlrR9Sa.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-render-CHlrR9Sa.mjs","names":[],"sources":["../src/prompt-render.ts"],"sourcesContent":["import type { PromptText, PromptValue } from \"./index.js\";\n\n/** Renders a prompt source/value into plain text for Pi prompts. */\nexport function renderPromptValue(value: PromptValue): string {\n if (value === undefined || value === null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n if (typeof value === \"object\" && value !== null && Reflect.get(value, \"kind\") === \"pipr.prompt\") {\n return (value as PromptText).value;\n }\n return JSON.stringify(value, null, 2);\n}\n"],"mappings":";;AAGA,SAAgB,kBAAkB,OAA4B;CAC5D,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC,OAAO;CAET,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAChD,OAAO,OAAO,KAAK;CAErB,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,QAAQ,IAAI,OAAO,MAAM,MAAM,eAChF,OAAQ,MAAqB;CAE/B,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC;AACtC"}
@@ -0,0 +1,2 @@
1
+ import { $ as ReviewRecipeOptions, At as reviewSchemaExample, Ct as ReviewResult, Dt as parseReviewSummary, Et as parseReviewResult, I as PathFilter, N as Markdown, Ot as reviewFindingSchema, Q as ReviewEntrypoints, S as DefaultReviewInput, St as ReviewFinding, Tt as parseReviewFinding, U as PriorInlineFinding, W as PriorReview, Z as ReviewCommentContext, et as Reviewer, f as ChangeRequestAction, i as AgentPromptContext, jt as reviewSummarySchema, kt as reviewResultSchema, tt as ReviewerOptions, wt as ReviewSummary, x as CommentValue } from "./index-DMjdjJV4.mjs";
2
+ export { type AgentPromptContext, type ChangeRequestAction, type CommentValue, type DefaultReviewInput, type Markdown, type PathFilter, type PriorInlineFinding, type PriorReview, type ReviewCommentContext, type ReviewEntrypoints, type ReviewFinding, type ReviewRecipeOptions, type ReviewResult, type ReviewSummary, type Reviewer, type ReviewerOptions, parseReviewFinding, parseReviewResult, parseReviewSummary, reviewFindingSchema, reviewResultSchema, reviewSchemaExample, reviewSummarySchema };
@@ -0,0 +1,2 @@
1
+ import { c as parseReviewResult, d as reviewResultSchema, f as reviewSchemaExample, l as parseReviewSummary, p as reviewSummarySchema, s as parseReviewFinding, u as reviewFindingSchema } from "./src-CR3NktDT.mjs";
2
+ export { parseReviewFinding, parseReviewResult, parseReviewSummary, reviewFindingSchema, reviewResultSchema, reviewSchemaExample, reviewSummarySchema };