@microsoft/copilot-sdk 0.0.0-stage → 2.0.0-preview.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.
Files changed (91) hide show
  1. package/README.md +2531 -2
  2. package/dist/canvas.d.ts +135 -0
  3. package/dist/canvas.js +51 -0
  4. package/dist/cjs/canvas.js +77 -0
  5. package/dist/cjs/cliVersion.js +31 -0
  6. package/dist/cjs/client.js +3941 -0
  7. package/dist/cjs/copilotRequestHandler.js +815 -0
  8. package/dist/cjs/decisions.js +139 -0
  9. package/dist/cjs/entra.js +83 -0
  10. package/dist/cjs/extension.js +79 -0
  11. package/dist/cjs/ffiRuntimeHost.js +400 -0
  12. package/dist/cjs/generated/lifecycle-diagnostics.js +16 -0
  13. package/dist/cjs/generated/rpc.js +5883 -0
  14. package/dist/cjs/generated/session-events.js +16 -0
  15. package/dist/cjs/host.js +83 -0
  16. package/dist/cjs/index.js +100 -0
  17. package/dist/cjs/installationConfirmation.js +98 -0
  18. package/dist/cjs/jsonrpcTypes.js +41 -0
  19. package/dist/cjs/localModelJson.js +103 -0
  20. package/dist/cjs/package.json +1 -0
  21. package/dist/cjs/providerConfiguration.js +39 -0
  22. package/dist/cjs/rpcCancellation.js +49 -0
  23. package/dist/cjs/runtimeArtifacts.js +255 -0
  24. package/dist/cjs/schema.js +40 -0
  25. package/dist/cjs/sdkProtocolVersion.js +33 -0
  26. package/dist/cjs/session.js +2764 -0
  27. package/dist/cjs/sessionFsProvider.js +283 -0
  28. package/dist/cjs/taskAnalyticsJson.js +47 -0
  29. package/dist/cjs/telemetry.js +35 -0
  30. package/dist/cjs/toolSet.js +107 -0
  31. package/dist/cjs/types.js +204 -0
  32. package/dist/cjs/workflow.js +278 -0
  33. package/dist/cliVersion.d.ts +2 -0
  34. package/dist/cliVersion.js +6 -0
  35. package/dist/client.d.ts +576 -0
  36. package/dist/client.js +3924 -0
  37. package/dist/copilotRequestHandler.d.ts +91 -0
  38. package/dist/copilotRequestHandler.js +787 -0
  39. package/dist/decisions.d.ts +65 -0
  40. package/dist/decisions.js +113 -0
  41. package/dist/entra.d.ts +3 -0
  42. package/dist/entra.js +59 -0
  43. package/dist/extension.d.ts +69 -0
  44. package/dist/extension.js +59 -0
  45. package/dist/ffiRuntimeHost.d.ts +44 -0
  46. package/dist/ffiRuntimeHost.js +366 -0
  47. package/dist/generated/lifecycle-diagnostics.d.ts +232 -0
  48. package/dist/generated/lifecycle-diagnostics.js +0 -0
  49. package/dist/generated/rpc.d.ts +47706 -0
  50. package/dist/generated/rpc.js +5854 -0
  51. package/dist/generated/session-events.d.ts +17349 -0
  52. package/dist/generated/session-events.js +0 -0
  53. package/dist/host.d.ts +143 -0
  54. package/dist/host.js +59 -0
  55. package/dist/index.d.ts +23 -0
  56. package/dist/index.js +74 -0
  57. package/dist/installationConfirmation.d.ts +19 -0
  58. package/dist/installationConfirmation.js +74 -0
  59. package/dist/jsonrpcTypes.d.ts +16 -0
  60. package/dist/jsonrpcTypes.js +17 -0
  61. package/dist/localModelJson.d.ts +1 -0
  62. package/dist/localModelJson.js +69 -0
  63. package/dist/providerConfiguration.d.ts +3 -0
  64. package/dist/providerConfiguration.js +15 -0
  65. package/dist/rpcCancellation.d.ts +3 -0
  66. package/dist/rpcCancellation.js +25 -0
  67. package/dist/runtimeArtifacts.d.ts +18 -0
  68. package/dist/runtimeArtifacts.js +233 -0
  69. package/dist/schema.d.ts +4 -0
  70. package/dist/schema.js +14 -0
  71. package/dist/sdkProtocolVersion.d.ts +10 -0
  72. package/dist/sdkProtocolVersion.js +8 -0
  73. package/dist/session.d.ts +524 -0
  74. package/dist/session.js +2751 -0
  75. package/dist/sessionFsProvider.d.ts +130 -0
  76. package/dist/sessionFsProvider.js +257 -0
  77. package/dist/taskAnalyticsJson.d.ts +8 -0
  78. package/dist/taskAnalyticsJson.js +12 -0
  79. package/dist/telemetry.d.ts +14 -0
  80. package/dist/telemetry.js +11 -0
  81. package/dist/toolSet.d.ts +75 -0
  82. package/dist/toolSet.js +82 -0
  83. package/dist/types.d.ts +3864 -0
  84. package/dist/types.js +169 -0
  85. package/dist/workflow.d.ts +413 -0
  86. package/dist/workflow.js +248 -0
  87. package/docs/agent-author.md +372 -0
  88. package/docs/examples.md +747 -0
  89. package/docs/extensions.md +121 -0
  90. package/docs/workflows.md +303 -0
  91. package/package.json +135 -5
@@ -0,0 +1,233 @@
1
+ import {
2
+ chmodSync,
3
+ copyFileSync,
4
+ existsSync,
5
+ lstatSync,
6
+ mkdirSync,
7
+ mkdtempSync,
8
+ readdirSync,
9
+ renameSync,
10
+ rmSync,
11
+ statSync
12
+ } from "node:fs";
13
+ import { createHash } from "node:crypto";
14
+ import { createRequire } from "node:module";
15
+ import { homedir } from "node:os";
16
+ import { dirname, join, relative, sep } from "node:path";
17
+ import { COPILOT_CLI_USE_NPM_PACKAGE } from "./cliVersion.js";
18
+ const require2 = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
19
+ const RUNTIME_PLATFORMS = [
20
+ "darwin-arm64",
21
+ "darwin-x64",
22
+ "linux-arm64",
23
+ "linux-x64",
24
+ "linuxmusl-arm64",
25
+ "linuxmusl-x64",
26
+ "win32-arm64",
27
+ "win32-x64"
28
+ ];
29
+ const EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
30
+ "app.js",
31
+ "assets",
32
+ "changelog.json",
33
+ "cli-main.js",
34
+ "copilot",
35
+ "copilot.exe",
36
+ "foundry-local-sdk",
37
+ "index.js",
38
+ "LICENSE.md",
39
+ "napi-oop-runtime",
40
+ "npm-loader.js",
41
+ "package.json",
42
+ "pvrecorder",
43
+ "queries",
44
+ "README.md",
45
+ "sea-loader.js",
46
+ "webview"
47
+ ]);
48
+ function validateFile(path, label) {
49
+ if (!existsSync(path)) {
50
+ throw new Error(`${label} not found at ${path}.`);
51
+ }
52
+ if (statSync(path).size === 0) {
53
+ throw new Error(`${label} at ${path} is empty.`);
54
+ }
55
+ }
56
+ function validateRuntimeBundle(wrapper, runtimeNode) {
57
+ validateFile(wrapper, "Copilot runtime wrapper");
58
+ validateFile(runtimeNode, "Copilot runtime.node");
59
+ }
60
+ function isExcluded(relativePath) {
61
+ const parts = relativePath.split(sep);
62
+ const topLevel = parts[0];
63
+ const fileName = parts.at(-1) ?? "";
64
+ return EXCLUDED_TOP_LEVEL.has(topLevel) || /^tree-sitter.*\.wasm$/.test(topLevel) || /^voice-.*\.js$/.test(topLevel) || fileName === "cli-native.node" || parts.includes("mediaremote-adapter") || fileName.startsWith("copilot-runtime-bin");
65
+ }
66
+ function collectRuntimeAssets(sources) {
67
+ const assets = [];
68
+ const visit = (directory) => {
69
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
70
+ const source = join(directory, entry.name);
71
+ const sourceRelative = relative(sources.packageRoot, source);
72
+ if (isExcluded(sourceRelative)) {
73
+ continue;
74
+ }
75
+ if (entry.isDirectory()) {
76
+ visit(source);
77
+ continue;
78
+ }
79
+ if (!entry.isFile() && !entry.isSymbolicLink()) {
80
+ continue;
81
+ }
82
+ const parts = sourceRelative.split(sep);
83
+ if (parts[0] === "prebuilds") {
84
+ if (parts[1] !== sources.platform || parts.length < 3) {
85
+ continue;
86
+ }
87
+ }
88
+ assets.push({ source, relativePath: sourceRelative });
89
+ }
90
+ };
91
+ visit(sources.packageRoot);
92
+ return assets.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
93
+ }
94
+ function sourceFingerprint(assets) {
95
+ const hash = createHash("sha256");
96
+ for (const asset of assets) {
97
+ const stat = lstatSync(asset.source);
98
+ hash.update(asset.relativePath).update("\0");
99
+ hash.update(`${stat.size}:${stat.mtimeMs}`).update("\0");
100
+ }
101
+ return hash.digest("hex").slice(0, 20);
102
+ }
103
+ function makeExecutable(path) {
104
+ if (process.platform === "win32") {
105
+ return;
106
+ }
107
+ const mode = statSync(path).mode;
108
+ if ((mode & 73) === 0) {
109
+ chmodSync(path, mode | 73);
110
+ }
111
+ }
112
+ function defaultRuntimeCacheRoot(platform = process.platform, home = homedir(), environment = process.env) {
113
+ const cacheDirectory = platform === "win32" ? environment.LOCALAPPDATA ?? join(home, "AppData", "Local") : platform === "darwin" ? join(home, "Library", "Caches") : environment.XDG_CACHE_HOME ?? join(home, ".cache");
114
+ return join(cacheDirectory, "copilot-sdk", "runtime");
115
+ }
116
+ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot(), cacheKey = `${sources.platform}-${sourceFingerprint(collectRuntimeAssets(sources))}`) {
117
+ const assets = collectRuntimeAssets(sources);
118
+ const wrapperName = sources.platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
119
+ const prebuildDir = join("prebuilds", sources.platform);
120
+ const wrapperRelative = join(prebuildDir, wrapperName);
121
+ const runtimeNodeRelative = join(prebuildDir, "runtime.node");
122
+ const sourceWrapper = assets.find((asset) => asset.relativePath === wrapperRelative)?.source;
123
+ const sourceRuntimeNode = assets.find(
124
+ (asset) => asset.relativePath === runtimeNodeRelative
125
+ )?.source;
126
+ validateRuntimeBundle(sourceWrapper ?? "", sourceRuntimeNode ?? "");
127
+ const installDir = join(cacheRoot, cacheKey);
128
+ const installedWrapper = join(installDir, wrapperRelative);
129
+ const installedRuntimeNode = join(installDir, runtimeNodeRelative);
130
+ if (existsSync(installDir)) {
131
+ validateRuntimeBundle(installedWrapper, installedRuntimeNode);
132
+ makeExecutable(installedWrapper);
133
+ return installedWrapper;
134
+ }
135
+ mkdirSync(cacheRoot, { recursive: true });
136
+ const stagingDir = mkdtempSync(join(cacheRoot, ".runtime-"));
137
+ try {
138
+ for (const asset of assets) {
139
+ const destination = join(stagingDir, asset.relativePath);
140
+ mkdirSync(dirname(destination), { recursive: true });
141
+ copyFileSync(asset.source, destination);
142
+ }
143
+ const stagedWrapper = join(stagingDir, wrapperRelative);
144
+ makeExecutable(stagedWrapper);
145
+ renameSync(stagingDir, installDir);
146
+ } catch (error) {
147
+ if (!existsSync(installDir)) {
148
+ throw error;
149
+ }
150
+ validateRuntimeBundle(installedWrapper, installedRuntimeNode);
151
+ } finally {
152
+ rmSync(stagingDir, { recursive: true, force: true });
153
+ }
154
+ return installedWrapper;
155
+ }
156
+ function isMusl() {
157
+ if (process.platform !== "linux") {
158
+ return false;
159
+ }
160
+ const report = process.report?.getReport();
161
+ return report?.header?.glibcVersionRuntime === void 0;
162
+ }
163
+ function getRuntimePlatform(platform = process.platform, arch = process.arch, musl = isMusl()) {
164
+ if (arch !== "x64" && arch !== "arm64") {
165
+ throw new Error(`Unsupported Copilot CLI architecture: ${arch}.`);
166
+ }
167
+ if (platform === "linux") {
168
+ return `${musl ? "linuxmusl" : "linux"}-${arch}`;
169
+ }
170
+ if (platform === "darwin" || platform === "win32") {
171
+ return `${platform}-${arch}`;
172
+ }
173
+ throw new Error(`Unsupported Copilot CLI platform: ${platform}-${arch}.`);
174
+ }
175
+ function getRuntimeReleaseAssetName(version, platform) {
176
+ return `github-copilot-${version}-${platform}.tgz`;
177
+ }
178
+ function getRuntimePackageName(platform) {
179
+ return `@microsoft/copilot-sdk-${platform}`;
180
+ }
181
+ function resolvePackageRoot(packageName, searchPaths = require2.resolve.paths(packageName) ?? []) {
182
+ return searchPaths.map((base) => join(base, ...packageName.split("/"))).find((candidate) => existsSync(join(candidate, "package.json")));
183
+ }
184
+ async function ensureRuntimeBundle(version, options = {}) {
185
+ const platform = options.platform ?? getRuntimePlatform();
186
+ if (COPILOT_CLI_USE_NPM_PACKAGE) {
187
+ const packageName2 = `@github/copilot-${platform}`;
188
+ const packageRoot2 = resolvePackageRoot(packageName2, options.packageSearchPaths);
189
+ if (!packageRoot2) {
190
+ throw new Error(`Could not resolve ${packageName2} for Copilot CLI ${version}.`);
191
+ }
192
+ validateFile(
193
+ join(packageRoot2, "prebuilds", platform, "runtime.node"),
194
+ "Copilot runtime.node"
195
+ );
196
+ return materializeRuntimeBundle(
197
+ { packageRoot: packageRoot2, platform },
198
+ options.cacheRoot,
199
+ `${version}-${platform}`
200
+ );
201
+ }
202
+ const packageName = getRuntimePackageName(platform);
203
+ const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);
204
+ if (!packageRoot) {
205
+ throw new Error(
206
+ `Could not resolve ${packageName}. Reinstall @microsoft/copilot-sdk so its platform package is installed.`
207
+ );
208
+ }
209
+ const wrapperName = platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
210
+ const prebuildDir = join(packageRoot, "prebuilds", platform);
211
+ const wrapper = join(prebuildDir, wrapperName);
212
+ try {
213
+ validateRuntimeBundle(wrapper, join(prebuildDir, "runtime.node"));
214
+ } catch (error) {
215
+ throw new Error(
216
+ `${packageName} is missing required Copilot CLI runtime files. Reinstall @microsoft/copilot-sdk.`,
217
+ { cause: error }
218
+ );
219
+ }
220
+ makeExecutable(wrapper);
221
+ return wrapper;
222
+ }
223
+ export {
224
+ RUNTIME_PLATFORMS,
225
+ defaultRuntimeCacheRoot,
226
+ ensureRuntimeBundle,
227
+ getRuntimePackageName,
228
+ getRuntimePlatform,
229
+ getRuntimeReleaseAssetName,
230
+ materializeRuntimeBundle,
231
+ resolvePackageRoot,
232
+ validateFile
233
+ };
@@ -0,0 +1,4 @@
1
+ import type { ResponseSchema, ZodSchema } from "./types.js";
2
+ export declare function isZodSchema(value: unknown): value is ZodSchema;
3
+ export declare function toJsonSchema(schema: ZodSchema | Record<string, unknown> | undefined): Record<string, unknown> | undefined;
4
+ export declare function isResponseSchema(value: unknown): value is ResponseSchema;
package/dist/schema.js ADDED
@@ -0,0 +1,14 @@
1
+ function isZodSchema(value) {
2
+ return typeof value === "object" && value !== null && "toJSONSchema" in value && typeof value.toJSONSchema === "function";
3
+ }
4
+ function toJsonSchema(schema) {
5
+ return isZodSchema(schema) ? schema.toJSONSchema() : schema;
6
+ }
7
+ function isResponseSchema(value) {
8
+ return isZodSchema(value) && "parse" in value && typeof value.parse === "function";
9
+ }
10
+ export {
11
+ isResponseSchema,
12
+ isZodSchema,
13
+ toJsonSchema
14
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The SDK protocol version.
3
+ * This must match the version expected by the Copilot runtime server.
4
+ */
5
+ export declare const SDK_PROTOCOL_VERSION = 3;
6
+ /**
7
+ * Gets the SDK protocol version.
8
+ * @returns The protocol version number
9
+ */
10
+ export declare function getSdkProtocolVersion(): number;
@@ -0,0 +1,8 @@
1
+ const SDK_PROTOCOL_VERSION = 3;
2
+ function getSdkProtocolVersion() {
3
+ return SDK_PROTOCOL_VERSION;
4
+ }
5
+ export {
6
+ SDK_PROTOCOL_VERSION,
7
+ getSdkProtocolVersion
8
+ };