# Complete web SDK integration

Public setup guide: https://www.smart365guide.com/asdk/integration

## 1. Register and enable the application

Sign in to the company portal, register the application in **Applications**, and
set its allowed host/domain. Install on staging first. Keep the application active
and have the platform owner enable the required company/application feature
package. **Guide** and **Agent integration** are required for ASDK paths. Browser
configuration cannot grant a feature that the server package disables.

Use the generated browser SDK license. It is an application credential, not a user
password, server secret or delegated agent key. Never embed provider credentials,
`S365_NETWORK_KEY`, OAuth access/refresh tokens or account passwords.

## 2. Install once per document

Recommended npm integration (the current SDK, separate from the legacy local
`@smart365guide/sdk-web` used by old demos):

```sh
npm install @smart365guide/asdk
```

```js
import { init } from '@smart365guide/asdk';
const guide = init({ licenseKey: 'YOUR_BROWSER_SDK_LICENSE' });
await guide.ready;
```

React/Next.js can mount one client component in the application layout:

```tsx
'use client';
import { Smart365Guide } from '@smart365guide/asdk/react';
export default function Guide() {
  return <Smart365Guide licenseKey="YOUR_BROWSER_SDK_LICENSE" />;
}
```

The component initializes after mount and destroys its instance on unmount. It
supports React Strict Mode and language changes without restarting conversations.
Imports are safe for SSR; explicit `init()` must run in a browser after mount.
No separate stylesheet or script tag is needed. The package includes all avatar
assets, language files and their source/license notices. Default assets load from
the service. To serve the included assets yourself, run `npx smart365guide-assets`
and set `assetBaseUrl: '/smart365guide'` (the default copy directory is
`public/smart365guide`). API and built-in locale requests still use the service.
Re-run the copy after upgrading. See the package README for props and cleanup.

For non-bundled sites, use this alternative HTML embed instead:

```html
<script
  src="https://www.smart365guide.com/sdk/smart365guide.js"
  async
  data-license-key="YOUR_APPLICATION_SDK_LICENSE"
  data-endpoint="https://www.smart365guide.com"
  data-language="fr"
></script>
```

Omit `data-language` to use the host document's language. Set `<html lang="fr">`
and the host direction where appropriate. Use the generated active license and
allow every deployed hostname; a localhost registration does not cover production.

For Next.js, load once from the application layout with `next/script` and
`strategy="afterInteractive"`, passing the same `data-*` attributes. Keep SDK
initialization in the browser. In other React/SPAs, use the application shell or
a client-side script-load callback, not a script inserted on every component
render. A full-page navigation needs the script again in the new document; the
SDK observes supported same-document navigation. Verify your router in staging.

For explicit JavaScript configuration, load the bundle without a `data-license-key`
auto-initializer, then run this from its load callback:

```js
const guide = Smart365Guide.init({
  licenseKey: "YOUR_APPLICATION_SDK_LICENSE",
  endpoint: "https://www.smart365guide.com",
  language: "fr-CA"
});
// On deliberate unmount of an embedded application:
// guide.destroy();
```

`init()` replaces an existing instance. Use one initialization method and keep a
reference if you need teardown. Voice requires browser support and user permission;
typing remains available. Native iOS/Android/desktop UI is not covered merely by
installing a JavaScript bundle. A webview must expose the necessary browser APIs.

## 3. Network and Content Security Policy

Allow the configured service origin for the SDK script and API requests. Depending
on the enabled avatar/media features, its image and iframe origins are needed too.
Merge these destinations into the host's existing `script-src`, `connect-src`,
`img-src` and `frame-src` directives; do not replace the policy with a broad wildcard.

The current widget constructs inline styles. A strict style policy requires a
reviewed host-specific integration; there is no general SDK style-nonce option
claimed here. A page can load the script yet block its style or frame resources.
Inspect the exact blocked directive before changing policy. Never disable TLS or
cross-origin security to make an integration pass.

SDK requests are authenticated against the registered application and allowed
origin. A customer frontend cannot supply arbitrary tenant IDs to obtain another
company's data. A 403 may indicate domain, package or application-status denial.

## 4. Teach and publish a workflow

1. Open **Workflows → Record**, select the registered application and starting URL.
2. Start capture and perform the task in the opened application tab. Install the
   current SDK on each relevant page. Pause capture for unrelated/private work.
3. Finish and review the captured routes, selectors, required fields, constraints
   and dropdown options. Fix inaccuracies before saving/publishing.
4. Publish the reviewed workflow. Drafts are not exposed to agents. Enable its
   automation setting only when the owner approves autonomous following.
5. Test with the actual host account/role. A published path or automation flag is
   not user consent, account access or permission to submit a payment.

See `WORKFLOW-CAPTURE.md` in the downloaded bundle or
[dynamic workflow learning](dynamic-workflow-learning.md). Private controls and
entered values are excluded from reusable workflow learning. Mark sensitive
regions with `data-smart365-private`; review the separate SDK knowledge settings
before enabling structural observations. Cookie contents and unrestricted network
response capture are not part of the knowledge contract.

## 5. Use browser guidance or connect an MCP client

An agent with authorized browser controls can read:

```js
const matches = await Smart365Guide.getASDKContext({ goal: "invite a teammate" });
const path = await Smart365Guide.getASDKContext({ workflowId: "PUBLISHED_WORKFLOW_ID" });
const fields = await Smart365Guide.getFormFields();
```

Follow `nextOffset`, `nextStepOffset` and omitted-option pagination where present.
The response has `executed: false`. The agent must validate the live page, use
authorized controls and check the saved result. An ordinary website text fetch
does not gain browser control by finding these instructions.

For ChatGPT, Claude, Codex, Qwen and other tool-capable clients, use
[MCP client setup](mcp-clients.md). OAuth grants are read-only and selected-app
scoped. Delegated Network keys have the existing account/company boundary and
can expose backend tools; their actual actions retain provider grants and checks.

Backend execution needs an explicitly reviewed REST/MCP provider action, user
grants, policy and approval rules, idempotency keys and independent result checks.
Browser guidance alone does not create this backend integration.

## 6. Appearance, features and analytics

Company administrators configure the companion's name, avatar, appearance and
available experience in the portal, within their platform-assigned package. The
browser embed is not a feature-entitlement override. Use company-owned staging
data to test form assistance, validation expressions and workflow suggestions.

SDK Analysis, heatmaps, navigation and presence describe recorded SDK activity.
Browser IDs represent observed sessions/devices, not independently verified people.
Registered agent credentials identify granted access, not proof of model-vendor
identity. The platform does not observe every external bot or bypass request.

## Live website translation and versioned context

Enable the company features and opt-in application policy in **SDK knowledge**,
mark public copy with `data-smart365-translate`, and give important screen controls
stable `data-smart365-knowledge` IDs. The SDK can translate eligible host text,
accept explicit voice language commands and retain structural observations.
See the [live site guide](live-site-guide.md) for dictionaries, provider boundaries,
privacy, revision retention and the separate observed-context MCP tool.

## 7. Language, discovery and deployment verification

Read [language support](language-support.md) for catalog coverage, regional speech,
owner-supplied language packs, workflow translations and fallback behavior.

Copy the downloaded `site-discovery/.well-known/asdk.json` and `llms.txt` to their
exact paths on the customer's own origin, merging existing files. Include the
shipped initial HTML links. The browser script cannot create server routes, and
discovery documents must never contain keys, private records or workflows.

Before production, verify script loading, allowed-origin initialization, a reviewed
published path, required roles, validation behavior, selected language, a separate
saved-state check and key/OAuth revocation. Test the actual client and browser you
intend to support. No native vendor login or universal browser/voice support is
implied by a successful protocol test.

## Downloaded package contents

`smart365guide-web-sdk.zip` contains the browser bundle, locale files/status,
avatar assets, discovery files, this manual, the MCP/language manuals, workflow
capture guidance, the server agent package and integrity manifest. Install the
local server package with `npm install ./server-agent`; it remains a separate local
package. The browser ASDK is published as `@smart365guide/asdk` and has its own install and release lifecycle. No live credentials are
included. The bridge needs Node.js 20+ and its MCP SDK dependency.
