@@ -4,20 +4,17 @@ import (
44 "bytes"
55 "context"
66 "encoding/json"
7- "errors"
87 "fmt"
98 "io"
109 "net/http"
1110 "paperdebugger/internal/libs/db"
1211 "paperdebugger/internal/services"
13- "paperdebugger/internal/services/toolkit"
1412 toolCallRecordDB "paperdebugger/internal/services/toolkit/db"
1513 "time"
1614
1715 "github.com/openai/openai-go/v2"
1816 "github.com/openai/openai-go/v2/packages/param"
1917 "github.com/openai/openai-go/v2/responses"
20- "go.mongodb.org/mongo-driver/v2/mongo"
2118)
2219
2320// ToolSchema represents the schema from your backend
@@ -89,80 +86,9 @@ func NewDynamicTool(db *db.DB, projectService *services.ProjectService, toolSche
8986}
9087
9188// Call handles the tool execution (generic for any tool)
89+ // DEPRECATED: v1 API is no longer supported. This method should not be called.
9290func (t * DynamicTool ) Call (ctx context.Context , toolCallId string , args json.RawMessage ) (string , string , error ) {
93- // Parse arguments as generic map since we don't know the structure
94- var argsMap map [string ]interface {}
95- err := json .Unmarshal (args , & argsMap )
96- if err != nil {
97- return "" , "" , err
98- }
99-
100- // inject user/project context if required
101- if t .requiresInjection {
102- err := t .injectSecurityContext (ctx , argsMap )
103- if err != nil {
104- return "" , "" , fmt .Errorf ("security context injection failed: %w" , err )
105- }
106- }
107-
108- record , err := t .toolCallRecordDB .Create (ctx , toolCallId , t .Name , argsMap )
109- if err != nil {
110- return "" , "" , err
111- }
112-
113- // Execute the tool via MCP
114- respStr , err := t .executeTool (argsMap )
115- if err != nil {
116- err = fmt .Errorf ("failed to execute tool %s: %v" , t .Name , err )
117- t .toolCallRecordDB .OnError (ctx , record , err )
118- return "" , "" , err
119- }
120-
121- rawJson , err := json .Marshal (respStr )
122- if err != nil {
123- err = fmt .Errorf ("failed to marshal tool result: %v" , err )
124- t .toolCallRecordDB .OnError (ctx , record , err )
125- return "" , "" , err
126- }
127- t .toolCallRecordDB .OnSuccess (ctx , record , string (rawJson ))
128-
129- return respStr , "" , nil
130- }
131-
132- // extracts user/project from context and injects into arguments
133- func (t * DynamicTool ) injectSecurityContext (ctx context.Context , argsMap map [string ]interface {}) error {
134- // 1. Extract from context
135- actor , projectId , _ := toolkit .GetActorProjectConversationID (ctx )
136- if actor == nil || projectId == "" {
137- return fmt .Errorf ("authentication required: user context not found" )
138- }
139-
140- // 2. Validate user owns the project
141- _ , err := t .projectService .GetProject (ctx , actor .ID , projectId )
142- if err != nil {
143- if errors .Is (err , mongo .ErrNoDocuments ) {
144- return fmt .Errorf ("authorization failed: project not found or access denied" )
145- }
146- return fmt .Errorf ("authorization check failed: %w" , err )
147- }
148-
149- // 3. Check if tool schema expects these parameters
150- properties , ok := t .schema ["properties" ].(map [string ]interface {})
151- if ! ok {
152- return fmt .Errorf ("invalid tool schema: properties not found" )
153- }
154-
155- // 4. Inject user_id if expected by tool
156- if _ , hasUserId := properties ["user_id" ]; hasUserId {
157- argsMap ["user_id" ] = actor .ID .Hex ()
158- }
159-
160- // 5. Inject project_id if expected by tool
161- if _ , hasProjectId := properties ["project_id" ]; hasProjectId {
162- argsMap ["project_id" ] = projectId
163- }
164-
165- return nil
91+ return "" , "" , fmt .Errorf ("v1 API is deprecated and no longer supported. Please use v2 API instead" )
16692}
16793
16894// executeTool makes the MCP request (generic for any tool)
0 commit comments