@databricks/ai-sdk-provider 0.3.0 → 0.4.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.
- package/README.md +0 -16
- package/dist/index.cjs +47 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -113
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -113
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +48 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -54,117 +54,5 @@ interface DatabricksProviderSettings {
|
|
|
54
54
|
}
|
|
55
55
|
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider;
|
|
56
56
|
//#endregion
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* MCP Approval Utility Functions
|
|
60
|
-
*
|
|
61
|
-
* Shared utilities for handling MCP (Model Context Protocol) approval requests
|
|
62
|
-
* and responses across client and server code.
|
|
63
|
-
*/
|
|
64
|
-
/** Key used in tool output to indicate approval status */
|
|
65
|
-
declare const MCP_APPROVAL_STATUS_KEY = "__approvalStatus__";
|
|
66
|
-
/** Type string for MCP approval requests in provider metadata */
|
|
67
|
-
declare const MCP_APPROVAL_REQUEST_TYPE = "mcp_approval_request";
|
|
68
|
-
/** Type string for MCP approval responses in provider metadata */
|
|
69
|
-
declare const MCP_APPROVAL_RESPONSE_TYPE = "mcp_approval_response";
|
|
70
|
-
/** Approval status output object shape */
|
|
71
|
-
type ApprovalStatusOutput = {
|
|
72
|
-
[MCP_APPROVAL_STATUS_KEY]: boolean;
|
|
73
|
-
};
|
|
74
|
-
/** State of an MCP approval request */
|
|
75
|
-
type McpApprovalState = 'awaiting-approval' | 'approved' | 'denied';
|
|
76
|
-
/** Databricks-specific metadata attached to tool calls */
|
|
77
|
-
interface DatabricksToolMetadata {
|
|
78
|
-
type?: string;
|
|
79
|
-
toolName?: string;
|
|
80
|
-
itemId?: string;
|
|
81
|
-
serverLabel?: string;
|
|
82
|
-
mcpServerName?: string;
|
|
83
|
-
approvalRequestId?: string;
|
|
84
|
-
approve?: boolean;
|
|
85
|
-
reason?: string;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check if output contains an approval status marker.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* if (isApprovalStatusOutput(output)) {
|
|
92
|
-
* console.log(output.__approvalStatus__); // TypeScript knows this is boolean
|
|
93
|
-
* }
|
|
94
|
-
*/
|
|
95
|
-
declare function isApprovalStatusOutput(output: unknown): output is ApprovalStatusOutput;
|
|
96
|
-
/**
|
|
97
|
-
* Check if provider metadata indicates an MCP approval request.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
101
|
-
* if (isMcpApprovalRequest(metadata)) {
|
|
102
|
-
* // Handle MCP approval request
|
|
103
|
-
* }
|
|
104
|
-
*/
|
|
105
|
-
declare function isMcpApprovalRequest(metadata: DatabricksToolMetadata | Record<string, unknown> | undefined): boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Check if provider metadata indicates an MCP approval response.
|
|
108
|
-
*/
|
|
109
|
-
declare function isMcpApprovalResponse(metadata: DatabricksToolMetadata | Record<string, unknown> | undefined): boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Extract Databricks metadata from a tool call part's callProviderMetadata.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
115
|
-
* const toolName = metadata?.toolName;
|
|
116
|
-
* const isMcp = isMcpApprovalRequest(metadata);
|
|
117
|
-
*/
|
|
118
|
-
declare function extractDatabricksMetadata(part: {
|
|
119
|
-
callProviderMetadata?: Record<string, unknown>;
|
|
120
|
-
}): DatabricksToolMetadata | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* Extract the approval status boolean from an output object.
|
|
123
|
-
*
|
|
124
|
-
* @returns `true` if approved, `false` if denied, `undefined` if not an approval output
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* const status = extractApprovalStatus(output);
|
|
128
|
-
* if (status !== undefined) {
|
|
129
|
-
* console.log(status ? 'Approved' : 'Denied');
|
|
130
|
-
* }
|
|
131
|
-
*/
|
|
132
|
-
declare function extractApprovalStatus(output: unknown): boolean | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* Extract approval status from a tool result's output value.
|
|
135
|
-
* Handles the nested structure where output.type === 'json' and value contains the status.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* const status = extractApprovalStatusFromToolResult(toolResult.output);
|
|
139
|
-
*/
|
|
140
|
-
declare function extractApprovalStatusFromToolResult(output: {
|
|
141
|
-
type: string;
|
|
142
|
-
value?: unknown;
|
|
143
|
-
}): boolean | undefined;
|
|
144
|
-
/**
|
|
145
|
-
* Create an approval status output object.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* await addToolResult({
|
|
149
|
-
* toolCallId,
|
|
150
|
-
* output: createApprovalStatusOutput(true), // Approve
|
|
151
|
-
* });
|
|
152
|
-
*/
|
|
153
|
-
declare function createApprovalStatusOutput(approve: boolean): ApprovalStatusOutput;
|
|
154
|
-
/**
|
|
155
|
-
* Determine the MCP approval state from a tool output.
|
|
156
|
-
*
|
|
157
|
-
* Logic:
|
|
158
|
-
* - No output → 'awaiting-approval' (user hasn't responded yet)
|
|
159
|
-
* - Output with __approvalStatus__: true → 'approved'
|
|
160
|
-
* - Output with __approvalStatus__: false → 'denied'
|
|
161
|
-
* - Output without __approvalStatus__ → 'approved' (tool executed, so it was approved)
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* const approvalState = getMcpApprovalState(part.output);
|
|
165
|
-
* // 'awaiting-approval' | 'approved' | 'denied'
|
|
166
|
-
*/
|
|
167
|
-
declare function getMcpApprovalState(output: unknown): McpApprovalState;
|
|
168
|
-
//#endregion
|
|
169
|
-
export { ApprovalStatusOutput, DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, DatabricksToolMetadata, MCP_APPROVAL_REQUEST_TYPE, MCP_APPROVAL_RESPONSE_TYPE, MCP_APPROVAL_STATUS_KEY, McpApprovalState, createApprovalStatusOutput, createDatabricksProvider, extractApprovalStatus, extractApprovalStatusFromToolResult, extractDatabricksMetadata, getMcpApprovalState, isApprovalStatusOutput, isMcpApprovalRequest, isMcpApprovalResponse };
|
|
57
|
+
export { DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, createDatabricksProvider };
|
|
170
58
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/databricks-provider.ts"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/databricks-provider.ts"],"mappings":";;;;KAMY,6BAAA;EACV,QAAA;EACA,OAAA,QAAe,MAAA;EACf,GAAA,GAAM,OAAA;IAAW,IAAA;EAAA;EACjB,KAAA,GAAQ,aAAA;EAFR;;;;;EAQA,oBAAA;AAAA;AAAA,UAGe,kBAAA,SAA2B,UAAA;EAHtB;EAKpB,SAAA,CAAU,OAAA,WAAkB,eAAA;EAC5B,SAAA,CAAU,OAAA,WAAkB,eAAA;EAHM;EAMlC,eAAA,CAAgB,OAAA,WAAkB,eAAA;EAJN;EAO5B,kBAAA,CAAmB,OAAA;EACnB,aAAA,CAAc,OAAA;AAAA;AAAA,UAGC,0BAAA;EAbqC;EAepD,OAAA;EAbA;EAeA,OAAA,GAAU,MAAA;EAfkB;EAiB5B,QAAA;EAhBU;;;;EAsBV,KAAA,GAAQ,aAAA;EAhBR;;;EAqBA,SAAA,IAAa,OAAA;IAAW,OAAA;IAAkB,IAAA;EAAA;EAjBD;;;;;EAwBzC,oBAAA;AAAA;AAAA,cAGW,wBAAA,GACX,QAAA,EAAU,0BAAA,KACT,kBAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -54,117 +54,5 @@ interface DatabricksProviderSettings {
|
|
|
54
54
|
}
|
|
55
55
|
declare const createDatabricksProvider: (settings: DatabricksProviderSettings) => DatabricksProvider;
|
|
56
56
|
//#endregion
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* MCP Approval Utility Functions
|
|
60
|
-
*
|
|
61
|
-
* Shared utilities for handling MCP (Model Context Protocol) approval requests
|
|
62
|
-
* and responses across client and server code.
|
|
63
|
-
*/
|
|
64
|
-
/** Key used in tool output to indicate approval status */
|
|
65
|
-
declare const MCP_APPROVAL_STATUS_KEY = "__approvalStatus__";
|
|
66
|
-
/** Type string for MCP approval requests in provider metadata */
|
|
67
|
-
declare const MCP_APPROVAL_REQUEST_TYPE = "mcp_approval_request";
|
|
68
|
-
/** Type string for MCP approval responses in provider metadata */
|
|
69
|
-
declare const MCP_APPROVAL_RESPONSE_TYPE = "mcp_approval_response";
|
|
70
|
-
/** Approval status output object shape */
|
|
71
|
-
type ApprovalStatusOutput = {
|
|
72
|
-
[MCP_APPROVAL_STATUS_KEY]: boolean;
|
|
73
|
-
};
|
|
74
|
-
/** State of an MCP approval request */
|
|
75
|
-
type McpApprovalState = 'awaiting-approval' | 'approved' | 'denied';
|
|
76
|
-
/** Databricks-specific metadata attached to tool calls */
|
|
77
|
-
interface DatabricksToolMetadata {
|
|
78
|
-
type?: string;
|
|
79
|
-
toolName?: string;
|
|
80
|
-
itemId?: string;
|
|
81
|
-
serverLabel?: string;
|
|
82
|
-
mcpServerName?: string;
|
|
83
|
-
approvalRequestId?: string;
|
|
84
|
-
approve?: boolean;
|
|
85
|
-
reason?: string;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check if output contains an approval status marker.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* if (isApprovalStatusOutput(output)) {
|
|
92
|
-
* console.log(output.__approvalStatus__); // TypeScript knows this is boolean
|
|
93
|
-
* }
|
|
94
|
-
*/
|
|
95
|
-
declare function isApprovalStatusOutput(output: unknown): output is ApprovalStatusOutput;
|
|
96
|
-
/**
|
|
97
|
-
* Check if provider metadata indicates an MCP approval request.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
101
|
-
* if (isMcpApprovalRequest(metadata)) {
|
|
102
|
-
* // Handle MCP approval request
|
|
103
|
-
* }
|
|
104
|
-
*/
|
|
105
|
-
declare function isMcpApprovalRequest(metadata: DatabricksToolMetadata | Record<string, unknown> | undefined): boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Check if provider metadata indicates an MCP approval response.
|
|
108
|
-
*/
|
|
109
|
-
declare function isMcpApprovalResponse(metadata: DatabricksToolMetadata | Record<string, unknown> | undefined): boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Extract Databricks metadata from a tool call part's callProviderMetadata.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
115
|
-
* const toolName = metadata?.toolName;
|
|
116
|
-
* const isMcp = isMcpApprovalRequest(metadata);
|
|
117
|
-
*/
|
|
118
|
-
declare function extractDatabricksMetadata(part: {
|
|
119
|
-
callProviderMetadata?: Record<string, unknown>;
|
|
120
|
-
}): DatabricksToolMetadata | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* Extract the approval status boolean from an output object.
|
|
123
|
-
*
|
|
124
|
-
* @returns `true` if approved, `false` if denied, `undefined` if not an approval output
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* const status = extractApprovalStatus(output);
|
|
128
|
-
* if (status !== undefined) {
|
|
129
|
-
* console.log(status ? 'Approved' : 'Denied');
|
|
130
|
-
* }
|
|
131
|
-
*/
|
|
132
|
-
declare function extractApprovalStatus(output: unknown): boolean | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* Extract approval status from a tool result's output value.
|
|
135
|
-
* Handles the nested structure where output.type === 'json' and value contains the status.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* const status = extractApprovalStatusFromToolResult(toolResult.output);
|
|
139
|
-
*/
|
|
140
|
-
declare function extractApprovalStatusFromToolResult(output: {
|
|
141
|
-
type: string;
|
|
142
|
-
value?: unknown;
|
|
143
|
-
}): boolean | undefined;
|
|
144
|
-
/**
|
|
145
|
-
* Create an approval status output object.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* await addToolResult({
|
|
149
|
-
* toolCallId,
|
|
150
|
-
* output: createApprovalStatusOutput(true), // Approve
|
|
151
|
-
* });
|
|
152
|
-
*/
|
|
153
|
-
declare function createApprovalStatusOutput(approve: boolean): ApprovalStatusOutput;
|
|
154
|
-
/**
|
|
155
|
-
* Determine the MCP approval state from a tool output.
|
|
156
|
-
*
|
|
157
|
-
* Logic:
|
|
158
|
-
* - No output → 'awaiting-approval' (user hasn't responded yet)
|
|
159
|
-
* - Output with __approvalStatus__: true → 'approved'
|
|
160
|
-
* - Output with __approvalStatus__: false → 'denied'
|
|
161
|
-
* - Output without __approvalStatus__ → 'approved' (tool executed, so it was approved)
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* const approvalState = getMcpApprovalState(part.output);
|
|
165
|
-
* // 'awaiting-approval' | 'approved' | 'denied'
|
|
166
|
-
*/
|
|
167
|
-
declare function getMcpApprovalState(output: unknown): McpApprovalState;
|
|
168
|
-
//#endregion
|
|
169
|
-
export { ApprovalStatusOutput, DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, DatabricksToolMetadata, MCP_APPROVAL_REQUEST_TYPE, MCP_APPROVAL_RESPONSE_TYPE, MCP_APPROVAL_STATUS_KEY, McpApprovalState, createApprovalStatusOutput, createDatabricksProvider, extractApprovalStatus, extractApprovalStatusFromToolResult, extractDatabricksMetadata, getMcpApprovalState, isApprovalStatusOutput, isMcpApprovalRequest, isMcpApprovalResponse };
|
|
57
|
+
export { DatabricksLanguageModelConfig, DatabricksProvider, DatabricksProviderSettings, createDatabricksProvider };
|
|
170
58
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/databricks-provider.ts"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/databricks-provider.ts"],"mappings":";;;;KAMY,6BAAA;EACV,QAAA;EACA,OAAA,QAAe,MAAA;EACf,GAAA,GAAM,OAAA;IAAW,IAAA;EAAA;EACjB,KAAA,GAAQ,aAAA;EAFR;;;;;EAQA,oBAAA;AAAA;AAAA,UAGe,kBAAA,SAA2B,UAAA;EAHtB;EAKpB,SAAA,CAAU,OAAA,WAAkB,eAAA;EAC5B,SAAA,CAAU,OAAA,WAAkB,eAAA;EAHM;EAMlC,eAAA,CAAgB,OAAA,WAAkB,eAAA;EAJN;EAO5B,kBAAA,CAAmB,OAAA;EACnB,aAAA,CAAc,OAAA;AAAA;AAAA,UAGC,0BAAA;EAbqC;EAepD,OAAA;EAbA;EAeA,OAAA,GAAU,MAAA;EAfkB;EAiB5B,QAAA;EAhBU;;;;EAsBV,KAAA,GAAQ,aAAA;EAhBR;;;EAqBA,SAAA,IAAa,OAAA;IAAW,OAAA;IAAkB,IAAA;EAAA;EAjBD;;;;;EAwBzC,oBAAA;AAAA;AAAA,cAGW,wBAAA,GACX,QAAA,EAAU,0BAAA,KACT,kBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -615,119 +615,6 @@ const responsesAgentChunkSchema = z.union([
|
|
|
615
615
|
*/
|
|
616
616
|
const looseResponseAgentChunkSchema = z.union([responsesAgentChunkSchema, z.object({ type: z.string() }).loose()]);
|
|
617
617
|
|
|
618
|
-
//#endregion
|
|
619
|
-
//#region src/mcp.ts
|
|
620
|
-
/**
|
|
621
|
-
* MCP Approval Utility Functions
|
|
622
|
-
*
|
|
623
|
-
* Shared utilities for handling MCP (Model Context Protocol) approval requests
|
|
624
|
-
* and responses across client and server code.
|
|
625
|
-
*/
|
|
626
|
-
/** Key used in tool output to indicate approval status */
|
|
627
|
-
const MCP_APPROVAL_STATUS_KEY = "__approvalStatus__";
|
|
628
|
-
/** Type string for MCP approval requests in provider metadata */
|
|
629
|
-
const MCP_APPROVAL_REQUEST_TYPE = "mcp_approval_request";
|
|
630
|
-
/** Type string for MCP approval responses in provider metadata */
|
|
631
|
-
const MCP_APPROVAL_RESPONSE_TYPE = "mcp_approval_response";
|
|
632
|
-
/**
|
|
633
|
-
* Check if output contains an approval status marker.
|
|
634
|
-
*
|
|
635
|
-
* @example
|
|
636
|
-
* if (isApprovalStatusOutput(output)) {
|
|
637
|
-
* console.log(output.__approvalStatus__); // TypeScript knows this is boolean
|
|
638
|
-
* }
|
|
639
|
-
*/
|
|
640
|
-
function isApprovalStatusOutput(output) {
|
|
641
|
-
return typeof output === "object" && output !== null && MCP_APPROVAL_STATUS_KEY in output && typeof output[MCP_APPROVAL_STATUS_KEY] === "boolean";
|
|
642
|
-
}
|
|
643
|
-
/**
|
|
644
|
-
* Check if provider metadata indicates an MCP approval request.
|
|
645
|
-
*
|
|
646
|
-
* @example
|
|
647
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
648
|
-
* if (isMcpApprovalRequest(metadata)) {
|
|
649
|
-
* // Handle MCP approval request
|
|
650
|
-
* }
|
|
651
|
-
*/
|
|
652
|
-
function isMcpApprovalRequest(metadata) {
|
|
653
|
-
return metadata?.type?.toString() === MCP_APPROVAL_REQUEST_TYPE;
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Check if provider metadata indicates an MCP approval response.
|
|
657
|
-
*/
|
|
658
|
-
function isMcpApprovalResponse(metadata) {
|
|
659
|
-
return metadata?.type?.toString() === MCP_APPROVAL_RESPONSE_TYPE;
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Extract Databricks metadata from a tool call part's callProviderMetadata.
|
|
663
|
-
*
|
|
664
|
-
* @example
|
|
665
|
-
* const metadata = extractDatabricksMetadata(part);
|
|
666
|
-
* const toolName = metadata?.toolName;
|
|
667
|
-
* const isMcp = isMcpApprovalRequest(metadata);
|
|
668
|
-
*/
|
|
669
|
-
function extractDatabricksMetadata(part) {
|
|
670
|
-
if ("callProviderMetadata" in part && part.callProviderMetadata?.databricks) return part.callProviderMetadata.databricks;
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Extract the approval status boolean from an output object.
|
|
674
|
-
*
|
|
675
|
-
* @returns `true` if approved, `false` if denied, `undefined` if not an approval output
|
|
676
|
-
*
|
|
677
|
-
* @example
|
|
678
|
-
* const status = extractApprovalStatus(output);
|
|
679
|
-
* if (status !== undefined) {
|
|
680
|
-
* console.log(status ? 'Approved' : 'Denied');
|
|
681
|
-
* }
|
|
682
|
-
*/
|
|
683
|
-
function extractApprovalStatus(output) {
|
|
684
|
-
if (isApprovalStatusOutput(output)) return output[MCP_APPROVAL_STATUS_KEY];
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Extract approval status from a tool result's output value.
|
|
688
|
-
* Handles the nested structure where output.type === 'json' and value contains the status.
|
|
689
|
-
*
|
|
690
|
-
* @example
|
|
691
|
-
* const status = extractApprovalStatusFromToolResult(toolResult.output);
|
|
692
|
-
*/
|
|
693
|
-
function extractApprovalStatusFromToolResult(output) {
|
|
694
|
-
if (output.type === "json" && output.value && typeof output.value === "object" && MCP_APPROVAL_STATUS_KEY in output.value) {
|
|
695
|
-
const value = output.value[MCP_APPROVAL_STATUS_KEY];
|
|
696
|
-
if (typeof value === "boolean") return value;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Create an approval status output object.
|
|
701
|
-
*
|
|
702
|
-
* @example
|
|
703
|
-
* await addToolResult({
|
|
704
|
-
* toolCallId,
|
|
705
|
-
* output: createApprovalStatusOutput(true), // Approve
|
|
706
|
-
* });
|
|
707
|
-
*/
|
|
708
|
-
function createApprovalStatusOutput(approve) {
|
|
709
|
-
return { [MCP_APPROVAL_STATUS_KEY]: approve };
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Determine the MCP approval state from a tool output.
|
|
713
|
-
*
|
|
714
|
-
* Logic:
|
|
715
|
-
* - No output → 'awaiting-approval' (user hasn't responded yet)
|
|
716
|
-
* - Output with __approvalStatus__: true → 'approved'
|
|
717
|
-
* - Output with __approvalStatus__: false → 'denied'
|
|
718
|
-
* - Output without __approvalStatus__ → 'approved' (tool executed, so it was approved)
|
|
719
|
-
*
|
|
720
|
-
* @example
|
|
721
|
-
* const approvalState = getMcpApprovalState(part.output);
|
|
722
|
-
* // 'awaiting-approval' | 'approved' | 'denied'
|
|
723
|
-
*/
|
|
724
|
-
function getMcpApprovalState(output) {
|
|
725
|
-
if (!output) return "awaiting-approval";
|
|
726
|
-
const status = extractApprovalStatus(output);
|
|
727
|
-
if (status === void 0) return "approved";
|
|
728
|
-
return status ? "approved" : "denied";
|
|
729
|
-
}
|
|
730
|
-
|
|
731
618
|
//#endregion
|
|
732
619
|
//#region src/responses-agent-language-model/responses-convert-to-message-parts.ts
|
|
733
620
|
const convertResponsesAgentChunkToMessagePart = (chunk, options = { useRemoteToolCalling: false }) => {
|
|
@@ -843,25 +730,24 @@ const convertOutputItemDone = (item, options) => {
|
|
|
843
730
|
toolCallId: item.id,
|
|
844
731
|
toolName: item.name,
|
|
845
732
|
input: item.arguments,
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
providerExecuted: true
|
|
849
|
-
},
|
|
733
|
+
providerExecuted: true,
|
|
734
|
+
dynamic: true,
|
|
850
735
|
providerMetadata: { databricks: {
|
|
851
|
-
type: MCP_APPROVAL_REQUEST_TYPE,
|
|
852
736
|
itemId: item.id,
|
|
853
|
-
serverLabel: item.server_label
|
|
737
|
+
serverLabel: item.server_label,
|
|
738
|
+
approvalRequestId: item.id
|
|
854
739
|
} }
|
|
740
|
+
}, {
|
|
741
|
+
type: "tool-approval-request",
|
|
742
|
+
approvalId: item.id,
|
|
743
|
+
toolCallId: item.id
|
|
855
744
|
}];
|
|
856
745
|
case "mcp_approval_response": return [{
|
|
857
746
|
type: "tool-result",
|
|
858
747
|
toolCallId: item.approval_request_id,
|
|
859
748
|
toolName: options.toolNamesByCallId?.get(item.approval_request_id) ?? "mcp_approval",
|
|
860
|
-
result:
|
|
861
|
-
providerMetadata: { databricks: {
|
|
862
|
-
type: MCP_APPROVAL_RESPONSE_TYPE,
|
|
863
|
-
...item.id != null && { itemId: item.id }
|
|
864
|
-
} }
|
|
749
|
+
result: { approved: item.approve },
|
|
750
|
+
providerMetadata: { databricks: { itemId: item.id ?? item.approval_request_id } }
|
|
865
751
|
}];
|
|
866
752
|
default: return [];
|
|
867
753
|
}
|
|
@@ -913,23 +799,27 @@ const convertResponsesAgentResponseToMessagePart = (response, options = { useRem
|
|
|
913
799
|
toolCallId: output.id,
|
|
914
800
|
toolName: output.name,
|
|
915
801
|
input: output.arguments,
|
|
802
|
+
providerExecuted: true,
|
|
803
|
+
dynamic: true,
|
|
916
804
|
providerMetadata: { databricks: {
|
|
917
|
-
type: MCP_APPROVAL_REQUEST_TYPE,
|
|
918
805
|
itemId: output.id,
|
|
919
|
-
serverLabel: output.server_label
|
|
806
|
+
serverLabel: output.server_label,
|
|
807
|
+
approvalRequestId: output.id
|
|
920
808
|
} }
|
|
921
809
|
});
|
|
810
|
+
parts.push({
|
|
811
|
+
type: "tool-approval-request",
|
|
812
|
+
approvalId: output.id,
|
|
813
|
+
toolCallId: output.id
|
|
814
|
+
});
|
|
922
815
|
break;
|
|
923
816
|
case "mcp_approval_response":
|
|
924
817
|
parts.push({
|
|
925
818
|
type: "tool-result",
|
|
926
819
|
toolCallId: output.approval_request_id,
|
|
927
820
|
toolName: toolNamesByCallId.get(output.approval_request_id) ?? "mcp_approval",
|
|
928
|
-
result:
|
|
929
|
-
providerMetadata: { databricks: {
|
|
930
|
-
type: MCP_APPROVAL_RESPONSE_TYPE,
|
|
931
|
-
...output.id != null && { itemId: output.id }
|
|
932
|
-
} }
|
|
821
|
+
result: { approved: output.approve },
|
|
822
|
+
providerMetadata: { databricks: { itemId: output.id ?? output.approval_request_id } }
|
|
933
823
|
});
|
|
934
824
|
break;
|
|
935
825
|
default: break;
|
|
@@ -942,6 +832,8 @@ const convertResponsesAgentResponseToMessagePart = (response, options = { useRem
|
|
|
942
832
|
async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
943
833
|
const input = [];
|
|
944
834
|
const warnings = [];
|
|
835
|
+
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
836
|
+
const approvalIdsWithToolResult = /* @__PURE__ */ new Set();
|
|
945
837
|
const toolCallResultsByToolCallId = prompt.filter((p) => p.role === "tool").flatMap((p) => p.content).reduce((reduction, toolCallResult) => {
|
|
946
838
|
if (toolCallResult.type === "tool-result") reduction[toolCallResult.toolCallId] = toolCallResult;
|
|
947
839
|
return reduction;
|
|
@@ -1008,37 +900,16 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
1008
900
|
break;
|
|
1009
901
|
case "tool-call": {
|
|
1010
902
|
const toolName = providerOptions?.toolName ?? part.toolName;
|
|
1011
|
-
|
|
903
|
+
const approvalRequestId = providerOptions?.approvalRequestId;
|
|
904
|
+
if (approvalRequestId) {
|
|
1012
905
|
const serverLabel = providerOptions?.serverLabel ?? "";
|
|
1013
|
-
const argumentsString = JSON.stringify(part.input);
|
|
1014
|
-
const id = part.toolCallId;
|
|
1015
906
|
input.push({
|
|
1016
|
-
type:
|
|
1017
|
-
id,
|
|
907
|
+
type: "mcp_approval_request",
|
|
908
|
+
id: approvalRequestId,
|
|
1018
909
|
name: toolName,
|
|
1019
|
-
arguments:
|
|
910
|
+
arguments: JSON.stringify(part.input),
|
|
1020
911
|
server_label: serverLabel
|
|
1021
912
|
});
|
|
1022
|
-
const toolResult = toolCallResultsByToolCallId[part.toolCallId];
|
|
1023
|
-
if (toolResult) {
|
|
1024
|
-
/**
|
|
1025
|
-
* The tool call result is either the approval status or the actual output from the tool call.
|
|
1026
|
-
* If it's the approval status, we need to add an approval response part.
|
|
1027
|
-
* If it's the tool call output, we don't include the approval response part but we do include the tool call output part.
|
|
1028
|
-
*/
|
|
1029
|
-
const approvalStatus = extractApprovalStatusFromToolResult(toolResult.output);
|
|
1030
|
-
if (approvalStatus !== void 0) input.push({
|
|
1031
|
-
type: MCP_APPROVAL_RESPONSE_TYPE,
|
|
1032
|
-
id: toolResult.toolCallId,
|
|
1033
|
-
approval_request_id: toolResult.toolCallId,
|
|
1034
|
-
approve: approvalStatus
|
|
1035
|
-
});
|
|
1036
|
-
else input.push({
|
|
1037
|
-
type: "function_call_output",
|
|
1038
|
-
call_id: toolResult.toolCallId,
|
|
1039
|
-
output: convertToolResultOutputToString(toolResult.output)
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
913
|
break;
|
|
1043
914
|
}
|
|
1044
915
|
input.push({
|
|
@@ -1057,24 +928,12 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
1057
928
|
break;
|
|
1058
929
|
}
|
|
1059
930
|
case "tool-result":
|
|
1060
|
-
if (providerOptions?.type === MCP_APPROVAL_RESPONSE_TYPE) {
|
|
1061
|
-
const approvalRequestId = providerOptions?.approvalRequestId ?? part.toolCallId;
|
|
1062
|
-
const approve = providerOptions?.approve ?? false;
|
|
1063
|
-
const reason = providerOptions?.reason ?? "";
|
|
1064
|
-
input.push({
|
|
1065
|
-
type: MCP_APPROVAL_RESPONSE_TYPE,
|
|
1066
|
-
id: approvalRequestId,
|
|
1067
|
-
approval_request_id: approvalRequestId,
|
|
1068
|
-
approve,
|
|
1069
|
-
reason
|
|
1070
|
-
});
|
|
1071
|
-
break;
|
|
1072
|
-
}
|
|
1073
931
|
input.push({
|
|
1074
932
|
type: "function_call_output",
|
|
1075
933
|
call_id: part.toolCallId,
|
|
1076
934
|
output: convertToolResultOutputToString(part.output)
|
|
1077
935
|
});
|
|
936
|
+
approvalIdsWithToolResult.add(part.toolCallId);
|
|
1078
937
|
break;
|
|
1079
938
|
case "reasoning":
|
|
1080
939
|
if (!itemId) break;
|
|
@@ -1090,7 +949,19 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
1090
949
|
}
|
|
1091
950
|
}
|
|
1092
951
|
break;
|
|
1093
|
-
case "tool":
|
|
952
|
+
case "tool":
|
|
953
|
+
for (const part of content) if (part.type === "tool-approval-response") {
|
|
954
|
+
if (processedApprovalIds.has(part.approvalId)) continue;
|
|
955
|
+
processedApprovalIds.add(part.approvalId);
|
|
956
|
+
if (approvalIdsWithToolResult.has(part.approvalId)) continue;
|
|
957
|
+
input.push({
|
|
958
|
+
type: "mcp_approval_response",
|
|
959
|
+
approval_request_id: part.approvalId,
|
|
960
|
+
approve: part.approved,
|
|
961
|
+
...part.reason && { reason: part.reason }
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
break;
|
|
1094
965
|
default: {
|
|
1095
966
|
const _exhaustiveCheck = role;
|
|
1096
967
|
throw new Error(`Unsupported role: ${String(_exhaustiveCheck)}`);
|
|
@@ -1104,11 +975,8 @@ async function convertToResponsesInput({ prompt, systemMessageMode }) {
|
|
|
1104
975
|
const ProviderOptionsSchema$1 = z.object({
|
|
1105
976
|
itemId: z.string().nullish(),
|
|
1106
977
|
toolName: z.string().nullish(),
|
|
1107
|
-
type: z.enum(["mcp_approval_request", "mcp_approval_response"]).nullish(),
|
|
1108
978
|
serverLabel: z.string().nullish(),
|
|
1109
|
-
approvalRequestId: z.string().nullish()
|
|
1110
|
-
approve: z.boolean().nullish(),
|
|
1111
|
-
reason: z.string().nullish()
|
|
979
|
+
approvalRequestId: z.string().nullish()
|
|
1112
980
|
});
|
|
1113
981
|
const convertToolResultOutputToString = (output) => {
|
|
1114
982
|
switch (output.type) {
|
|
@@ -1406,7 +1274,9 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1406
1274
|
type: "tool-call",
|
|
1407
1275
|
toolCallId: toolCallFromPreviousMessages.toolCallId,
|
|
1408
1276
|
toolName: toolCallFromPreviousMessages.toolName,
|
|
1409
|
-
input: JSON.stringify(toolCallFromPreviousMessages.input)
|
|
1277
|
+
input: JSON.stringify(toolCallFromPreviousMessages.input),
|
|
1278
|
+
providerExecuted: true,
|
|
1279
|
+
dynamic: true
|
|
1410
1280
|
});
|
|
1411
1281
|
}
|
|
1412
1282
|
}
|
|
@@ -1418,7 +1288,7 @@ var DatabricksResponsesAgentLanguageModel = class {
|
|
|
1418
1288
|
const toolCalls = allParts.filter((p) => p.type === "tool-call");
|
|
1419
1289
|
const toolResults = allParts.filter((p) => p.type === "tool-result");
|
|
1420
1290
|
for (const toolCall of toolCalls) {
|
|
1421
|
-
if (toolCall.providerMetadata?.databricks?.
|
|
1291
|
+
if (toolCall.providerMetadata?.databricks?.approvalRequestId != null) continue;
|
|
1422
1292
|
if (!toolResults.some((r) => r.toolCallId === toolCall.toolCallId)) controller.enqueue({
|
|
1423
1293
|
...toolCall,
|
|
1424
1294
|
providerExecuted: true,
|
|
@@ -2212,5 +2082,5 @@ const createDatabricksProvider = (settings) => {
|
|
|
2212
2082
|
};
|
|
2213
2083
|
|
|
2214
2084
|
//#endregion
|
|
2215
|
-
export {
|
|
2085
|
+
export { createDatabricksProvider };
|
|
2216
2086
|
//# sourceMappingURL=index.mjs.map
|