@tangle-network/create-agent-app 0.60.160 → 0.60.162

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.
@@ -0,0 +1,33 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import { ApiAccessPanel, AgentSetupBlock, type ApiAccessKey } from '@tangle-network/agent-app/web-react'
3
+ import { json, post } from './api'
4
+
5
+ const access = [
6
+ { scope: 'operator:read', label: 'Read workspace', description: 'Read your conversations, task results, and pending owner decisions.' },
7
+ { scope: 'operator:run', label: 'Run agent work', description: 'Start work and modify your workspace using this deployment’s paid model and sandbox access. No finite spending cap is enforced on this lane.', requires: ['operator:read'] },
8
+ ]
9
+
10
+ export function ApiAccess() {
11
+ const [runEnabled, setRunEnabled] = useState(false)
12
+ const [keys, setKeys] = useState<ApiAccessKey[]>([])
13
+ const [error, setError] = useState<string | null>(null)
14
+ const refresh = useCallback(async () => {
15
+ try {
16
+ const [stored, policy] = await Promise.all([json<{ keys: ApiAccessKey[] }>('/api/keys'), json<{ operatorRunEnabled: boolean }>('/api/keys/access')])
17
+ setKeys(stored.keys); setRunEnabled(policy.operatorRunEnabled); setError(null)
18
+ }
19
+ catch (cause) { setError(cause instanceof Error ? cause.message : String(cause)) }
20
+ }, [])
21
+ useEffect(() => { void refresh() }, [refresh])
22
+ return <div className="h-full overflow-y-auto p-6">
23
+ <AgentSetupBlock productName={document.title} setupUrl={`${location.origin}/agent-setup.md`} description="Give your external agent the setup instructions. You sign in, issue or reuse an expiring key, and grant its scopes. The agent verifies access with that key; it cannot approve deployment spending for you." />
24
+ {error && <p role="alert" className="text-destructive">{error}</p>}
25
+ {!runEnabled && <p>External-agent execution is disabled until the deployment payer enables it. Read-only access remains available.</p>}
26
+ <ApiAccessPanel keys={keys} access={access.filter(item => item.scope !== 'operator:run' || runEnabled)} defaultScopes={['operator:read']} baseUrl={`${location.origin}/api/operator/v1`}
27
+ description="Give an external agent an expiring, revocable key to your personal workspace. Existing accounts and keys can be reused."
28
+ limitsDescription="Read-only is the default. Run access can incur provider charges and change workspace files. Review your budget before granting it. Human decisions remain in your browser."
29
+ onCreate={async ({ name, scopes, expiresAt }) => json('/api/keys', post({ name, scopes, expiresAt }))}
30
+ onRevoke={async id => { await json(`/api/keys/${encodeURIComponent(id)}`, { method: 'DELETE' }) }}
31
+ onChanged={() => void refresh()} />
32
+ </div>
33
+ }
@@ -1,14 +1,16 @@
1
1
  import { useCallback, useEffect, useState, type FormEvent } from 'react'
2
- import { CirclePlus, History } from 'lucide-react'
2
+ import { CirclePlus, History, KeyRound } from 'lucide-react'
3
3
  import { AgentWorkspaceCompanion, AgentWorkspaceLayout } from '@tangle-network/agent-app/workspace-react'
4
4
  import { SessionHistoryPanel, useSessionHistory, type FetchSessionPage } from '@tangle-network/agent-app/web-react'
5
5
  import type { SessionSort } from '@tangle-network/agent-app/session-shell'
6
+ import { ApiAccess } from './ApiAccess'
6
7
  import { Conversation } from './Conversation'
7
8
  import { workspaceTools } from './workspace-tools'
8
9
  import { historyHref, json, listThreads, post, threadHref, type Session, type Thread } from './api'
9
10
 
10
11
  const productName = document.title
11
12
  const initialThreadId = new URL(location.href).searchParams.get('threadId')
13
+ const showApiAccess = !initialThreadId && new URL(location.href).searchParams.get('view') === 'api-access'
12
14
  const showHistory = !initialThreadId && new URL(location.href).searchParams.get('view') === 'history'
13
15
 
14
16
  function Auth({ onAuthenticated }: { onAuthenticated: () => Promise<void> }) {
@@ -77,15 +79,15 @@ function Workspace({ session }: { session: Session }) {
77
79
  catch (cause) { setError(cause instanceof Error ? cause.message : String(cause)) }
78
80
  }
79
81
  return <AgentWorkspaceLayout
80
- navItems={[{ id: 'new', label: 'New thread', icon: CirclePlus, href: '/', variant: 'primary' }]}
82
+ navItems={[{ id: 'new', label: 'New thread', icon: CirclePlus, href: '/', variant: 'primary' }, { id: 'api-access', label: 'API access', icon: KeyRound, href: '/?view=api-access' }]}
81
83
  sessions={{ icon: History, href: historyHref, hrefForSession: threadHref, sessions: threads,
82
84
  totalCount: threads.length, activeSessionId: activeId }}
83
- activeId={showHistory ? 'history' : activeId ? undefined : 'new'}
85
+ activeId={showApiAccess ? 'api-access' : showHistory ? 'history' : activeId ? undefined : 'new'}
84
86
  logo={<span className="flex h-8 w-8 items-center justify-center rounded-lg bg-primary text-primary-foreground" title={productName}>{productName.slice(0, 1)}</span>}
85
87
  logoHref="/" user={session.user} settingsHref={null} onLogout={() => void logout()}
86
88
  contentClassName="h-dvh min-h-0 overflow-hidden" defaultRailCollapsed={false}>
87
89
  {error && <div role="alert" className="p-4 text-sm text-destructive">{error} <button className="underline" onClick={() => location.reload()}>Reload</button></div>}
88
- {showHistory ? loaded ? <HistoryPage threads={threads} /> : <p role="status" className="p-6">Loading History…</p>
90
+ {showApiAccess ? <ApiAccess /> : showHistory ? loaded ? <HistoryPage threads={threads} /> : <p role="status" className="p-6">Loading History…</p>
89
91
  : <AgentWorkspaceCompanion tabs={workspaceTools} persistenceKey={`workspace:${session.user.id}:tools`}><Conversation initialThreadId={initialThreadId} onThread={setActiveId} onChanged={refreshThreads} /></AgentWorkspaceCompanion>}
90
92
  </AgentWorkspaceLayout>
91
93
  }