@yourgpt/copilot-sdk 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,30 +1,40 @@
1
1
  # @yourgpt/copilot-sdk
2
2
 
3
- Build AI copilots with app context awareness.
3
+ Build AI Copilots for Your Product.
4
+
5
+ Production-ready AI Copilots for any product. Connect any LLM, deploy on your infrastructure, own your data.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
- npm install @yourgpt/copilot-sdk
10
+ npm install @yourgpt/copilot-sdk @yourgpt/llm-sdk
9
11
  ```
10
12
 
11
- ## Usage
13
+ ## Quick Start
12
14
 
13
15
  ```tsx
14
- // React hooks & provider
15
- import {
16
- CopilotProvider,
17
- useTools,
18
- useAIContext,
19
- } from "@yourgpt/copilot-sdk/react";
20
-
21
- // UI components
16
+ import { CopilotProvider } from "@yourgpt/copilot-sdk/react";
22
17
  import { CopilotChat } from "@yourgpt/copilot-sdk/ui";
23
-
24
- // Core types and utilities
25
- import { tool, success, type ToolDefinition } from "@yourgpt/copilot-sdk/core";
18
+ import "@yourgpt/copilot-sdk/ui/styles.css";
19
+
20
+ function App() {
21
+ return (
22
+ <CopilotProvider runtimeUrl="/api/chat">
23
+ <YourApp />
24
+ <CopilotChat />
25
+ </CopilotProvider>
26
+ );
27
+ }
26
28
  ```
27
29
 
30
+ ## Subpath Exports
31
+
32
+ | Subpath | Description |
33
+ | -------- | ------------------------------ |
34
+ | `/react` | React hooks and provider |
35
+ | `/ui` | Pre-built UI components |
36
+ | `/core` | Types, utilities, tool helpers |
37
+
28
38
  ## Styling (Tailwind CSS v4)
29
39
 
30
40
  Add the SDK source to your Tailwind config:
@@ -44,17 +54,9 @@ For theming, optionally import the default CSS variables:
44
54
  @import "@yourgpt/copilot-sdk/ui/styles.css";
45
55
  ```
46
56
 
47
- ## Subpath Exports
48
-
49
- | Subpath | Description |
50
- | -------- | ------------------------------ |
51
- | `/core` | Types, utilities, tool helpers |
52
- | `/react` | React hooks and provider |
53
- | `/ui` | Pre-built UI components |
54
-
55
57
  ## Documentation
56
58
 
57
- Visit [https://copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)
59
+ Visit [copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)
58
60
 
59
61
  ## License
60
62
 
@@ -1,4 +1,4 @@
1
- import { isConsoleCaptureActive, startConsoleCapture, isNetworkCaptureActive, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, isScreenshotSupported, captureScreenshot, getConsoleLogs, getNetworkRequests, clearConsoleLogs, clearNetworkRequests, formatLogsForAI, formatRequestsForAI, detectIntent, streamSSE, zodObjectToInputSchema } from './chunk-N4OA2J32.js';
1
+ import { isConsoleCaptureActive, startConsoleCapture, isNetworkCaptureActive, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, isScreenshotSupported, captureScreenshot, getConsoleLogs, getNetworkRequests, clearConsoleLogs, clearNetworkRequests, formatLogsForAI, formatRequestsForAI, detectIntent, streamSSE, zodObjectToInputSchema } from './chunk-QWQELTEB.js';
2
2
  import { createContext, useContext, useCallback, useEffect, useState, useRef, useSyncExternalStore, useMemo } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
  import * as z from 'zod';
@@ -822,7 +822,7 @@ var AbstractAgentLoop = class {
822
822
  this._isProcessing = false;
823
823
  // Registered tools
824
824
  this.registeredTools = /* @__PURE__ */ new Map();
825
- // Pending approvals
825
+ // Pending approvals - resolve with approval result including extraData
826
826
  this.pendingApprovals = /* @__PURE__ */ new Map();
827
827
  this.config = config;
828
828
  this.callbacks = callbacks;
@@ -968,15 +968,18 @@ var AbstractAgentLoop = class {
968
968
  });
969
969
  return errorResult;
970
970
  }
971
+ let approvalData;
971
972
  if (tool.needsApproval && !this.config.autoApprove) {
972
- typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
973
+ const approvalMessage = typeof tool.approvalMessage === "function" ? tool.approvalMessage(toolCall.args) : tool.approvalMessage;
973
974
  execution.approvalStatus = "required";
975
+ execution.approvalMessage = approvalMessage;
974
976
  this.updateToolExecution(toolCall.id, {
975
- approvalStatus: "required"
977
+ approvalStatus: "required",
978
+ approvalMessage
976
979
  });
977
980
  this.callbacks.onApprovalRequired?.(execution);
978
- const approved = await this.waitForApproval(toolCall.id, execution);
979
- if (!approved) {
981
+ const approvalResult = await this.waitForApproval(toolCall.id, execution);
982
+ if (!approvalResult.approved) {
980
983
  const rejectedResult = {
981
984
  toolCallId: toolCall.id,
982
985
  success: false,
@@ -990,9 +993,7 @@ var AbstractAgentLoop = class {
990
993
  });
991
994
  return rejectedResult;
992
995
  }
993
- this.updateToolExecution(toolCall.id, {
994
- approvalStatus: "approved"
995
- });
996
+ approvalData = approvalResult.extraData;
996
997
  }
997
998
  this.updateToolExecution(toolCall.id, { status: "executing" });
998
999
  try {
@@ -1000,7 +1001,8 @@ var AbstractAgentLoop = class {
1000
1001
  throw new Error(`Tool "${toolCall.name}" has no handler`);
1001
1002
  }
1002
1003
  const result = await tool.handler(toolCall.args, {
1003
- data: { toolCallId: toolCall.id }
1004
+ data: { toolCallId: toolCall.id },
1005
+ approvalData
1004
1006
  });
1005
1007
  this.updateToolExecution(toolCall.id, {
1006
1008
  status: "completed",
@@ -1034,6 +1036,7 @@ var AbstractAgentLoop = class {
1034
1036
  }
1035
1037
  /**
1036
1038
  * Wait for user approval
1039
+ * Returns approval result with optional extraData from user's action
1037
1040
  */
1038
1041
  waitForApproval(executionId, execution) {
1039
1042
  return new Promise((resolve) => {
@@ -1044,13 +1047,17 @@ var AbstractAgentLoop = class {
1044
1047
  // Actions (implements AgentLoopActions)
1045
1048
  // ============================================
1046
1049
  /**
1047
- * Approve a tool execution
1050
+ * Approve a tool execution with optional extra data
1048
1051
  */
1049
- approveToolExecution(executionId, _permissionLevel) {
1052
+ approveToolExecution(executionId, extraData, _permissionLevel) {
1050
1053
  const pending = this.pendingApprovals.get(executionId);
1051
1054
  if (pending) {
1052
- pending.resolve(true);
1055
+ pending.resolve({ approved: true, extraData });
1053
1056
  this.pendingApprovals.delete(executionId);
1057
+ this.updateToolExecution(executionId, {
1058
+ approvalStatus: "approved",
1059
+ approvalData: extraData
1060
+ });
1054
1061
  }
1055
1062
  }
1056
1063
  /**
@@ -1064,7 +1071,7 @@ var AbstractAgentLoop = class {
1064
1071
  error: reason
1065
1072
  });
1066
1073
  }
1067
- pending.resolve(false);
1074
+ pending.resolve({ approved: false });
1068
1075
  this.pendingApprovals.delete(executionId);
1069
1076
  }
1070
1077
  }
@@ -1108,8 +1115,8 @@ var AbstractAgentLoop = class {
1108
1115
  * Dispose of resources
1109
1116
  */
1110
1117
  dispose() {
1111
- for (const [id, pending] of this.pendingApprovals) {
1112
- pending.resolve(false);
1118
+ for (const [_id, pending] of this.pendingApprovals) {
1119
+ pending.resolve({ approved: false });
1113
1120
  }
1114
1121
  this.pendingApprovals.clear();
1115
1122
  this.registeredTools.clear();
@@ -1299,10 +1306,10 @@ var ChatWithTools = class {
1299
1306
  // Tool Approval
1300
1307
  // ============================================
1301
1308
  /**
1302
- * Approve a tool execution
1309
+ * Approve a tool execution with optional extra data
1303
1310
  */
1304
- approveToolExecution(id, permissionLevel) {
1305
- this.agentLoop.approveToolExecution(id, permissionLevel);
1311
+ approveToolExecution(id, extraData, permissionLevel) {
1312
+ this.agentLoop.approveToolExecution(id, extraData, permissionLevel);
1306
1313
  }
1307
1314
  /**
1308
1315
  * Reject a tool execution
@@ -1645,8 +1652,8 @@ function CopilotProvider({
1645
1652
  chatRef.current?.unregisterTool(name);
1646
1653
  }, []);
1647
1654
  const approveToolExecution = useCallback(
1648
- (id, permissionLevel) => {
1649
- chatRef.current?.approveToolExecution(id, permissionLevel);
1655
+ (id, extraData, permissionLevel) => {
1656
+ chatRef.current?.approveToolExecution(id, extraData, permissionLevel);
1650
1657
  },
1651
1658
  []
1652
1659
  );
@@ -3096,5 +3103,5 @@ function useChat(config) {
3096
3103
  }
3097
3104
 
3098
3105
  export { AbstractAgentLoop, AbstractChat, CopilotProvider, ReactChat, ReactChatState, createPermissionStorage, createReactChat, createReactChatState, createSessionPermissionCache, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useSuggestions, useSupportedMediaTypes, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
3099
- //# sourceMappingURL=chunk-QUGTRQSS.js.map
3100
- //# sourceMappingURL=chunk-QUGTRQSS.js.map
3106
+ //# sourceMappingURL=chunk-FO75W5UI.js.map
3107
+ //# sourceMappingURL=chunk-FO75W5UI.js.map