@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,278 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var workflow_exports = {};
20
+ __export(workflow_exports, {
21
+ WORKFLOW_AGENT_OPTION_KEYS: () => WORKFLOW_AGENT_OPTION_KEYS,
22
+ WorkflowResumeError: () => WorkflowResumeError,
23
+ defineWorkflow: () => defineWorkflow,
24
+ getWorkflowAgentReference: () => getWorkflowAgentReference,
25
+ getWorkflowDefinition: () => getWorkflowDefinition,
26
+ getWorkflowRegistration: () => getWorkflowRegistration,
27
+ isWorkflowRunTerminal: () => isWorkflowRunTerminal
28
+ });
29
+ module.exports = __toCommonJS(workflow_exports);
30
+ var import_node_crypto = require("node:crypto");
31
+ const WORKFLOW_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
32
+ "completed",
33
+ "halted",
34
+ "paused",
35
+ "cancelled",
36
+ "error"
37
+ ]);
38
+ function isWorkflowRunTerminal(status) {
39
+ return WORKFLOW_TERMINAL_STATUSES.has(status);
40
+ }
41
+ const WORKFLOW_AGENT_OPTION_KEYS = [
42
+ "label",
43
+ "schema",
44
+ "model",
45
+ "reasoningEffort",
46
+ "contextTier",
47
+ "agent",
48
+ "timeoutSeconds"
49
+ ];
50
+ class WorkflowResumeError extends Error {
51
+ constructor(code, message) {
52
+ super(message);
53
+ this.code = code;
54
+ this.name = "WorkflowResumeError";
55
+ }
56
+ code;
57
+ }
58
+ const workflowHandles = /* @__PURE__ */ new WeakMap();
59
+ const workflowAgentReferences = /* @__PURE__ */ new WeakSet();
60
+ const MAX_WORKFLOW_TIMEOUT_SECONDS = 2147483647e-3;
61
+ const NANO_AIU_PER_AIU = 1e9;
62
+ function deepFreeze(value) {
63
+ if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
64
+ Object.freeze(value);
65
+ for (const nested of Object.values(value)) {
66
+ deepFreeze(nested);
67
+ }
68
+ }
69
+ return value;
70
+ }
71
+ function canonicalJson(value) {
72
+ const compareUtf8 = (left, right) => Buffer.compare(Buffer.from(left, "utf8"), Buffer.from(right, "utf8"));
73
+ const canonicalize = (nested) => {
74
+ if (Array.isArray(nested)) {
75
+ return nested.map(canonicalize);
76
+ }
77
+ if (nested !== null && typeof nested === "object") {
78
+ return Object.fromEntries(
79
+ Object.entries(nested).filter(([, child]) => child !== void 0).sort(([left], [right]) => compareUtf8(left, right)).map(([key, child]) => [key, canonicalize(child)])
80
+ );
81
+ }
82
+ return nested;
83
+ };
84
+ return JSON.stringify(canonicalize(value));
85
+ }
86
+ function sha256(value) {
87
+ return (0, import_node_crypto.createHash)("sha256").update(value, "utf8").digest("hex");
88
+ }
89
+ function validateRequiredWorkflowAgentString(value, field) {
90
+ if (typeof value !== "string" || value.trim().length === 0) {
91
+ throw new Error(`Workflow agent "${field}" must not be empty`);
92
+ }
93
+ }
94
+ function validateOptionalWorkflowAgentString(value, field) {
95
+ if (value !== void 0 && (typeof value !== "string" || value.trim().length === 0)) {
96
+ throw new Error(`Workflow agent "${field}" must be a non-empty string when provided`);
97
+ }
98
+ }
99
+ function normalizeWorkflowAgent(config) {
100
+ if (config === null || typeof config !== "object" || Array.isArray(config)) {
101
+ throw new Error("Workflow agent configuration must be an object");
102
+ }
103
+ const allowed = /* @__PURE__ */ new Set(["name", "displayName", "description", "prompt", "tools", "infer"]);
104
+ for (const field of Object.keys(config)) {
105
+ if (!allowed.has(field)) {
106
+ throw new Error(`Workflow agent field "${field}" is not supported`);
107
+ }
108
+ }
109
+ validateRequiredWorkflowAgentString(config.name, "name");
110
+ validateRequiredWorkflowAgentString(config.prompt, "prompt");
111
+ validateOptionalWorkflowAgentString(config.displayName, "displayName");
112
+ validateOptionalWorkflowAgentString(config.description, "description");
113
+ if (config.infer !== false) {
114
+ throw new Error('Workflow agent "infer" must be false');
115
+ }
116
+ if (config.tools !== void 0 && (!Array.isArray(config.tools) || config.tools.length !== 0)) {
117
+ throw new Error("Workflow agents must not declare tools");
118
+ }
119
+ return deepFreeze({
120
+ name: config.name,
121
+ ...config.displayName !== void 0 ? { displayName: config.displayName } : {},
122
+ ...config.description !== void 0 ? { description: config.description } : {},
123
+ prompt: config.prompt,
124
+ tools: [],
125
+ infer: false
126
+ });
127
+ }
128
+ function workflowRegistration(meta, agents) {
129
+ if (agents === void 0) {
130
+ return {
131
+ registration: meta,
132
+ agents: Object.freeze({}),
133
+ agentReferences: /* @__PURE__ */ new Map()
134
+ };
135
+ }
136
+ if (agents === null || typeof agents !== "object" || Array.isArray(agents)) {
137
+ throw new Error("Workflow agents must be a named object map");
138
+ }
139
+ const definitions = Object.entries(agents).map(([key, config]) => {
140
+ if (key.trim().length === 0) {
141
+ throw new Error("Workflow agent map keys must not be empty");
142
+ }
143
+ const definition = normalizeWorkflowAgent(config);
144
+ const reference = Object.freeze({});
145
+ workflowAgentReferences.add(reference);
146
+ return { key, reference, definition };
147
+ });
148
+ if (definitions.length === 0) {
149
+ return {
150
+ registration: meta,
151
+ agents: Object.freeze({}),
152
+ agentReferences: /* @__PURE__ */ new Map()
153
+ };
154
+ }
155
+ const names = /* @__PURE__ */ new Set();
156
+ for (const { definition } of definitions) {
157
+ if (names.has(definition.name)) {
158
+ throw new Error(`Workflow agent "${definition.name}" is declared more than once`);
159
+ }
160
+ names.add(definition.name);
161
+ }
162
+ definitions.sort(
163
+ (left, right) => Buffer.compare(
164
+ Buffer.from(left.definition.name, "utf8"),
165
+ Buffer.from(right.definition.name, "utf8")
166
+ )
167
+ );
168
+ const roleDefinitionHash = sha256(
169
+ canonicalJson(definitions.map(({ definition }) => definition))
170
+ );
171
+ const agentReferences = /* @__PURE__ */ new Map();
172
+ const contextAgentEntries = [];
173
+ const privateRoles = definitions.map(({ key, reference: agentReference, definition }) => {
174
+ const wireReference = sha256(
175
+ `workflow-role\0${meta.name}\0${definition.name}\0${roleDefinitionHash}`
176
+ );
177
+ agentReferences.set(agentReference, wireReference);
178
+ contextAgentEntries.push([key, agentReference]);
179
+ return { reference: wireReference, ...definition };
180
+ });
181
+ return {
182
+ registration: deepFreeze({
183
+ ...meta,
184
+ privateRoles,
185
+ roleDefinitionHash
186
+ }),
187
+ agents: Object.freeze(Object.fromEntries(contextAgentEntries)),
188
+ agentReferences
189
+ };
190
+ }
191
+ function validateLimits(meta) {
192
+ const limits = meta.limits;
193
+ if (!limits) {
194
+ return;
195
+ }
196
+ for (const field of ["maxConcurrentSubagents", "maxTotalSubagents"]) {
197
+ const value = limits[field];
198
+ if (value !== void 0 && (!Number.isInteger(value) || value <= 0)) {
199
+ throw new Error(`Workflow limit "${field}" must be a positive integer`);
200
+ }
201
+ }
202
+ if (limits.timeoutSeconds !== void 0 && (!Number.isFinite(limits.timeoutSeconds) || limits.timeoutSeconds <= 0)) {
203
+ throw new Error(
204
+ 'Workflow limit "timeoutSeconds" must be a positive, finite number of seconds'
205
+ );
206
+ }
207
+ if (limits.timeoutSeconds !== void 0 && limits.timeoutSeconds > MAX_WORKFLOW_TIMEOUT_SECONDS) {
208
+ throw new Error(
209
+ `Workflow limit "timeoutSeconds" must not exceed ${MAX_WORKFLOW_TIMEOUT_SECONDS} seconds`
210
+ );
211
+ }
212
+ if (limits.maxAiCredits !== void 0) {
213
+ const maxNanoAiu = Math.round(limits.maxAiCredits * NANO_AIU_PER_AIU);
214
+ if (!Number.isFinite(limits.maxAiCredits) || limits.maxAiCredits <= 0 || !Number.isSafeInteger(maxNanoAiu) || maxNanoAiu < 1) {
215
+ throw new Error(
216
+ 'Workflow limit "maxAiCredits" must be a positive, finite number that rounds to a safe positive integer nano-AIU ceiling'
217
+ );
218
+ }
219
+ }
220
+ }
221
+ function validatePhases(meta) {
222
+ const titles = /* @__PURE__ */ new Set();
223
+ for (const phase of meta.phases) {
224
+ if (phase.title.trim().length === 0) {
225
+ throw new Error("Workflow phase titles must not be empty");
226
+ }
227
+ if (titles.has(phase.title)) {
228
+ throw new Error(`Workflow phase title "${phase.title}" is declared more than once`);
229
+ }
230
+ titles.add(phase.title);
231
+ }
232
+ }
233
+ function defineWorkflow(definition) {
234
+ const meta = deepFreeze(structuredClone(definition.meta));
235
+ validateLimits(meta);
236
+ validatePhases(meta);
237
+ const { registration, agents, agentReferences } = workflowRegistration(meta, definition.agents);
238
+ const stored = {
239
+ meta,
240
+ registration,
241
+ agents,
242
+ agentReferences,
243
+ run: definition.run
244
+ };
245
+ const handle = Object.freeze({ meta });
246
+ workflowHandles.set(handle, stored);
247
+ return handle;
248
+ }
249
+ function getWorkflowDefinition(handle) {
250
+ const definition = workflowHandles.get(handle);
251
+ if (!definition) {
252
+ throw new Error("Invalid workflow handle");
253
+ }
254
+ return definition;
255
+ }
256
+ function getWorkflowRegistration(handle) {
257
+ return getWorkflowDefinition(handle).registration;
258
+ }
259
+ function getWorkflowAgentReference(workflow, agent) {
260
+ if (!workflowAgentReferences.has(agent)) {
261
+ throw new Error("Invalid workflow agent reference");
262
+ }
263
+ const reference = workflow.agentReferences.get(agent);
264
+ if (!reference) {
265
+ throw new Error("Workflow agent reference is not declared by this workflow");
266
+ }
267
+ return reference;
268
+ }
269
+ // Annotate the CommonJS export names for ESM import in node:
270
+ 0 && (module.exports = {
271
+ WORKFLOW_AGENT_OPTION_KEYS,
272
+ WorkflowResumeError,
273
+ defineWorkflow,
274
+ getWorkflowAgentReference,
275
+ getWorkflowDefinition,
276
+ getWorkflowRegistration,
277
+ isWorkflowRunTerminal
278
+ });
@@ -0,0 +1,2 @@
1
+ export declare const COPILOT_CLI_VERSION = "1.0.106-9.unstable.r43755488033.g11df7b2";
2
+ export declare const COPILOT_CLI_USE_NPM_PACKAGE = false;
@@ -0,0 +1,6 @@
1
+ const COPILOT_CLI_VERSION = "1.0.106-9.unstable.r43755488033.g11df7b2";
2
+ const COPILOT_CLI_USE_NPM_PACKAGE = false;
3
+ export {
4
+ COPILOT_CLI_USE_NPM_PACKAGE,
5
+ COPILOT_CLI_VERSION
6
+ };