@creatornader/agent-bridge 0.2.0
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.
- package/CHANGELOG.md +60 -0
- package/LICENSE +216 -0
- package/README.md +338 -0
- package/SKILL.md +24 -0
- package/bin/CLAUDE.md +11 -0
- package/bin/agent-bridge +7 -0
- package/clients/claude-code.json +20 -0
- package/clients/claude-desktop.json +20 -0
- package/clients/codex.json +20 -0
- package/clients/generic-mcp.json +13 -0
- package/clients/openclaw.json +13 -0
- package/dist/bridge-domain-BcnBeHOn.d.ts +97 -0
- package/dist/bridge-service-CfqMcMAn.d.ts +28 -0
- package/dist/bridge-store-BuGjxTn4.d.ts +61 -0
- package/dist/bridge.d.ts +102 -0
- package/dist/bridge.js +83 -0
- package/dist/bridge.js.map +1 -0
- package/dist/chunk-4KAOBC5X.js +773 -0
- package/dist/chunk-4KAOBC5X.js.map +1 -0
- package/dist/chunk-6MAZ6YLZ.js +146 -0
- package/dist/chunk-6MAZ6YLZ.js.map +1 -0
- package/dist/chunk-AXL2I7FH.js +423 -0
- package/dist/chunk-AXL2I7FH.js.map +1 -0
- package/dist/chunk-BV6W4AJK.js +211 -0
- package/dist/chunk-BV6W4AJK.js.map +1 -0
- package/dist/chunk-CKSKUBDQ.js +153 -0
- package/dist/chunk-CKSKUBDQ.js.map +1 -0
- package/dist/chunk-JOUBDRYX.js +272 -0
- package/dist/chunk-JOUBDRYX.js.map +1 -0
- package/dist/chunk-JTC5YURG.js +49 -0
- package/dist/chunk-JTC5YURG.js.map +1 -0
- package/dist/chunk-KVR4JBRF.js +80 -0
- package/dist/chunk-KVR4JBRF.js.map +1 -0
- package/dist/chunk-O26W5QHS.js +409 -0
- package/dist/chunk-O26W5QHS.js.map +1 -0
- package/dist/chunk-WEULPMUY.js +988 -0
- package/dist/chunk-WEULPMUY.js.map +1 -0
- package/dist/chunk-YD6YJATN.js +48 -0
- package/dist/chunk-YD6YJATN.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +670 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-config.d.ts +30 -0
- package/dist/client-config.js +10 -0
- package/dist/client-config.js.map +1 -0
- package/dist/client-runtime.d.ts +15 -0
- package/dist/client-runtime.js +15 -0
- package/dist/client-runtime.js.map +1 -0
- package/dist/gateway-BULozv3K.d.ts +54 -0
- package/dist/gateway-main.d.ts +2 -0
- package/dist/gateway-main.js +105 -0
- package/dist/gateway-main.js.map +1 -0
- package/dist/gateway.d.ts +4 -0
- package/dist/gateway.js +10 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.js +19 -0
- package/dist/server.js.map +1 -0
- package/dist/sqlite.d.ts +156 -0
- package/dist/sqlite.js +24 -0
- package/dist/sqlite.js.map +1 -0
- package/llms.txt +39 -0
- package/package.json +104 -0
- package/sql/migrations/001_schema_state.sql +34 -0
- package/sql/migrations/002_workspaces_agents_credentials.sql +77 -0
- package/sql/migrations/003_messages_receipts_deliveries.sql +116 -0
- package/sql/migrations/004_message_query_indexes.sql +31 -0
- package/sql/migrations/005_delivery_events_presence.sql +79 -0
- package/sql/migrations/006_legacy_shared_context_import.sql +139 -0
- package/sql/migrations/007_runtime_role.sql +59 -0
- package/sql/setup.sql +68 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
begin;
|
|
2
|
+
|
|
3
|
+
select pg_advisory_xact_lock(1646705660);
|
|
4
|
+
|
|
5
|
+
create or replace function agent_bridge.safe_timestamptz(value text) returns timestamptz
|
|
6
|
+
language plpgsql immutable set search_path = '' as $$
|
|
7
|
+
begin
|
|
8
|
+
return value::timestamptz;
|
|
9
|
+
exception when others then
|
|
10
|
+
return null;
|
|
11
|
+
end
|
|
12
|
+
$$;
|
|
13
|
+
|
|
14
|
+
create or replace function agent_bridge.legacy_message_uuid(value bigint, metadata jsonb) returns uuid
|
|
15
|
+
language sql immutable set search_path = '' as $$
|
|
16
|
+
select case
|
|
17
|
+
when metadata #>> '{message_envelope,message_id}' ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
|
|
18
|
+
then (metadata #>> '{message_envelope,message_id}')::uuid
|
|
19
|
+
when value between 0 and 281474976710655
|
|
20
|
+
then ('00000000-0000-8000-8000-' || lpad(to_hex(value), 12, '0'))::uuid
|
|
21
|
+
else (
|
|
22
|
+
'00000000-0000-8' || substring(encoded, 1, 3) || '-9' ||
|
|
23
|
+
substring(encoded, 4, 3) || '-' || substring(encoded, 7, 12)
|
|
24
|
+
)::uuid
|
|
25
|
+
end
|
|
26
|
+
from (
|
|
27
|
+
select lpad(to_hex(value), 16, '0')::text as raw
|
|
28
|
+
) mapped_raw
|
|
29
|
+
cross join lateral (
|
|
30
|
+
select lpad(mapped_raw.raw, 18, '0') as encoded
|
|
31
|
+
) mapped
|
|
32
|
+
$$;
|
|
33
|
+
|
|
34
|
+
do $import$
|
|
35
|
+
begin
|
|
36
|
+
if to_regclass('public.shared_context') is not null then
|
|
37
|
+
alter table public.shared_context
|
|
38
|
+
add column if not exists atrib_receipt_id text;
|
|
39
|
+
|
|
40
|
+
insert into agent_bridge.workspaces (id, name)
|
|
41
|
+
select distinct coalesce(project, 'legacy'), coalesce(project, 'Legacy unscoped')
|
|
42
|
+
from public.shared_context
|
|
43
|
+
on conflict (id) do nothing;
|
|
44
|
+
|
|
45
|
+
if exists (
|
|
46
|
+
select mapped_id from (
|
|
47
|
+
select agent_bridge.legacy_message_uuid(id, metadata) as mapped_id
|
|
48
|
+
from public.shared_context
|
|
49
|
+
) mapped
|
|
50
|
+
group by mapped_id having count(*) > 1
|
|
51
|
+
) then
|
|
52
|
+
raise exception 'legacy shared_context contains duplicate message IDs';
|
|
53
|
+
end if;
|
|
54
|
+
|
|
55
|
+
if exists (
|
|
56
|
+
select 1
|
|
57
|
+
from public.shared_context context
|
|
58
|
+
join agent_bridge.messages message
|
|
59
|
+
on message.id = agent_bridge.legacy_message_uuid(context.id, context.metadata)
|
|
60
|
+
) then
|
|
61
|
+
raise exception 'legacy shared_context message ID collides with existing v2 history';
|
|
62
|
+
end if;
|
|
63
|
+
|
|
64
|
+
insert into agent_bridge.messages (
|
|
65
|
+
id, workspace, source, type, content, content_type, data, targets,
|
|
66
|
+
thread_id, reply_to_id, correlation_id, causation_id, priority,
|
|
67
|
+
expires_at, idempotency_key, atrib_receipt_id,
|
|
68
|
+
informed_by, metadata, created_at
|
|
69
|
+
)
|
|
70
|
+
select
|
|
71
|
+
agent_bridge.legacy_message_uuid(id, metadata),
|
|
72
|
+
coalesce(project, 'legacy'),
|
|
73
|
+
source,
|
|
74
|
+
coalesce(metadata #>> '{message_envelope,kind}', category),
|
|
75
|
+
content,
|
|
76
|
+
coalesce(metadata #>> '{message_envelope,payload_mime}', 'text/plain'),
|
|
77
|
+
metadata #> '{message_envelope,payload}',
|
|
78
|
+
case
|
|
79
|
+
when jsonb_typeof(metadata #> '{message_envelope,target_agents}')='array'
|
|
80
|
+
then metadata #> '{message_envelope,target_agents}'
|
|
81
|
+
else '[]'::jsonb
|
|
82
|
+
end,
|
|
83
|
+
metadata #>> '{message_envelope,thread_id}',
|
|
84
|
+
metadata #>> '{message_envelope,reply_to_id}',
|
|
85
|
+
metadata #>> '{message_envelope,correlation_id}',
|
|
86
|
+
metadata #>> '{message_envelope,causation_id}',
|
|
87
|
+
case when priority in ('info','high','urgent') then priority else 'info' end,
|
|
88
|
+
agent_bridge.safe_timestamptz(metadata #>> '{message_envelope,expires_at}'),
|
|
89
|
+
metadata #>> '{message_envelope,idempotency_key}',
|
|
90
|
+
coalesce(atrib_receipt_id, metadata #>> '{message_envelope,atrib_receipt_id}'),
|
|
91
|
+
metadata #> '{message_envelope,informed_by}',
|
|
92
|
+
metadata,
|
|
93
|
+
created_at
|
|
94
|
+
from public.shared_context
|
|
95
|
+
on conflict (id) do nothing;
|
|
96
|
+
|
|
97
|
+
-- Targets on imported rows describe historical routing. Creating pending
|
|
98
|
+
-- deliveries here would execute old work again during an upgrade.
|
|
99
|
+
|
|
100
|
+
insert into agent_bridge.receipts (workspace, message_id, principal, read_at)
|
|
101
|
+
select
|
|
102
|
+
coalesce(context.project, 'legacy'),
|
|
103
|
+
agent_bridge.legacy_message_uuid(context.id, context.metadata),
|
|
104
|
+
principal,
|
|
105
|
+
context.created_at
|
|
106
|
+
from public.shared_context context
|
|
107
|
+
cross join lateral unnest(context.acked_by) as principal
|
|
108
|
+
on conflict do nothing;
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
select count(*) from public.shared_context context
|
|
112
|
+
join agent_bridge.messages message
|
|
113
|
+
on message.id = agent_bridge.legacy_message_uuid(context.id, context.metadata)
|
|
114
|
+
) <> (select count(*) from public.shared_context) then
|
|
115
|
+
raise exception 'legacy shared_context import count verification failed';
|
|
116
|
+
end if;
|
|
117
|
+
end if;
|
|
118
|
+
end
|
|
119
|
+
$import$;
|
|
120
|
+
|
|
121
|
+
insert into agent_bridge.schema_migrations (version, name, checksum)
|
|
122
|
+
values (6, 'legacy_shared_context_import', '__AGENT_BRIDGE_MIGRATION_CHECKSUM__')
|
|
123
|
+
on conflict (version) do update set applied_at=agent_bridge.schema_migrations.applied_at
|
|
124
|
+
where agent_bridge.schema_migrations.name=excluded.name
|
|
125
|
+
and agent_bridge.schema_migrations.checksum=excluded.checksum;
|
|
126
|
+
|
|
127
|
+
do $migration$
|
|
128
|
+
begin
|
|
129
|
+
if not exists (
|
|
130
|
+
select 1 from agent_bridge.schema_migrations
|
|
131
|
+
where version=6 and name='legacy_shared_context_import'
|
|
132
|
+
and checksum='__AGENT_BRIDGE_MIGRATION_CHECKSUM__'
|
|
133
|
+
) then
|
|
134
|
+
raise exception 'migration 6_legacy_shared_context_import conflicts with recorded schema state';
|
|
135
|
+
end if;
|
|
136
|
+
end
|
|
137
|
+
$migration$;
|
|
138
|
+
|
|
139
|
+
commit;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
begin;
|
|
2
|
+
|
|
3
|
+
select pg_advisory_xact_lock(1646705660);
|
|
4
|
+
|
|
5
|
+
do $role$
|
|
6
|
+
declare
|
|
7
|
+
role_name text := 'agent_bridge_runtime_' || substr(md5(current_database()), 1, 16);
|
|
8
|
+
begin
|
|
9
|
+
if not exists (select 1 from pg_roles where rolname=role_name) then
|
|
10
|
+
execute format(
|
|
11
|
+
'create role %I nologin nosuperuser nocreatedb nocreaterole noreplication nobypassrls',
|
|
12
|
+
role_name
|
|
13
|
+
);
|
|
14
|
+
end if;
|
|
15
|
+
execute format(
|
|
16
|
+
'alter role %I nologin nosuperuser nocreatedb nocreaterole noreplication nobypassrls',
|
|
17
|
+
role_name
|
|
18
|
+
);
|
|
19
|
+
execute format('revoke all on schema agent_bridge from %I', role_name);
|
|
20
|
+
execute format('revoke all on all tables in schema agent_bridge from %I', role_name);
|
|
21
|
+
execute format('revoke all on all sequences in schema agent_bridge from %I', role_name);
|
|
22
|
+
execute format('revoke all on all functions in schema agent_bridge from %I', role_name);
|
|
23
|
+
execute format('grant usage on schema agent_bridge to %I', role_name);
|
|
24
|
+
execute format(
|
|
25
|
+
'grant select on agent_bridge.schema_migrations, agent_bridge.workspaces, agent_bridge.agents, agent_bridge.credentials, agent_bridge.messages, agent_bridge.receipts, agent_bridge.deliveries, agent_bridge.delivery_events, agent_bridge.agent_instances to %I',
|
|
26
|
+
role_name
|
|
27
|
+
);
|
|
28
|
+
execute format(
|
|
29
|
+
'grant insert on agent_bridge.messages, agent_bridge.receipts, agent_bridge.deliveries, agent_bridge.delivery_events, agent_bridge.agent_instances to %I',
|
|
30
|
+
role_name
|
|
31
|
+
);
|
|
32
|
+
execute format(
|
|
33
|
+
'grant update on agent_bridge.deliveries, agent_bridge.agent_instances to %I',
|
|
34
|
+
role_name
|
|
35
|
+
);
|
|
36
|
+
execute format('grant delete on agent_bridge.agent_instances to %I', role_name);
|
|
37
|
+
execute format('grant usage, select on all sequences in schema agent_bridge to %I', role_name);
|
|
38
|
+
end
|
|
39
|
+
$role$;
|
|
40
|
+
|
|
41
|
+
insert into agent_bridge.schema_migrations (version, name, checksum)
|
|
42
|
+
values (7, 'runtime_role', '__AGENT_BRIDGE_MIGRATION_CHECKSUM__')
|
|
43
|
+
on conflict (version) do update set applied_at=agent_bridge.schema_migrations.applied_at
|
|
44
|
+
where agent_bridge.schema_migrations.name=excluded.name
|
|
45
|
+
and agent_bridge.schema_migrations.checksum=excluded.checksum;
|
|
46
|
+
|
|
47
|
+
do $migration$
|
|
48
|
+
begin
|
|
49
|
+
if not exists (
|
|
50
|
+
select 1 from agent_bridge.schema_migrations
|
|
51
|
+
where version=7 and name='runtime_role'
|
|
52
|
+
and checksum='__AGENT_BRIDGE_MIGRATION_CHECKSUM__'
|
|
53
|
+
) then
|
|
54
|
+
raise exception 'migration 7_runtime_role conflicts with recorded schema state';
|
|
55
|
+
end if;
|
|
56
|
+
end
|
|
57
|
+
$migration$;
|
|
58
|
+
|
|
59
|
+
commit;
|
package/sql/setup.sql
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
-- Agent Bridge: shared_context table
|
|
2
|
+
-- Provides cross-agent context sharing via Supabase REST API
|
|
3
|
+
|
|
4
|
+
create table shared_context (
|
|
5
|
+
id bigserial primary key,
|
|
6
|
+
source text not null,
|
|
7
|
+
category text not null,
|
|
8
|
+
content text not null,
|
|
9
|
+
priority text not null default 'info',
|
|
10
|
+
project text,
|
|
11
|
+
metadata jsonb not null default '{}',
|
|
12
|
+
atrib_receipt_id text,
|
|
13
|
+
created_at timestamptz not null default now(),
|
|
14
|
+
acked_by text[] not null default '{}'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- Categories:
|
|
18
|
+
-- operational — runtime status, health, delivery confirmations
|
|
19
|
+
-- config-change — settings or wrapper modifications
|
|
20
|
+
-- goal-update — goal progress, new goals, goal completion
|
|
21
|
+
-- flag — urgent alerts, blockers, warnings
|
|
22
|
+
-- bridge-meta — suggested improvements to the Agent Bridge itself
|
|
23
|
+
|
|
24
|
+
-- Indexes for common query patterns
|
|
25
|
+
create index idx_ctx_created on shared_context(created_at desc);
|
|
26
|
+
create index idx_ctx_source on shared_context(source);
|
|
27
|
+
create index idx_ctx_category on shared_context(category);
|
|
28
|
+
create index idx_ctx_atrib_receipt on shared_context(atrib_receipt_id)
|
|
29
|
+
where atrib_receipt_id is not null;
|
|
30
|
+
|
|
31
|
+
-- RLS: allow anon key to read all rows and insert/update
|
|
32
|
+
alter table shared_context enable row level security;
|
|
33
|
+
|
|
34
|
+
create policy "Allow read access"
|
|
35
|
+
on shared_context for select
|
|
36
|
+
using (true);
|
|
37
|
+
|
|
38
|
+
create policy "Allow insert access"
|
|
39
|
+
on shared_context for insert
|
|
40
|
+
with check (true);
|
|
41
|
+
|
|
42
|
+
create policy "Allow update access"
|
|
43
|
+
on shared_context for update
|
|
44
|
+
using (true);
|
|
45
|
+
|
|
46
|
+
-- Atomic ack function (avoids fetch-then-update race condition)
|
|
47
|
+
create or replace function ack_context(entry_ids bigint[], agent_name text)
|
|
48
|
+
returns integer
|
|
49
|
+
language plpgsql
|
|
50
|
+
security definer
|
|
51
|
+
set search_path = public
|
|
52
|
+
as $$
|
|
53
|
+
declare
|
|
54
|
+
affected integer;
|
|
55
|
+
begin
|
|
56
|
+
update shared_context
|
|
57
|
+
set acked_by = array_append(acked_by, agent_name)
|
|
58
|
+
where id = any(entry_ids)
|
|
59
|
+
and not (acked_by @> array[agent_name]);
|
|
60
|
+
get diagnostics affected = row_count;
|
|
61
|
+
return affected;
|
|
62
|
+
end;
|
|
63
|
+
$$;
|
|
64
|
+
|
|
65
|
+
comment on column shared_context.atrib_receipt_id is
|
|
66
|
+
'Optional signed atrib record receipt_id (record_hash "." creator_key, base64url) ' ||
|
|
67
|
+
'emitted by an atrib-signing wrapper at insert time. ' ||
|
|
68
|
+
'Consumers use this as the informed_by anchor for cross-process causal edges.';
|