Skip to content

Commit e3bc3d7

Browse files
committed
feat: add basic implementation
1 parent 1db3f31 commit e3bc3d7

38 files changed

Lines changed: 8776 additions & 0 deletions

src/_index.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: "1.0"
2+
namespace: wippy.session
3+
4+
entries:
5+
# wippy.session:start_tokens
6+
- name: start_tokens
7+
kind: library.lua
8+
meta:
9+
comment: Library for creating and validating session start tokens
10+
description: User sessions and conversation management system
11+
depends_on:
12+
- ns:wippy.agent
13+
- ns:wippy.llm
14+
- ns:wippy.agent.gen1
15+
source: file://start_tokens.lua
16+
modules:
17+
- crypto
18+
- base64
19+
- json
20+
21+
# wippy.session:start_tokens_test
22+
- name: start_tokens_test
23+
kind: function.lua
24+
meta:
25+
name: Start Tokens Library Test
26+
type: test
27+
comment: Tests the start_tokens library for creating and validating session start tokens
28+
group: Session Tests
29+
tags:
30+
- session
31+
- security
32+
- token
33+
- tests
34+
description: User sessions and conversation management system
35+
depends_on:
36+
- ns:wippy.agent
37+
- ns:wippy.llm
38+
- ns:wippy.agent.gen1
39+
source: file://start_tokens_test.lua
40+
modules:
41+
- crypto
42+
- base64
43+
- json
44+
imports:
45+
start_tokens: wippy.session:start_tokens
46+
test: wippy.test:test
47+
method: run_tests
48+

src/api/_index.yaml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
version: "1.0"
2+
namespace: wippy.session.api
3+
4+
entries:
5+
# wippy.session.api:get_artifact
6+
- name: get_artifact
7+
kind: function.lua
8+
meta:
9+
comment: Returns metadata for an artifact by ID
10+
depends_on:
11+
- ns:app
12+
- ns:wippy.session.persist
13+
router: app:api
14+
source: file://get_artifact.lua
15+
modules:
16+
- http
17+
- json
18+
- security
19+
imports:
20+
artifact_repo: wippy.session.persist:artifact_repo
21+
session_repo: wippy.session.persist:session_repo
22+
method: handler
23+
pool:
24+
size: 2
25+
26+
# wippy.session.api:get_artifact.endpoint
27+
- name: get_artifact.endpoint
28+
kind: http.endpoint
29+
meta:
30+
comment: Endpoint that returns metadata for an artifact
31+
depends_on:
32+
- ns:app
33+
router: app:api
34+
method: GET
35+
func: get_artifact
36+
path: /artifact/{id}
37+
38+
# wippy.session.api:get_artifact_content
39+
- name: get_artifact_content
40+
kind: function.lua
41+
meta:
42+
comment: Returns content for an artifact by ID
43+
depends_on:
44+
- ns:app
45+
- ns:wippy.session.persist
46+
router: app:api
47+
source: file://get_artifact_content.lua
48+
modules:
49+
- http
50+
- json
51+
- security
52+
imports:
53+
artifact_repo: wippy.session.persist:artifact_repo
54+
renderer: wippy.views:renderer
55+
session_repo: wippy.session.persist:session_repo
56+
method: handler
57+
pool:
58+
size: 2
59+
60+
# wippy.session.api:get_artifact_content.endpoint
61+
- name: get_artifact_content.endpoint
62+
kind: http.endpoint
63+
meta:
64+
comment: Endpoint that returns content for an artifact
65+
depends_on:
66+
- ns:app
67+
router: app:api
68+
method: GET
69+
func: get_artifact_content
70+
path: /artifact/{id}/content
71+
72+
# wippy.session.api:get_session
73+
- name: get_session
74+
kind: function.lua
75+
meta:
76+
comment: Get detailed session info
77+
description: Session management HTTP endpoints
78+
depends_on:
79+
- app:api
80+
- ns:wippy.session
81+
- ns:wippy.session.persist
82+
router: app:api
83+
source: file://get_session.lua
84+
modules:
85+
- http
86+
- security
87+
imports:
88+
message_repo: wippy.session.persist:message_repo
89+
session_repo: wippy.session.persist:session_repo
90+
method: handler
91+
pool:
92+
size: 2
93+
94+
# wippy.session.api:get_session.endpoint
95+
- name: get_session.endpoint
96+
kind: http.endpoint
97+
meta:
98+
comment: Get session endpoint
99+
description: Session management HTTP endpoints
100+
depends_on:
101+
- app:api
102+
- ns:wippy.session
103+
- ns:wippy.session.persist
104+
router: app:api
105+
method: GET
106+
func: get_session
107+
path: /sessions/get
108+
109+
# wippy.session.api:list_sessions
110+
- name: list_sessions
111+
kind: function.lua
112+
meta:
113+
comment: List all user sessions
114+
description: Session management HTTP endpoints
115+
depends_on:
116+
- app:api
117+
- ns:wippy.session
118+
- ns:wippy.session.persist
119+
router: app:api
120+
source: file://list_sessions.lua
121+
modules:
122+
- http
123+
- security
124+
imports:
125+
session_repo: wippy.session.persist:session_repo
126+
method: handler
127+
pool:
128+
size: 2
129+
130+
# wippy.session.api:list_sessions.endpoint
131+
- name: list_sessions.endpoint
132+
kind: http.endpoint
133+
meta:
134+
comment: List sessions endpoint
135+
description: Session management HTTP endpoints
136+
depends_on:
137+
- app:api
138+
- ns:wippy.session
139+
- ns:wippy.session.persist
140+
router: app:api
141+
method: GET
142+
func: list_sessions
143+
path: /sessions
144+
145+
# wippy.session.api:session_messages
146+
- name: session_messages
147+
kind: function.lua
148+
meta:
149+
comment: Get messages for a session
150+
description: Session management HTTP endpoints
151+
depends_on:
152+
- app:api
153+
- ns:wippy.session
154+
- ns:wippy.session.persist
155+
router: app:api
156+
source: file://session_messages.lua
157+
modules:
158+
- http
159+
- security
160+
- time
161+
imports:
162+
message_repo: wippy.session.persist:message_repo
163+
session_repo: wippy.session.persist:session_repo
164+
method: handler
165+
pool:
166+
size: 2
167+
168+
# wippy.session.api:session_messages.endpoint
169+
- name: session_messages.endpoint
170+
kind: http.endpoint
171+
meta:
172+
comment: Session messages endpoint
173+
description: Session management HTTP endpoints
174+
depends_on:
175+
- app:api
176+
- ns:wippy.session
177+
- ns:wippy.session.persist
178+
router: app:api
179+
method: GET
180+
func: session_messages
181+
path: /sessions/messages
182+

src/api/get_artifact.lua

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
local http = require("http")
2+
local json = require("json")
3+
local artifact_repo = require("artifact_repo")
4+
local session_repo = require("session_repo")
5+
local security = require("security")
6+
7+
local function handler()
8+
-- Get response object
9+
local res = http.response()
10+
local req = http.request()
11+
if not res or not req then
12+
return nil, "Failed to get HTTP context"
13+
end
14+
15+
-- Security check - ensure user is authenticated
16+
local actor = security.actor()
17+
if not actor then
18+
res:set_status(http.STATUS.UNAUTHORIZED)
19+
res:set_content_type(http.CONTENT.JSON)
20+
res:write_json({
21+
success = false,
22+
error = "Authentication required"
23+
})
24+
return
25+
end
26+
27+
-- Get user ID from the authenticated actor
28+
local user_id = actor:id()
29+
30+
-- Get artifact ID from URL path
31+
local artifact_id = req:param("id")
32+
if not artifact_id or artifact_id == "" then
33+
res:set_status(http.STATUS.BAD_REQUEST)
34+
res:set_content_type(http.CONTENT.JSON)
35+
res:write_json({
36+
success = false,
37+
error = "Missing artifact ID in path"
38+
})
39+
return
40+
end
41+
42+
-- Fetch the artifact from the repository
43+
local artifact, err = artifact_repo.get(artifact_id)
44+
if err then
45+
-- Handle not found error
46+
if err:match("not found") then
47+
res:set_status(http.STATUS.NOT_FOUND)
48+
res:set_content_type(http.CONTENT.JSON)
49+
res:write_json({
50+
success = false,
51+
error = "Artifact not found: " .. artifact_id
52+
})
53+
return
54+
end
55+
56+
-- Handle other errors
57+
res:set_status(http.STATUS.INTERNAL_ERROR)
58+
res:set_content_type(http.CONTENT.JSON)
59+
res:write_json({
60+
success = false,
61+
error = "Failed to retrieve artifact: " .. err
62+
})
63+
return
64+
end
65+
66+
-- Get the session to check ownership
67+
local session, session_err = session_repo.get(artifact.session_id)
68+
if session_err then
69+
res:set_status(http.STATUS.INTERNAL_ERROR)
70+
res:set_content_type(http.CONTENT.JSON)
71+
res:write_json({
72+
success = false,
73+
error = "Failed to verify artifact ownership: " .. session_err
74+
})
75+
return
76+
end
77+
78+
-- Verify the session belongs to the authenticated user
79+
if session.user_id ~= user_id then
80+
res:set_status(http.STATUS.FORBIDDEN)
81+
res:set_content_type(http.CONTENT.JSON)
82+
res:write_json({
83+
success = false,
84+
error = "Access denied: You don't have permission to access this artifact"
85+
})
86+
return
87+
end
88+
89+
-- Convert to a client-friendly format
90+
local response = {
91+
uuid = artifact.artifact_id,
92+
type = artifact.kind,
93+
title = artifact.title,
94+
created_at = artifact.created_at,
95+
updated_at = artifact.updated_at,
96+
content_version = 1
97+
}
98+
99+
-- Include metadata if available
100+
if artifact.meta then
101+
response.content_type = artifact.meta.content_type
102+
response.description = artifact.meta.description
103+
response.icon = artifact.meta.icon
104+
response.status = artifact.meta.status
105+
106+
-- Add page reference specific data if this is a view_ref artifact
107+
if artifact.kind == "view_ref" then
108+
response.page_id = artifact.meta.page_id
109+
response.is_view_reference = true
110+
response.type = artifact.meta.display_type or "standalone"
111+
112+
-- Also get the params if this is a view_ref
113+
if artifact.content and artifact.content ~= "" then
114+
local params, decode_err = json.decode(artifact.content)
115+
if not decode_err then
116+
response.params = params
117+
end
118+
end
119+
end
120+
end
121+
122+
-- Return JSON metadata response
123+
res:set_content_type(http.CONTENT.JSON)
124+
res:set_status(http.STATUS.OK)
125+
res:write_json(response)
126+
end
127+
128+
return {
129+
handler = handler
130+
}

0 commit comments

Comments
 (0)