@hotmeshio/long-tail 0.1.11 → 0.1.13

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.
Files changed (29) hide show
  1. package/README.md +1 -1
  2. package/build/api/escalations.js +7 -2
  3. package/build/examples/seed.js +50 -0
  4. package/build/lib/db/schemas/001_schema.sql +281 -106
  5. package/build/lib/db/schemas/002_seed.sql +56 -39
  6. package/build/services/mcp/client/connection.d.ts +13 -0
  7. package/build/services/mcp/client/connection.js +62 -0
  8. package/build/services/mcp/client/tools.js +20 -7
  9. package/build/services/mcp/server.js +31 -0
  10. package/build/services/yaml-workflow/workers/register.js +24 -4
  11. package/build/system/mcp-servers/human-queue.js +31 -0
  12. package/docs/cloud.md +123 -0
  13. package/package.json +3 -3
  14. package/build/lib/db/schemas/003_workflow_discovery.sql +0 -39
  15. package/build/lib/db/schemas/004_query_router.sql +0 -38
  16. package/build/lib/db/schemas/004_workflow_sets.sql +0 -29
  17. package/build/lib/db/schemas/005_triage_router.sql +0 -37
  18. package/build/lib/db/schemas/005_unique_graph_topic.sql +0 -7
  19. package/build/lib/db/schemas/006_oauth.sql +0 -50
  20. package/build/lib/db/schemas/007_security.sql +0 -27
  21. package/build/lib/db/schemas/008_bot_accounts.sql +0 -30
  22. package/build/lib/db/schemas/009_audit_trail.sql +0 -7
  23. package/build/lib/db/schemas/010_credential_providers.sql +0 -4
  24. package/build/lib/db/schemas/011_system_workflow_configs.sql +0 -37
  25. package/build/lib/db/schemas/012_drop_modality.sql +0 -6
  26. package/build/lib/db/schemas/013_execute_as.sql +0 -9
  27. package/build/lib/db/schemas/014_ephemeral_credentials.sql +0 -16
  28. package/build/lib/db/schemas/015_knowledge.sql +0 -23
  29. package/build/lib/db/schemas/016_streamable_http.sql +0 -7
@@ -1,29 +0,0 @@
1
- -- Workflow sets: groups of related workflows produced by plan mode.
2
-
3
- CREATE TABLE IF NOT EXISTS lt_workflow_sets (
4
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5
- name TEXT UNIQUE NOT NULL,
6
- description TEXT,
7
- specification TEXT NOT NULL,
8
- plan JSONB NOT NULL DEFAULT '[]'::JSONB,
9
- namespaces TEXT[] NOT NULL DEFAULT '{}',
10
- status TEXT NOT NULL DEFAULT 'planning'
11
- CHECK (status IN ('planning','planned','building','deploying','completed','failed')),
12
- source_workflow_id TEXT,
13
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
14
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
15
- );
16
-
17
- CREATE OR REPLACE TRIGGER trg_lt_workflow_sets_updated_at
18
- BEFORE UPDATE ON lt_workflow_sets
19
- FOR EACH ROW EXECUTE FUNCTION lt_set_updated_at();
20
-
21
- -- Extend lt_yaml_workflows with set membership columns
22
- ALTER TABLE lt_yaml_workflows ADD COLUMN IF NOT EXISTS set_id UUID
23
- REFERENCES lt_workflow_sets(id) ON DELETE SET NULL;
24
- ALTER TABLE lt_yaml_workflows ADD COLUMN IF NOT EXISTS set_role TEXT
25
- CHECK (set_role IN ('leaf', 'composition', 'router'));
26
- ALTER TABLE lt_yaml_workflows ADD COLUMN IF NOT EXISTS set_build_order INTEGER;
27
-
28
- CREATE INDEX IF NOT EXISTS idx_lt_yaml_workflows_set_id
29
- ON lt_yaml_workflows (set_id) WHERE set_id IS NOT NULL;
@@ -1,37 +0,0 @@
1
- -- Split mcpTriage into router + dynamic + deterministic workflows.
2
- -- mcpTriageRouter is the new entry point (orchestrator).
3
- -- mcpTriage becomes dynamic-only (leaf).
4
- -- mcpTriageDeterministic invokes compiled YAML workflows (leaf).
5
-
6
- -- Update existing mcpTriage: no longer directly invocable (called via router)
7
- UPDATE lt_config_workflows
8
- SET invocable = false,
9
- description = 'Dynamic MCP triage — LLM agentic loop for escalation remediation'
10
- WHERE workflow_type = 'mcpTriage';
11
-
12
- -- Add mcpTriageRouter (orchestrator — the new entry point for triage)
13
- INSERT INTO lt_config_workflows
14
- (workflow_type, task_queue, default_role, invocable, description, tool_tags)
15
- VALUES
16
- ('mcpTriageRouter', 'long-tail-system', 'engineer', false,
17
- 'Triage router — discovers compiled workflows for remediation, routes to deterministic or dynamic triage',
18
- '{}')
19
- ON CONFLICT (workflow_type) DO NOTHING;
20
-
21
- -- Add mcpTriageDeterministic (leaf — invokes compiled triage workflows)
22
- INSERT INTO lt_config_workflows
23
- (workflow_type, task_queue, default_role, invocable, description, tool_tags)
24
- VALUES
25
- ('mcpTriageDeterministic', 'long-tail-system', 'engineer', false,
26
- 'Deterministic triage — invokes matched compiled workflows for escalation remediation',
27
- '{}')
28
- ON CONFLICT (workflow_type) DO NOTHING;
29
-
30
- -- Assign roles
31
- INSERT INTO lt_config_roles (workflow_type, role)
32
- SELECT 'mcpTriageRouter', unnest(ARRAY['reviewer', 'engineer', 'admin'])
33
- ON CONFLICT (workflow_type, role) DO NOTHING;
34
-
35
- INSERT INTO lt_config_roles (workflow_type, role)
36
- SELECT 'mcpTriageDeterministic', unnest(ARRAY['reviewer', 'engineer', 'admin'])
37
- ON CONFLICT (workflow_type, role) DO NOTHING;
@@ -1,7 +0,0 @@
1
- -- Enforce unique graph_topic per app_id for non-archived workflows.
2
- -- Two active/deployed/draft workflows in the same namespace must not
3
- -- share a subscribes topic — deploying them would cause routing collisions.
4
-
5
- CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_yaml_workflows_app_topic_unique
6
- ON lt_yaml_workflows (app_id, graph_topic)
7
- WHERE status != 'archived';
@@ -1,50 +0,0 @@
1
- -- ── OAuth token storage ─────────────────────────────────────────────────────
2
- -- Encrypted per-user, per-provider OAuth tokens for identity and resource OAuth.
3
-
4
- CREATE TABLE IF NOT EXISTS lt_oauth_tokens (
5
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
6
- user_id UUID NOT NULL REFERENCES lt_users(id) ON DELETE CASCADE,
7
- provider TEXT NOT NULL,
8
- label TEXT NOT NULL DEFAULT 'default',
9
- access_token_enc TEXT NOT NULL,
10
- refresh_token_enc TEXT,
11
- token_type TEXT NOT NULL DEFAULT 'bearer',
12
- scopes TEXT[] NOT NULL DEFAULT '{}',
13
- expires_at TIMESTAMPTZ,
14
- provider_user_id TEXT NOT NULL,
15
- provider_email TEXT,
16
- metadata JSONB,
17
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
18
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
19
- UNIQUE (user_id, provider, label)
20
- );
21
-
22
- -- Migration: add label column for multiple credentials per provider per user.
23
- -- Existing rows get 'default'. The unique constraint moves from (user_id, provider)
24
- -- to (user_id, provider, label).
25
- ALTER TABLE lt_oauth_tokens ADD COLUMN IF NOT EXISTS label TEXT NOT NULL DEFAULT 'default';
26
-
27
- -- Drop old unique constraint if it exists (safe no-op if already migrated)
28
- DO $$ BEGIN
29
- ALTER TABLE lt_oauth_tokens DROP CONSTRAINT IF EXISTS lt_oauth_tokens_user_id_provider_key;
30
- EXCEPTION WHEN undefined_object THEN NULL;
31
- END $$;
32
-
33
- -- Create the new composite unique constraint (idempotent via IF NOT EXISTS on index)
34
- CREATE UNIQUE INDEX IF NOT EXISTS lt_oauth_tokens_user_id_provider_label_key
35
- ON lt_oauth_tokens (user_id, provider, label);
36
-
37
- CREATE INDEX IF NOT EXISTS idx_lt_oauth_tokens_provider
38
- ON lt_oauth_tokens (provider, user_id);
39
-
40
- CREATE OR REPLACE TRIGGER trg_lt_oauth_tokens_updated_at
41
- BEFORE UPDATE ON lt_oauth_tokens
42
- FOR EACH ROW EXECUTE FUNCTION lt_set_updated_at();
43
-
44
- -- ── Identity link columns on lt_users ──────────────────────────────────────
45
- ALTER TABLE lt_users ADD COLUMN IF NOT EXISTS oauth_provider TEXT;
46
- ALTER TABLE lt_users ADD COLUMN IF NOT EXISTS oauth_provider_id TEXT;
47
-
48
- CREATE INDEX IF NOT EXISTS idx_lt_users_oauth
49
- ON lt_users (oauth_provider, oauth_provider_id)
50
- WHERE oauth_provider IS NOT NULL;
@@ -1,27 +0,0 @@
1
- -- ── Service tokens for external MCP servers ─────────────────────────────────
2
- CREATE TABLE IF NOT EXISTS lt_service_tokens (
3
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
4
- name TEXT UNIQUE NOT NULL,
5
- token_hash TEXT NOT NULL,
6
- server_id UUID REFERENCES lt_mcp_servers(id) ON DELETE CASCADE,
7
- scopes TEXT[] NOT NULL DEFAULT '{}',
8
- expires_at TIMESTAMPTZ,
9
- last_used_at TIMESTAMPTZ,
10
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
11
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
12
- );
13
-
14
- CREATE INDEX IF NOT EXISTS idx_lt_service_tokens_server
15
- ON lt_service_tokens (server_id);
16
-
17
- CREATE OR REPLACE TRIGGER trg_lt_service_tokens_updated_at
18
- BEFORE UPDATE ON lt_service_tokens
19
- FOR EACH ROW EXECUTE FUNCTION lt_set_updated_at();
20
-
21
- -- ── Audit: who initiated escalations ────────────────────────────────────────
22
- ALTER TABLE lt_escalations ADD COLUMN IF NOT EXISTS created_by UUID REFERENCES lt_users(id);
23
- CREATE INDEX IF NOT EXISTS idx_lt_escalations_created_by
24
- ON lt_escalations (created_by) WHERE created_by IS NOT NULL;
25
-
26
- -- ── Scope declarations for MCP servers ──────────────────────────────────────
27
- ALTER TABLE lt_mcp_servers ADD COLUMN IF NOT EXISTS required_scopes TEXT[] NOT NULL DEFAULT '{}';
@@ -1,30 +0,0 @@
1
- -- 008_bot_accounts.sql
2
- -- Bot/service account support for universal IAM.
3
- -- Bots live in lt_users (account_type = 'bot') and authenticate via API keys.
4
-
5
- -- Add account_type column to lt_users to distinguish human vs bot accounts.
6
- ALTER TABLE lt_users ADD COLUMN IF NOT EXISTS account_type TEXT NOT NULL DEFAULT 'user';
7
-
8
- -- Apply check constraint (idempotent: skip if already exists).
9
- DO $$ BEGIN
10
- ALTER TABLE lt_users ADD CONSTRAINT lt_users_account_type_check
11
- CHECK (account_type IN ('user', 'bot'));
12
- EXCEPTION
13
- WHEN duplicate_object THEN NULL;
14
- END $$;
15
-
16
- -- Bot API keys — similar to lt_service_tokens but scoped to a user (bot) account.
17
- CREATE TABLE IF NOT EXISTS lt_bot_api_keys (
18
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
19
- name TEXT NOT NULL,
20
- user_id UUID NOT NULL REFERENCES lt_users(id) ON DELETE CASCADE,
21
- key_hash TEXT NOT NULL,
22
- scopes TEXT[] NOT NULL DEFAULT '{}',
23
- expires_at TIMESTAMPTZ,
24
- last_used_at TIMESTAMPTZ,
25
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
26
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
27
- UNIQUE (user_id, name)
28
- );
29
-
30
- CREATE INDEX IF NOT EXISTS idx_bot_api_keys_user_id ON lt_bot_api_keys (user_id);
@@ -1,7 +0,0 @@
1
- -- 009_audit_trail.sql
2
- -- Add IAM audit columns to lt_tasks for identity traceability.
3
-
4
- ALTER TABLE lt_tasks ADD COLUMN IF NOT EXISTS initiated_by UUID REFERENCES lt_users(id) ON DELETE SET NULL;
5
- ALTER TABLE lt_tasks ADD COLUMN IF NOT EXISTS principal_type TEXT DEFAULT 'user';
6
-
7
- CREATE INDEX IF NOT EXISTS idx_lt_tasks_initiated_by ON lt_tasks (initiated_by) WHERE initiated_by IS NOT NULL;
@@ -1,4 +0,0 @@
1
- -- Add credential_providers column to lt_mcp_servers
2
- -- Declares which credential providers a server's tools need
3
- ALTER TABLE lt_mcp_servers
4
- ADD COLUMN IF NOT EXISTS credential_providers TEXT[] NOT NULL DEFAULT '{}';
@@ -1,37 +0,0 @@
1
- -- Ensure all system leaf workflows have config entries.
2
- -- Migrations 004/005 tried to UPDATE these but they were never seeded —
3
- -- the interceptor needs config entries to wrap workflows with lifecycle events.
4
-
5
- INSERT INTO lt_config_workflows
6
- (workflow_type, task_queue, default_role, invocable, description, tool_tags)
7
- VALUES
8
- ('mcpQuery', 'long-tail-system', 'engineer', false,
9
- 'Dynamic MCP tool orchestration — LLM agentic loop with raw MCP tools',
10
- '{}'),
11
- ('mcpTriage', 'long-tail-system', 'engineer', false,
12
- 'Dynamic MCP triage — LLM agentic loop for escalation remediation',
13
- '{}'),
14
- ('mcpWorkflowBuilder', 'long-tail-system', 'engineer', false,
15
- 'Direct pipeline builder — LLM constructs DAG from tool schemas',
16
- '{}'),
17
- ('mcpWorkflowPlanner', 'long-tail-system', 'engineer', false,
18
- 'Plan mode — decomposes specifications into multi-workflow sets',
19
- '{}')
20
- ON CONFLICT (workflow_type) DO NOTHING;
21
-
22
- -- Assign roles
23
- INSERT INTO lt_config_roles (workflow_type, role)
24
- SELECT 'mcpQuery', unnest(ARRAY['reviewer', 'engineer', 'admin'])
25
- ON CONFLICT (workflow_type, role) DO NOTHING;
26
-
27
- INSERT INTO lt_config_roles (workflow_type, role)
28
- SELECT 'mcpTriage', unnest(ARRAY['reviewer', 'engineer', 'admin'])
29
- ON CONFLICT (workflow_type, role) DO NOTHING;
30
-
31
- INSERT INTO lt_config_roles (workflow_type, role)
32
- SELECT 'mcpWorkflowBuilder', unnest(ARRAY['reviewer', 'engineer', 'admin'])
33
- ON CONFLICT (workflow_type, role) DO NOTHING;
34
-
35
- INSERT INTO lt_config_roles (workflow_type, role)
36
- SELECT 'mcpWorkflowPlanner', unnest(ARRAY['reviewer', 'engineer', 'admin'])
37
- ON CONFLICT (workflow_type, role) DO NOTHING;
@@ -1,6 +0,0 @@
1
- -- Remove delivery modality — the concept was never used for actual routing.
2
- -- Alpha cleanup: drop from config, escalations, and tasks tables.
3
-
4
- ALTER TABLE lt_config_workflows DROP COLUMN IF EXISTS default_modality;
5
- ALTER TABLE lt_escalations DROP COLUMN IF EXISTS modality;
6
- ALTER TABLE lt_tasks DROP COLUMN IF EXISTS modality;
@@ -1,9 +0,0 @@
1
- -- Add execute_as to workflow configs: proxy invocation identity.
2
- -- When set, workflows run as the named bot instead of the invoking user.
3
-
4
- ALTER TABLE lt_config_workflows ADD COLUMN IF NOT EXISTS execute_as TEXT;
5
-
6
- -- Add executing_as to tasks: records the actual executing principal
7
- -- (may differ from initiated_by when proxy invocation is used).
8
-
9
- ALTER TABLE lt_tasks ADD COLUMN IF NOT EXISTS executing_as TEXT;
@@ -1,16 +0,0 @@
1
- -- Ephemeral credential store for sensitive fields in waitFor signal payloads.
2
- -- Supports max_uses (0 = unlimited) and TTL-based expiry.
3
-
4
- CREATE TABLE IF NOT EXISTS lt_ephemeral_credentials (
5
- token UUID PRIMARY KEY DEFAULT gen_random_uuid(),
6
- value BYTEA NOT NULL,
7
- label TEXT,
8
- max_uses INTEGER NOT NULL DEFAULT 0,
9
- use_count INTEGER NOT NULL DEFAULT 0,
10
- expires_at TIMESTAMPTZ,
11
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
12
- );
13
-
14
- CREATE INDEX IF NOT EXISTS idx_lt_ephemeral_expiry
15
- ON lt_ephemeral_credentials (expires_at)
16
- WHERE expires_at IS NOT NULL;
@@ -1,23 +0,0 @@
1
- -- Long Tail Knowledge Store
2
- -- Persistent JSONB memory for autonomous agents. Each entry lives in a domain
3
- -- (lightweight namespace) and is keyed by a human-readable string.
4
-
5
- CREATE TABLE IF NOT EXISTS lt_knowledge (
6
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
7
- domain TEXT NOT NULL,
8
- key TEXT NOT NULL,
9
- data JSONB NOT NULL DEFAULT '{}',
10
- tags TEXT[] NOT NULL DEFAULT '{}',
11
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
12
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
13
- UNIQUE(domain, key)
14
- );
15
-
16
- CREATE INDEX IF NOT EXISTS idx_lt_knowledge_domain ON lt_knowledge (domain);
17
- CREATE INDEX IF NOT EXISTS idx_lt_knowledge_tags ON lt_knowledge USING GIN (tags);
18
- CREATE INDEX IF NOT EXISTS idx_lt_knowledge_data ON lt_knowledge USING GIN (data);
19
-
20
- DROP TRIGGER IF EXISTS lt_knowledge_updated_at ON lt_knowledge;
21
- CREATE TRIGGER lt_knowledge_updated_at
22
- BEFORE UPDATE ON lt_knowledge
23
- FOR EACH ROW EXECUTE FUNCTION lt_set_updated_at();
@@ -1,7 +0,0 @@
1
- -- Allow 'streamable-http' as a transport type for MCP servers
2
- ALTER TABLE lt_mcp_servers
3
- DROP CONSTRAINT IF EXISTS lt_mcp_servers_transport_type_check;
4
-
5
- ALTER TABLE lt_mcp_servers
6
- ADD CONSTRAINT lt_mcp_servers_transport_type_check
7
- CHECK (transport_type IN ('stdio', 'sse', 'streamable-http'));