PHP code example of vested-ai / connector-sdk-php

1. Go to this page and download the library: Download vested-ai/connector-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vested-ai / connector-sdk-php example snippets



// src/Orders/OrdersAgent.php
namespace MyApp\Orders;

use Vested\Connect\Sdk\Attribute\{Agent, Model, Instruction};

#[Agent(key: 'myapp.orders', name: 'Orders')]
#[Model(provider: 'openai', name: 'gpt-4o')]
#[Instruction(type: 'system', position: 0, body: 'You help users look up their orders.')]
class OrdersAgent {}


// src/Orders/GetOrder.php
namespace MyApp\Orders;

use Vested\Connect\Sdk\Attribute\Tool;
use Vested\Connect\Sdk\Tool\{ToolHandler, ToolContext};

#[Tool(
    agentKey:     'myapp.orders',
    key:          'myapp.orders.get',
    name:         'Get order',
    description:  'Returns an order by ID.',
    inputSchema:  ['type' => 'object', 'properties' => ['id' => ['type' => 'string']], '


// bootstrap.php — must RETURN a ConnectorApp
orApp::create()
    ->scanNamespace('MyApp\\Orders', __DIR__ . '/src/Orders')
    ->build();


// src/Erp/ErpCredentials.php
namespace MyApp\Erp;

use Vested\Connect\Sdk\Attribute\{CredentialField, CredentialSchema};
use Vested\Connect\Sdk\Credential\{CredentialContext, CredentialValidation, UserCredentialHandler};

#[CredentialSchema(kind: 'basic', title: 'Al-Saif ERP account')]
#[CredentialField(key: 'username', label: 'ERP username', type: 'text',     ['username'], $credential['password']);

        return $who === null
            ? CredentialValidation::failed('ERP rejected those credentials.')
            : CredentialValidation::ok(['account' => $who->login]);
    }

    // Optional: tear down a remote session. Best-effort.
    public function revoke(CredentialContext $ctx, array $credential): void {}
}

$app->withCredentialHandler(new ErpCredentials($erp));


// src/Magento/MagentoSchemaProvider.php
namespace MyApp\Magento;

use PDO;
use Vested\Connect\Sdk\Attribute\RelationalSource;
use Vested\Connect\Sdk\Schema\{CanonicalSchema, RelationalSchemaProvider};

#[RelationalSource(
    engine:       'mysql',
    describeTool: 'magento.describe_schema',  // a ROWSET tool you declare
    queryTool:    'magento.query_sql',        // the free-form SQL tool
    sqlArg:       'sql',                      // its SQL argument, wire-exact
    paramsArg:    'params',                   // its bind-parameters argument, wire-exact (optional)
)]
final class MagentoSchemaProvider implements RelationalSchemaProvider
{
    public function __construct(private readonly PDO $pdo) {}

    /** @return string[] the scopes (databases) this source exposes */
    public function scopes(): array { /* … */ }

    public function describe(string $scopeKey): CanonicalSchema { /* … */ }

    public function catalogFingerprint(): string { /* … */ }
}

$app->withRelationalSchemaProvider(new MagentoSchemaProvider($pdo));

#[RelationalSource(
    engine:       'mysql',
    describeTool: 'erp.describe_schema',
    queryTool:    'erp.query_sql',
    sqlArg:       'sql',
    defaultScope: 'production',
)]
final class ErpSchemaProvider implements RelationalSchemaProvider
{
    public function scopes(): array
    {
        return ['production', 'erp_middleware_production'];
    }

    // …
}
bash
docker pull vestedai/vested-ai-connector-sdk-php:0.9.0
bash
VESTED_CONNECTOR_TOKEN=eyJ… VESTED_CONNECTOR_HUB=hub.example.com:4443 \
vendor/bin/vested-connect worker --bootstrap=./bootstrap.php